开发者

ItemTemplate Grid width in Silverlight ListBox

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜