1

This is my XAML:

<ListView ItemsSource="{Binding Items}">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Property1" DisplayMemberBinding="{Binding Property1}" />
            <GridViewColumn Header="Property2" DisplayMemberBinding="{Binding Property2}" />
        </GridView>
    </ListView.View>
</ListView>

I want these 2 columns to take up the width of ListView in 1:1 ratio.

How can I achieve this?


Edit: I found this suggestion on MS Connect. This would perfectly solve my problem. However it is closed as postponed (for 2.5 years now..)

Kugel
  • 19,354
  • 16
  • 71
  • 103

1 Answers1

1

What comes to mind is using internal Grids in the templates which each have a ColumnDefinition with the same SharedSizeGroup, the GridView should then have Grid.IsSharedSizeScope="True" and the columns of the grid view should themselves be unresizable (if that is possible), cannot test that right now so it's a bit sketchy.

Another method would be to bind both Widths of the GridViewColumns to the width of the ListView and then use a custom converter to get an appropriate fraction of that back.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • +1, Potentially Blend could be used to discover what the "template" looks like for the `GridView`, which may enable restyling the columns. However, my gut says binding the `Width` to a converter set to half the `ActualWidth` of the `ListView` is probably going to be the only way without writing his own `ViewBase`. – user7116 Feb 08 '11 at 16:13
  • @sixlettervariables I tried exactly that and it gave me a horizontal scrollbar. I think I need something less than 2 halves. – Kugel Feb 08 '11 at 21:37
  • @Kugel: You could just force the scrollbar to be off, you won't be needing it anyway, it's just a pixel or two :P – H.B. Feb 08 '11 at 21:39
  • I tried the SharedSizeGroup solution and it had no effect. – Simon F May 02 '14 at 15:47
  • @SimonF: See this answer in case you expected them to space out across the available space: http://stackoverflow.com/questions/4664008/grids-sharedsizegroup-and-sizing/4664030#4664030 – H.B. May 02 '14 at 15:51