1

I'm working on a Windows Store App. I'm new to XAML development.

I'm trying to get some elements within a Grid to be sized relative to each other. After looking at questions like this (What does the WPF star do (Width="100*")) I thought I had it all figured out. The following example does not seem to do what I expect however.

Instead of seeing 'Foo' on the left and 'Bar' on the further on the right (since Foo's column should be six times the size), I just see 'FooBar'. Anyone know what is going on?

    <Grid Margin="10">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="6*" />
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>

      <TextBlock Grid.Column="0" Text="Foo" />
      <TextBlock Grid.Column="1" Text="Bar" />
    </Grid>
Community
  • 1
  • 1
  • Have you tried adding `HorizontalAlignment="Stretch"` on the `` element? – Alyce Jun 03 '13 at 02:50
  • Your code works perfectly fine. But note; I didn't have a `size` on the `Window`..Can you try removing the default size on the `window` element.. – jacob aloysious Jun 03 '13 at 02:54
  • Can we see the `window` element of your `xaml`..If that is the only other code in your `xaml` – jacob aloysious Jun 03 '13 at 02:57
  • This is actually in a Windows Store app - no Window element. It's also nested pretty deep in a few stack panels and other grids. However, It has one half of the screen all to itself. When I set the column definitions to hard values like 600 and 100, it works fine. – Ian Michael Williams Jun 03 '13 at 03:11

1 Answers1

1

According to this tutorial star sizing does not work if your grid size is determined by the content (as opposed to its container). You might try specifying a width for the grid, or having it stretch to fill the container.

Brian Rogers
  • 125,747
  • 31
  • 299
  • 300
  • This is more or less the root cause. In my case, I had this grid as the DataTemplate in a ListView. I needed to set the ItemContainerStyle property of the ListView a certain way to get it so the grid would always fill the container to avoid this issue. – Ian Michael Williams Jun 03 '13 at 06:01