【问题标题】:Change listview selecteditem datatemplate UWP更改列表视图选定项数据模板 UWP
【发布时间】:2018-02-01 00:43:37
【问题描述】:

我正在尝试更改列表视图中所选项目的数据模板,我发现的所有内容都过于复杂或过时。 我尝试过使用行为,但它仍然不起作用。这就是我所追求的

<UserControl.Rescources>

  <DataTemplate x:DataType="dt" x:Key="notselected">
      <Grid>
       <Textblock Text="{Binding Title}" Foreground="White"/>
       <Image Source="ms-appx:///Assets/myimage.png"/>
     </Grid>
  </DataTemplate>

  <DataTemplate x:DataType="dt" x:Key="selected">
      <Grid>
       <Textblock Text="{Binding Title}" Foreground="Black"/>
       <Image Source="ms-appx:///Assets/myselectedimage.png"/>
     </Grid>
  </DataTemplate>

</UserControl.Rescources>


 <ListView x:Name="listview" ItemTemplate="{StaticResource TMP1}">
   <ListView.ItemContainerStyle>
       <StaticResource ResourceKey="ListViewItemStyle1"/>
   </ListView.ItemContainerStyle>

只是让它在选择时切换到 TMP2 这可能吗?

谢谢

【问题讨论】:

标签: xaml uwp win-universal-app uwp-xaml


【解决方案1】:

在您的ListView 中,您需要将ItemTemplateSelector 设置为DataTemplateSelector 的实现。在上面的代码中,你设置了ItemTemplate

假设 TMP1 指的是您的 DataTemplateSelctor 它看起来像 &lt;ListView x:Name="listview" ItemTemplateSelector="{StaticResource TMP1}"...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 2018-10-16
    • 2021-02-05
    相关资源
    最近更新 更多