2012-11-30 24 views
4

可以使用不同的颜色设置AutomationProperties.Name值的样式吗? 我从应用程序中的黑暗主题中获取基本文字颜色。我有一个自定义背景色和这就是为什么我需要一个特定的ForegroundColorTextColor此属性(Value="OtherUserAppBarButton"TopAppBar按钮Windows应用商店应用中的AutomationProperties样式

<Style x:Key="LogoutAppBarButtonStyle" TargetType="ButtonBase" 
       BasedOn="{StaticResource AppBarButtonStyle}"> 
    <Setter Property="AutomationProperties.AutomationId" Value="OtherUserAppBarButton"/> 
    <Setter Property="AutomationProperties.Name" Value="Other User"/> 
    <Setter Property="Content" Value="&#xE1A6;"/> 
    <Setter Property="Foreground" Value="#ffffffff" /> 
</Style> 

有人偷的想法?

回答

3

为了达到这个目的,您需要修改AppBarButtonStyle,这是您基于您的按钮样式。你可以在你的项目中找到Common\StandardStyles.xaml。如果您还需要未经修改的样式,则可以直接在此文件中修改样式或在App.xaml中创建它的副本。

您需要更改里面以下块样式的ControlTemplate

<TextBlock 
    x:Name="TextLabel" 
    Text="{TemplateBinding AutomationProperties.Name}" 
    Foreground="{StaticResource AppBarItemForegroundThemeBrush}" 
    Margin="0,0,2,0" 
    FontSize="12" 
    TextAlignment="Center" 
    Width="88" 
    MaxHeight="32" 
    TextTrimming="WordEllipsis" 
    Style="{StaticResource BasicTextStyle}"/> 

正如你可以看到Foreground属性固定为AppBarItemForegroundThemeBrush。您可以将其更改为{TemplateBinding Foreground},使其与您在LogoutAppBarButtonStyle中设置的颜色相匹配,或者您可以直接在模板中为其指定另一种自定义固定颜色。

另外不要忘记其他视觉状态(PointerOver,Pressed, DisabledChecked)的样式。他们也被设置为主题颜色。您可以在VisualStateManager内更改模板