首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >鼠标悬停时列表框自定义/禁用选择器(windows8)

鼠标悬停时列表框自定义/禁用选择器(windows8)
EN

Stack Overflow用户
提问于 2012-03-13 06:10:27
回答 2查看 2.5K关注 0票数 0

我想在我的列表框的每一项上禁用鼠标经过时的视觉效果,我也想在用户单击时禁用视觉效果。

我读到可以在Windows Phone上使用DataTrigger,但在Windows8上,我们不能使用DataTrigger:DataTrigger in WinRT?

我还可以使用什么来删除此视觉效果?

我看到了StyleSelector/ListViewItemStyleSelector,我可以使用它吗?

如果是,我在哪里可以找到样本,因为我不知道它是如何工作的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-13 06:16:29

如果您的意思是禁用所选项目样式,那么在WPF中,您可以这样做:

代码语言:javascript
复制
<Style x:Key="NullSelectionStyle" TargetType="ListBoxItem">
    <Style.Resources>
        <!-- SelectedItem with focus -->
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
        <!-- SelectedItem without focus -->
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
        <!-- SelectedItem text foreground -->
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="{DynamicResource {x:Static SystemColors.ControlTextColorKey}}" />
    </Style.Resources>
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>

<ListBox ItemContainerStyle="{StaticResource NullSelectionStyle}" ...>

不幸的是,我还不能使用Windows8,所以我不能说它是否能在WinRT上运行。

或者,如果您根本不需要任何选择,只需使用ItemsControl。

例如,使用<ItemsControl .../>代替<ListBox .../>。ItemsControl显示类似于ListBox的项目列表,但没有所选项目的概念。

票数 3
EN

Stack Overflow用户

发布于 2012-03-15 10:59:18

如果要编辑Metro Style应用程序的ListBox模板,可以从MouseOver VisualState中删除动画。这是一个可以工作的ListBoxItem模板。

代码语言:javascript
复制
<Style x:Key="NoSelectListBoxItemStyle" TargetType="ListBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver"/>
                                    <VisualState x:Name="Disabled">
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="Unselected">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ContentContainer">
                                                <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Selected"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{StaticResource Dark_Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" d:LayoutOverrides="Width"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

并应用样式

代码语言:javascript
复制
<ListBox ItemContainerStyle="{StaticResource NoSelectListBoxItemStyle}" />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9675531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档