我有一个绑定(bind)到 GridView 的项目列表。该列表包含多种类型的数据。我使用 ItemTemplateSelector 将 DataTemplate 应用于不同的数据类型,因此它们都具有独特的外观。
我不知道如何在没有 DataTriggers 的情况下消除 SubClass1 的 DataTemplate 中 GridViewItem 的悬停效果。
public class Base
{
public string Name {get;set;}
}
public class SubClass1 : Base
{
}
public class SubClass2 : Base
{
}
public PageViewModel : ViewModelBase
{
public List<Base> ListOfBases {get;set;}
}
<GridView
x:Name="baseGridView"
ItemsSource="{Binding ListOfBases}"
ItemTemplateSelector="{StaticResource itemsTemplateSelector}"
SelectionMode="Multiple"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
>
<DataTemplate x:Key="SubClass1Template">
<Grid Margin="0" Width="346" VerticalAlignment="Stretch" >
<TextBlock Grid.Column="0" Text="{Binding Name}" />
</Grid>
</DataTemplate>
最佳答案
您将需要编辑 GridViewItem 的 VisualState 样式。为此,请右键单击 VisualStudio 或 Blend 中的 GridView。在设计 View 或文档大纲中执行此操作。选择编辑附加模板 -> 编辑生成的项目容器 (ItemContainerStyle) -> 编辑副本
如果你想完全删除它,删除 PointerOver 状态内的元素
<VisualState x:Name="PointerOver"/>
您也可以使用它对其进行任何更改。也许您不喜欢默认的悬停颜色,但与其他人一样,您可以在此处进行这些更改。
更新基于评论
要仅具有特定类的悬停样式,请将用于悬停样式(例如:边框)的控件的可见性设置为直接绑定(bind)到该类。然后 ValueConverter 将根据类的类型返回 Visible 或 Collapsed
关于winrt-xaml - WinRT : How do I set the hover over affect for a specific GridIViewtem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13367986/