- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试更改页面上单个 AppBarButton
的颜色
我可以通过在我的 App.xaml
中设置这些值来更改它,但它们会在整个应用程序中发生变化
<SolidColorBrush x:Key="AppBarItemBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="AppBarItemDisabledForegroundThemeBrush" Color="#66000000" />
<SolidColorBrush x:Key="AppBarItemForegroundThemeBrush" Color="#FF3399FF" />
<SolidColorBrush x:Key="AppBarItemPointerOverBackgroundThemeBrush" Color="#3D000000" />
<SolidColorBrush x:Key="AppBarItemPointerOverForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="AppBarItemPressedForegroundThemeBrush" Color="#FFFFFFFF" />
因此尝试设置一个我可以随时使用的特定样式我使用它并更改 Setter
和 中的
但我唯一看到的是图标周围的环,图标本身和按钮的文本都丢失了Foreground
颜色VisualState 正常
<Style x:Key="HeaderButtonStyle" TargetType="ButtonBase">
<Setter Property="Foreground" Value="White"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="FontFamily" Value="Segoe UI Symbol"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="AutomationProperties.ItemType" Value="App Bar Button"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ButtonBase">
<Grid x:Name="RootGrid" Width="100" Background="Transparent">
<StackPanel VerticalAlignment="Top" Margin="0,12,0,11">
<Grid Width="40" Height="40" Margin="0,0,0,5" HorizontalAlignment="Center">
<TextBlock x:Name="BackgroundGlyph" Text="" FontFamily="Segoe UI Symbol" FontSize="53.333" Margin="-4,-19,0,0" Foreground="{StaticResource AppBarItemBackgroundThemeBrush}"/>
<TextBlock x:Name="OutlineGlyph" Text="" FontFamily="Segoe UI Symbol" FontSize="53.333" Margin="-4,-19,0,0"/>
<ContentPresenter x:Name="Content" HorizontalAlignment="Center" Margin="-1,-1,0,0" VerticalAlignment="Center"/>
</Grid>
<TextBlock
x:Name="TextLabel"
Text="{TemplateBinding Name}"
Foreground="{TemplateBinding Foreground}"
Margin="0,0,2,0"
FontSize="12"
TextAlignment="Center"
Width="88"
MaxHeight="32"
TextTrimming="WordEllipsis"
Style="{StaticResource BaseTextBlockStyle}"/>
</StackPanel>
<Rectangle
x:Name="FocusVisualWhite"
IsHitTestVisible="False"
Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
StrokeEndLineCap="Square"
StrokeDashArray="1,1"
Opacity="0"
StrokeDashOffset="1.5"/>
<Rectangle
x:Name="FocusVisualBlack"
IsHitTestVisible="False"
Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}"
StrokeEndLineCap="Square"
StrokeDashArray="1,1"
Opacity="0"
StrokeDashOffset="0.5"/>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ApplicationViewStates">
<VisualState x:Name="FullScreenLandscape"/>
<VisualState x:Name="Filled"/>
<VisualState x:Name="FullScreenPortrait">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TextLabel" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Width">
<DiscreteObjectKeyFrame KeyTime="0" Value="60"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Snapped">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TextLabel" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Width">
<DiscreteObjectKeyFrame KeyTime="0" Value="60"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="OutlineGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="White"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemPressedForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemPointerOverBackgroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemPointerOverForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="OutlineGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemPressedForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="OutlineGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemDisabledForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemDisabledForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TextLabel" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemDisabledForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="FocusVisualWhite"
Storyboard.TargetProperty="Opacity"
To="1"
Duration="0"/>
<DoubleAnimation
Storyboard.TargetName="FocusVisualBlack"
Storyboard.TargetProperty="Opacity"
To="1"
Duration="0"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Unfocused" />
<VisualState x:Name="PointerFocused" />
</VisualStateGroup>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked">
<Storyboard>
<DoubleAnimation Duration="0" To="0" Storyboard.TargetName="OutlineGlyph" Storyboard.TargetProperty="Opacity"/>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundCheckedGlyph" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemPressedForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unchecked"/>
<VisualState x:Name="Indeterminate"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我从这个链接得到的风格 http://msdn.microsoft.com/en-us/library/windows/apps/dn481531.aspx
我还需要更改什么?
最佳答案
ContentPresenter 行缺少“内容”属性。在这两个地方将 TargetType 从 ButtonBase 更改为 AppBarButton,并将“Content="{TemplateBinding Icon}"添加到 ContentPresenter 属性,然后您应该会看到该图标。
您的样式与默认的 AppBarButton 样式完全不同。除非我遗漏了您正在尝试做的事情,否则我建议您从以下位置复制整个样式: http://msdn.microsoft.com/en-us/library/windows/apps/dn481531.aspx并使用它。
关于c# - 更改页面上 AppBarButton 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21534712/
在我的 Windows Phone 8.1 中有以下 CommandBar(我使用的是通用模板):
根据某些条件,我在运行时更新 AppBarButton 图标时遇到问题。 我正在尝试使用此代码更新某些代码中的 Icon 属性 WeekButton.Icon = new FontIcon() {
我正在尝试更改页面上单个 AppBarButton 的颜色 我可以通过在我的 App.xaml 中设置这些值来更改它,但它们会在整个应用程序中发生变化 因此尝试设置一个我可以随时使用的特定
在我的 Windows 10 通用应用程序中,我在页面中有一个 AppBarButton: 我想检查是否 Icon="Pin" 然后 UnPin 它,反之亦然。 所以我试着这样写代码: priv
注意:这个问题仅涉及 AppBarButton 图标。 在编写在所有外形尺寸上运行的 UWP 应用程序时,我希望包含 AppBarButton 图标的所有必要变体。 从我到目前为止所读到的内容来看,我
尝试在 CommandBar 上使用新的 IsDynamicOverflowEnabled 属性时,我遇到了溢出的样式问题。问题如下,当 AppBarButton 的 Style 未被覆盖并掉落到 O
如何检测 AppBarButton 是否被按住?有一个 Holding 事件,但它永远不会触发,即使我将 AppBarButton 的属性 IsHoldingEnabled 设置为 true。甚至当我
AppbarButton FontSize 未更改。 我试过的是什么? AppbarButton =new AppbarButton(); BitmapIcon BitmapIcon = new Bi
当我尝试在 AppBarButton 元素中放置一个文本框时,我遇到了 template10 ( https://github.com/Windows-XAML/Template10) 的一个奇怪问题
我有一个通用 WinRT 应用程序,我正在尝试实现全局异常处理,以便我可以提示用户向我发送一份报告,其中包含我收集的额外诊断信息。 (额外的诊断信息是我无法使用将登录到开发门户的内置处理程序的原因)。
在 Windows 10 UWP Xaml 应用程序 AppBarButton 控件中,可以定义自定义图标。然而,似乎没有办法将标签放置在按钮内,因此如果您想要更大的图标,则不能,因为标签与图标重叠。
我有一个简单的数据页面,用户在其中填写 2 个字段(名字和姓氏)并单击保存 AppBarButton在 CommandBar 上. 这两个字段都使用 x:Bind与 Mode=TwoWay加载/更新值
我有两个 AppBarButton它们被放置在一个网格中。当没有附加弹出按钮时,它们按预期显示,但是在我附加弹出按钮时,系统会在图标右侧添加一个 V 形/箭头。 如何移除 V 形/箭头?我意识到这可能
如何将 AppBarButton 图标添加到 Windows Phone 8.1 中的普通按钮? 在this page的底部您可以看到正在使用的 AppBarButton 图标。我怎样才能做到与普通按
Microsoft 文档指出您可以使用 SVG 矢量图形文件设置图标:https://learn.microsoft.com/en-us/windows/uwp/design/style/icons
我是 Windows 8 应用开发新手,无法让我的 XAML 文件识别用于添加 AppBar 和 CommandBar 的生成代码。 对于我尝试添加的许多元素,我收到错误“XML 命名空间中的未知类型
我想知道如何使 AppBarButton 图标具有 2 行文本。我想让它像在 Windows 日历中一样: 最佳答案 AppBarButton 不在其图标中显示文本或任意 Xaml。它需要是来自字体、
我在 Windows Phone 8.1 RT 应用程序中有一个非常简单的场景。 这是一个全新的Page ,不涉及其他代码。在真实设备和模拟器中,从不调用 T
我是一名优秀的程序员,十分优秀!