【问题标题】:XAML: RelativePanel dose not fill the ListviewItem controlXAML:RelativePanel 不填充 ListviewItem 控件
【发布时间】:2018-02-18 13:08:33
【问题描述】:

我的 listview.Itemtemplate 有问题

<ListView.ItemTemplate>
  <DataTemplate>
    <Grid>
      <Grid.RowDefinitions>
         <RowDefinition Height="Auto"/>
         <RowDefinition Height="*"/>
         <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
         <ColumnDefinition Width="Auto"/>
      </Grid.ColumnDefinitions>
      <RelativePanel HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="0" Margin="0,5">
         <TextBlock Margin="5,0,0,0" x:Name="nameTxt" TextWrapping="Wrap" Text="{Binding Name}" FontSize="28"/>
         <TextBlock Margin="5,0,0,0" x:Name="IDtxt" TextWrapping="Wrap" Text="ID: " FontSize="12" RelativePanel.Below="nameTxt" FontWeight="Bold"/>
         <TextBlock x:Name="IDCode" TextWrapping="Wrap" Text="{Binding IDCode}" FontSize="12" RelativePanel.RightOf="IDtxt" RelativePanel.Below="nameTxt"/>
         <TextBlock x:Name="Stato" TextWrapping="Wrap" Text="Stato: " FontSize="20" VerticalAlignment="Center" RelativePanel.AlignRightWithPanel="True"/>
      </RelativePanel>
    </Grid>
  </DataTemplate>
</ListView.ItemTemplate>

我必须将最后一个 textBlock &lt;TextBlock x:Name="Stato"/&gt; 对齐到列表视图的右边缘,但 RelativePanel 似乎在内容的末尾结束并且没有填充网格。

【问题讨论】:

    标签: xaml uwp


    【解决方案1】:

    在这种情况下,父 Grid 实际上也没有填充 ItemTemplate。您需要强制 ItemContainer 水平和垂直拉伸其内容,如下所示:

    <ListView.ItemContainerStyle>
       <Style>
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Stretch" />
       </Style>
    </ListView.ItemContainerStyle>
    

    【讨论】:

      猜你喜欢
      • 2016-09-21
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-27
      相关资源
      最近更新 更多