I have some text data that I want to display in a grid, with three columns, the middle column being twice as wide as the other two, taking up the full width of the grid. The text is long and needs to be wrapped. What I can't get to work (and from other queries here in the past, I see others have had similar problems) is getting word wrap and sizing to the grid to work. What I have is:
<Window.Resources>
<local:DTData x:Key="dtData" />
</Window.Resources>
<StackPanel DataContext="{StaticResource dtData}">
<ListBox ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border x:Name="a" Grid.Column="0" Margin="4"/>
<TextBlock Margin="4" Grid.Column="0" TextWrapping="Wrap"
Text="{Binding A}" Width="{Binding ActualWidth, ElementName=a }" MinWidth="100"/>
<Border x:Name="b" Grid.Column="1" Margin="4"/>
<TextBlock Margin="4" Grid.Column="1" TextWrapping="Wrap"
Text="{Binding B}" Width="{Binding ActualWidth, ElementName=b }" MinWidth="100"/>
<Border x:Name="c" Grid.Column="2" Margin="4"/>
<TextBlock Margin="4" Grid.Column="2" TextWrapping="Wrap"
Text="{Binding C}" Width="{Binding ActualWidth, ElementName=b }" MinWidth="100"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This uses the Border trick from http://stackoverflow.com/questions/386039/wpf-textbox-and-scroll-behavior to force text wrapping to work but the column's width is either the minimum width set or the longest word if greater.
Does anyone know of a way to force the columns to fit the width of the grid?