Results 1 to 3 of 3

Thread: Rectangles and Grids

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    68

    Rectangles and Grids

    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
    Code:
    <ListBoxItem HorizontalContentAlignment="Stretch">
    . . .
    <Rectangle Fill="Red" Grid.ColumnSpan="2" Grid.RowSpan="3" />
    . . .
    For the second, I'm using the C# code below
    Code:
                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
    Attached Images Attached Images  
    Last edited by lunchboxtheman; Dec 26th, 2009 at 10:29 PM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    68

    Re: Rectangles and Grids

    *smack*
    In the XAML I had the width of the last column def to "*" and in the C# I had it set to "Auto".

    I still don't understand the difference between the two, and where and when they can be applied. I'll have to read up more on that.

    Thanks,
    Lunchboxtheman

  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Rectangles and Grids

    Auto means it will try to automatically size to the contents of the column, * means the columns will take up all available space
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width