lunchboxtheman
Dec 26th, 2009, 09:22 PM
Hey all,
I'm running into a weird issue with trying to get a rectangle to span an entire list item. Check out the screenshot attachment.
For the first list item there, I used the following XAML
<ListBoxItem HorizontalContentAlignment="Stretch">
. . .
<Rectangle Fill="Red" Grid.ColumnSpan="2" Grid.RowSpan="3" />
. . .
For the second, I'm using the C# code below
Rectangle highlightRect = new Rectangle();
Grid.SetColumnSpan(highlightRect, 2);
Grid.SetRowSpan(highlightRect, 3);
SolidColorBrush myBrush = new SolidColorBrush(Colors.Red);
highlightRect.Fill = myBrush;
. . .
layoutGrid.Children.Add(highlightRect);
. . .
ListBoxItem theItem = new ListBoxItem();
theItem.HorizontalContentAlignment = HorizontalAlignment.Stretch;
theItem.Content = layoutGrid;
The first result, the one obtained from using that XAML, is the desired one. What am I not doing in the C# to make the rectangle fill up the rest of the space?
Thanks,
Lunchboxtheman
I'm running into a weird issue with trying to get a rectangle to span an entire list item. Check out the screenshot attachment.
For the first list item there, I used the following XAML
<ListBoxItem HorizontalContentAlignment="Stretch">
. . .
<Rectangle Fill="Red" Grid.ColumnSpan="2" Grid.RowSpan="3" />
. . .
For the second, I'm using the C# code below
Rectangle highlightRect = new Rectangle();
Grid.SetColumnSpan(highlightRect, 2);
Grid.SetRowSpan(highlightRect, 3);
SolidColorBrush myBrush = new SolidColorBrush(Colors.Red);
highlightRect.Fill = myBrush;
. . .
layoutGrid.Children.Add(highlightRect);
. . .
ListBoxItem theItem = new ListBoxItem();
theItem.HorizontalContentAlignment = HorizontalAlignment.Stretch;
theItem.Content = layoutGrid;
The first result, the one obtained from using that XAML, is the desired one. What am I not doing in the C# to make the rectangle fill up the rest of the space?
Thanks,
Lunchboxtheman