winrt-xaml - WinRT : How do I set the hover over affect for a specific GridIViewtem?

标签 winrt-xaml

我有一个绑定(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/

相关文章:

xaml - 隐藏 Toast 通知窗口中的小 Logo 8

xaml - 使用可绑定(bind)集合启用 ScrollViewer Horizo​​ntalSnapPoints

c# - 如何仅使用 XAML 更改基于点击事件的文本 block 的可见性

c# - ListView : Stretch grid in custom datatemplate to max width?

wpf - 从代码隐藏设置 ContentControls 内容属性会引发异常 'value does not fall in range'

c# - 在控件中的属性更改之前和之后播放动画

winrt-xaml - 如何覆盖或操作 KeyDown : Space or Enter for ListView in UWP?

windows-8 - 如何禁用选择 GridView 中的单个项目

c# - 当 DataTemplate 子项折叠时如何隐藏 ListView 项目占位符?

windows-runtime - 如何在 WinRT 中读取除 UFT8 或 UTF16 之外的其他编码的文本文件?