【问题标题】:ItemTemplate Grid width in Silverlight ListBoxSilverlight 列表框中的 ItemTemplate 网格宽度
【发布时间】:2010-10-30 17:58:31
【问题描述】:

我有一个使用 DataTemplate 作为 ItemTemplate 的 Silverlight ListBox。我的 DataTemplate 和 ListBox 显示在这里:

<DataTemplate x:Key="myTemplate">
  <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}" />

运行此代码时,我发现每个 Persons 的生日都不是完全右对齐的。相反,它相对于特定项目是右对齐的。我希望 ItemTemplates Grid 拉伸为 ListBox 的整个宽度。我该怎么做呢?我究竟做错了什么?

【问题讨论】:

    标签: silverlight


    【解决方案1】:

    找到答案here

    【讨论】:

      猜你喜欢
      • 2016-02-10
      • 2011-01-12
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 2012-03-03
      • 1970-01-01
      相关资源
      最近更新 更多