Xaml 更改列表视图selecteditem数据模板UWP
我试图更改listview中所选项目的datatemplate,我发现的所有内容都过于复杂或过时。 我尝试过使用行为学,但仍然不起作用。这就是我想要的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"/&
<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
,它看起来像是我在过去一个小时里一直在玩弄的解决方案的可能副本,我无法让它工作