I have a data template formatting items in a ListBox
<DataTemplate x:Key="ChildViewModelTemplate">
<Border BorderBrush="#FFDC1C1C" BorderThickness="1" >
<Grid>
<TextBlock Text="{Binding Path=DisplayName}"></TextBlock>
<Image Height="Auto" Margin="0,0,2,0" VerticalAlignment="Stretch" HorizontalAlignment="Right" Width="31" Source="pack://siteoforigin:,,,/rocket.ico"/>
</Grid>
</Border>
</DataTemplate>
This puts a border around each item extending to the length of the text string bound in the TextBlock binding.
Is there a simple way to have all elements the same width, where the width is equal to the longest element? For bonus points I’m wondering if there is a way to do it for the longest visible element and/or longest element regardless if it’s visible.
Thanks
You might want to have a look at the Grid.IsSharedSizeScope and SharedSizeGroup Properties.
Here’s a tutorial for it:
http://blogs.interknowlogy.com/johnbowen/archive/2007/08/27/21132.aspx