【发布时间】:2016-04-13 17:41:45
【问题描述】:
我正在开发一个 Windows 8 商店桌面应用程序,我在 BottomAppBar 中的 AppBarButton(s) 遇到了一个奇怪的问题。
这是我的 BottomAppBar 的代码,只是为了表明那里的 xaml 中没有设置任何内容:
<Page.BottomAppBar>
<CommandBar Background="SlateGray">
<AppBarButton Label="UseGPS"
Icon="Target"/>
<AppBarButton Label="Reset"
Icon="Clear"/>
<AppBarButton Label="Save to File"
Icon="Save" />
<AppBarSeparator />
<AppBarButton Label="Copy Longitude"
Icon="Copy"/>
<AppBarButton Label="Copy Latitude"
Icon="Copy" />
</CommandBar>
</Page.BottomAppBar>
真正的问题在于我的 Generic.Xaml 资源字典中的这个 xaml 代码:
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment"
Value="Center" />
<Setter Property="FontFamily"
Value="Segoe UI" />
<Setter Property="FontSize"
Value="26" />
<Setter Property="Foreground"
Value="{StaticResource ApplicationForegroundThemeBrush}" />
<Setter Property="Margin"
Value="10,0" />
</Style>
特别是这一行:<Setter Property="Margin" Value="10,0" />
使用此代码,按钮的图标会被剪掉:
当该行被注释掉时,我会看到像这样的正常图标:
我尝试为 CommandBar 和 AppBarButton 设置Style={x:Null},我也尝试为两者设置Margin=0,但都没有解决问题。我不明白为什么以 TextBlock 为目标的样式会导致图标在 AppBarButton 中剪辑。我不能只注释样式的 setter,因为 TextBlocks 实际上需要它,所以如果有人有不涉及删除该 setter 的解决方案,我将非常感激。
【问题讨论】:
-
你的图标是字体吗?
-
@ChrisW。我的图标是 xaml 提供的内置图标
标签: xaml winrt-xaml