Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml 更改列表视图selecteditem数据模板UWP_Xaml_Uwp_Win Universal App_Uwp Xaml - Fatal编程技术网

Xaml 更改列表视图selecteditem数据模板UWP

Xaml 更改列表视图selecteditem数据模板UWP,xaml,uwp,win-universal-app,uwp-xaml,Xaml,Uwp,Win Universal App,Uwp Xaml,我试图更改listview中所选项目的datatemplate,我发现的所有内容都过于复杂或过时。 我尝试过使用行为学,但仍然不起作用。这就是我想要的 <UserControl.Rescources> <DataTemplate x:DataType="dt" x:Key="notselected"> <Grid> <Textblock Text="{Binding Title}" Foreground="White"/&

我试图更改listview中所选项目的datatemplate,我发现的所有内容都过于复杂或过时。 我尝试过使用行为学,但仍然不起作用。这就是我想要的

<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即可 这可能吗


谢谢

在您的
列表视图中
您需要设置
ItemTemplateSelector
来实现
DataTemplateSelector
。在上面的代码中,您已经设置了
ItemTemplate


假设
TMP1
指的是您的
datatemplateSelector
,它看起来像是
我在过去一个小时里一直在玩弄的解决方案的可能副本,我无法让它工作