bebo bebo - 1 year ago 80
C# Question

WPF ListBox Layout (dynamic column width considering all rows at once)

Is there a way to make sure that the

property considers the
of all elements in a list instead of calculating it individually for every row in the list?

<ListBox x:Name="listBox" HorizontalContentAlignment="Stretch" DockPanel.Dock="Top">
<Grid Margin="0,0,0,5">
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<TextBlock Text="{Binding Name}" />
<TextBlock Grid.Column="1" Text="{Binding Value}" />

I tried this, but as the length of the
is different for each column, the
of the
column of every row is different. Thus the second column starts at a different x position.

Answer Source

You can use SharedSizeGroup property in the ColumnDefinition like this:

<ColumnDefinition SharedSizeGroup="A"/>

Also have a look at this: Grid Size Sharing in WPF.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download