开发者

ItemTemplate Grid width in Silverlight ListBox

开发者 https://www.devze.com 2023-01-22 12:30 出处:网络
I have a Silverlight ListBox that uses a DataTemplate for the ItemTemplate. My DataTemplate and ListBox are shown here:

I have a Silverlight ListBox that uses a DataTemplate for the ItemTemplate. My DataTemplate and ListBox are shown here:

<DataTemplate x:Key="myT开发者_StackOverflow社区emplate">
  <Grid Background="Green" HorizontalAlignment="Stretch">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
      <ColumnDefinition />
      <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>

    <TextBlock Text="{Binding Name}" Grid.ColumnSpan="2" />
    <TextBlock Text="{Binding PhoneNumber}" Grid.ColumnSpan="2" Grid.Row="1" />
    <TextBlock Text="{Binding Age}" Grid.Row="2" />

    <TextBlock Grid.Column="1" Grid.Row="2" HorizontalAlignment="Right" 
      Text="{Binding BirthDate}" />
  </Grid>
</DataTemplate>

<ListBox x:Name="myListBox" Background="Yellow"
  ItemTemplate="{StaticResource myTemplate}" 
  ItemsSource="{Binding People}" />

When running this code, I have discovered that each Persons birthdate is not fully right-aligned. Rather, it is right-aligned in relation to the specific item. I want the ItemTemplates Grid to stretch to be the full width of the ListBox. How do I do this? What am I doing wrong?


Found the answer here

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号