Metro中listbox点击后整个背景不变色

来源:互联网 发布:达拉斯2000年人口数据 编辑:程序博客网 时间:2024/06/07 02:49

只需在 App.xaml 中更新画笔ListBoxFocusBackgroundThemeBrush

<SolidColorBrush x:Key="ListBoxFocusBackgroundThemeBrush" Color="Transparent" />



以下为metro样式的补充

metro UI控件系统样式文件位置,这里可以找到所有控件的系统样式

C:\Program Files (x86)\Windows Kits\8.0\Include\WinRT\Xaml\Design\generic.xaml


metro ListBox官方文档如下

ListBox 样式和模板

此主题尚未评级 评价此主题

本主题介绍 ListBox 控件的样式和模板。 你可以修改这些资源和默认 ControlTemplate 以便为该控件提供一个唯一的外观。

视觉状态

这些状态是在该控件的默认样式中定义的 VisualState

VisualState 名称VisualStateGroup 名称描述NormalCommonStates默认状态。DisabledCommonStates禁用控件。FocusedFocusStates控件具有焦点。UnfocusedFocusStates控件没有焦点。

 

有关焦点状态的详细信息,请参阅 Control.FocusState

主题资源

这些资源在该控件的默认样式中使用。

深色主题画笔

若要在深色主题下更改该控件的颜色,请在 App.xaml 中替代这些画笔。

XAML
<SolidColorBrush x:Key="ListBoxBackgroundThemeBrush" Color="#CCFFFFFF" /><SolidColorBrush x:Key="ListBoxBorderThemeBrush" Color="Transparent" /><SolidColorBrush x:Key="ListBoxDisabledForegroundThemeBrush" Color="#66FFFFFF" />  <SolidColorBrush x:Key="ListBoxFocusBackgroundThemeBrush" Color="#FFFFFFFF" /><SolidColorBrush x:Key="ListBoxForegroundThemeBrush" Color="#FF000000" />

浅色主题画笔

若要在浅色主题下更改该控件的颜色,请在 App.xaml 中替代这些画笔。

XAML
<SolidColorBrush x:Key="ListBoxBackgroundThemeBrush" Color="#CCFFFFFF" /><SolidColorBrush x:Key="ListBoxBorderThemeBrush" Color="#45000000" /><SolidColorBrush x:Key="ListBoxDisabledForegroundThemeBrush" Color="#66000000" /><SolidColorBrush x:Key="ListBoxFocusBackgroundThemeBrush" Color="#FFFFFFFF" /><SolidColorBrush x:Key="ListBoxForegroundThemeBrush" Color="#FF000000" />

其他资源

XAML
<Thickness x:Key="ListBoxBorderThemeThickness">2</Thickness>

共享资源

该控件模板使用这些资源与其他控件模板共享。更改这些值将影响使用这些资源的其他控件。

XAML
<FontFamily x:Key="ContentControlThemeFontFamily">Segoe UI</FontFamily><x:Double x:Key="ControlContentThemeFontSize">14.667</x:Double>

默认样式

XAML
<!-- Default style for Windows.UI.Xaml.Controls.ListBox --><Style TargetType="ListBox">    <Setter Property="Foreground" Value="{StaticResource ListBoxForegroundThemeBrush}" />    <Setter Property="Background" Value="{StaticResource ListBoxBackgroundThemeBrush}" />    <Setter Property="BorderBrush" Value="{StaticResource ListBoxBorderThemeBrush}" />    <Setter Property="BorderThickness" Value="{StaticResource ListBoxBorderThemeThickness}" />    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />    <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />    <Setter Property="ScrollViewer.IsHorizontalRailEnabled" Value="True" />    <Setter Property="ScrollViewer.VerticalScrollMode" Value="Enabled" />    <Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="True" />    <Setter Property="ScrollViewer.ZoomMode" Value="Disabled" />    <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />    <Setter Property="ScrollViewer.BringIntoViewOnFocusChange" Value="True" />    <Setter Property="IsTabStop" Value="False" />    <Setter Property="TabNavigation" Value="Once" />    <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}" />    <Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}" />    <Setter Property="ItemsPanel">        <Setter.Value>            <ItemsPanelTemplate>                <VirtualizingStackPanel />            </ItemsPanelTemplate>        </Setter.Value>    </Setter>    <Setter Property="Template">        <Setter.Value>            <ControlTemplate TargetType="ListBox">                <Border x:Name="LayoutRoot"                         Background="{TemplateBinding Background}"                        BorderBrush="{TemplateBinding BorderBrush}"                        BorderThickness="{TemplateBinding BorderThickness}">                    <VisualStateManager.VisualStateGroups>                        <VisualStateGroup x:Name="CommonStates">                            <VisualState x:Name="Normal" />                            <VisualState x:Name="Disabled">                                <Storyboard>                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot"                                                                   Storyboard.TargetProperty="Background">                                        <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />                                    </ObjectAnimationUsingKeyFrames>                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot"                                                                   Storyboard.TargetProperty="BorderBrush">                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxDisabledForegroundThemeBrush}" />                                    </ObjectAnimationUsingKeyFrames>                                </Storyboard>                            </VisualState>                        </VisualStateGroup>                        <VisualStateGroup x:Name="FocusStates">                            <VisualState x:Name="Focused">                                <Storyboard>                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot"                                                                   Storyboard.TargetProperty="Background">                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxFocusBackgroundThemeBrush}" />                                    </ObjectAnimationUsingKeyFrames>                                </Storyboard>                            </VisualState>                            <VisualState x:Name="Unfocused"/>                        </VisualStateGroup>                    </VisualStateManager.VisualStateGroups>                    <ScrollViewer x:Name="ScrollViewer"                                  Padding="{TemplateBinding Padding}"                                  TabNavigation="{TemplateBinding TabNavigation}"                                  HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"                                  HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"                                  VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"                                  VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"                                  IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"                                  IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"                                  ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}"                                  IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"                                  BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}">                        <ItemsPresenter />                    </ScrollViewer>                </Border>            </ControlTemplate>        </Setter.Value>    </Setter></Style>


原创粉丝点击