Xaml 为什么我的AppBarButton从TextBlock样式继承边距?
我正在使用Windows8商店桌面应用程序,我的AppBar按钮在底部AppBar中出现了一个奇怪的问题 下面是my BottomAppBar的代码,用于显示xaml中没有设置任何内容:Xaml 为什么我的AppBarButton从TextBlock样式继承边距?,xaml,winrt-xaml,Xaml,Winrt Xaml,我正在使用Windows8商店桌面应用程序,我的AppBar按钮在底部AppBar中出现了一个奇怪的问题 下面是my BottomAppBar的代码,用于显示xaml中没有设置任何内容: <Page.BottomAppBar> <CommandBar Background="SlateGray"> <AppBarButton Label="UseGPS" Icon="Targ
<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>
当该行被注释掉时,我会得到如下正常外观的图标:
我尝试过为CommandBar和AppBarButton设置Style={x:Null}
,也尝试过为两者设置Margin=0
,但都没有解决问题。我不明白为什么样式定位文本块会导致图标夹在AppBarButton中。我不能只是注释掉样式的setter,因为它实际上是TextBlocks所需要的,所以如果任何人有一个解决方案不涉及删除该setter,我将非常感激。所以原因是,因为图标实际上只是来自使用Segoe MDL2资产font并在运行时呈现为TextBlock的。因此继承了TargetType
您可以很容易地在如下实例中关闭该继承:
<CommandBar Background="SlateGray">
<CommandBar.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="0"/>
</Style>
</CommandBar.Resources>
<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>
希望这能有所帮助,干杯。你的图标来自字体吗?@ChrisW。我的图标是xaml提供的内置图标。您的修复程序运行良好,您也解释了为什么会发生这种情况,谢谢@GordonAllocman嘿,前几天我从你的一个答案中学到了一些东西,所以这是相互的。:)
<CommandBar Background="SlateGray">
<CommandBar.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="0"/>
</Style>
</CommandBar.Resources>
<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>