![](/img/trans.png)
[英]MahApps.Metro MetroWindow.ShowMessageAsync does not exist
[英]MahApps.Metro button fontsize is not inherited from metrowindow
我開始學習WPF,並且選擇MahApps.Metro進行樣式設計,因為它看起來很酷。 我面臨的問題是,更改MetroWindow的字體后,WindowCommandButton的字體會相應更新,但按鈕的字體不會更新。 我繼續看到細小的文本按鈕。
到目前為止,我的XAML看起來像這樣
<MahApps:MetroWindow
x:Class="MetroSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MetroSample"
xmlns:MahApps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
mc:Ignorable="d"
Title="Metro Sample"
Height="350" Width="525"
WindowStartupLocation="CenterScreen"
GlowBrush="{DynamicResource AccentColorBrush}" FontFamily="Lucida Sans Unicode" FontSize="14.667">
<MahApps:MetroWindow.RightWindowCommands>
<MahApps:WindowCommands>
<Button x:Name="btnReqLogs">
<StackPanel Orientation="Horizontal">
<Rectangle Width="20" Height="20" Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Fill" Visual="{StaticResource appbar_book_list}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Margin="4 0 0 0" VerticalAlignment="Center" Text="Request Logs" />
</StackPanel>
</Button>
<Button x:Name="btnSettings">
<StackPanel Orientation="Horizontal">
<Rectangle Width="20" Height="20" Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Fill" Visual="{StaticResource appbar_settings}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Margin="4 0 0 0" VerticalAlignment="Center" Text="Settings" />
</StackPanel>
</Button>
</MahApps:WindowCommands>
</MahApps:MetroWindow.RightWindowCommands>
<DockPanel LastChildFill="True">
<DockPanel Height="50" DockPanel.Dock="Top" LastChildFill="False">
<Button DockPanel.Dock="Left"
MahApps:ButtonHelper.PreserveTextCase="True" Background="Transparent"
Content="First Button" Padding="10,0" Width="150" Margin="0,0,2,0"/>
<Button DockPanel.Dock="Left"
MahApps:ButtonHelper.PreserveTextCase="True" Background="Transparent"
Content="Second Button" Padding="10,0" Width="150" Margin="0,0,2,0"/>
<Button DockPanel.Dock="Right"
MahApps:ButtonHelper.PreserveTextCase="True" Background="Transparent"
Content="Logout" Padding="10,0" Width="150" Margin="0,0,2,0"/>
</DockPanel>
<StackPanel>
</StackPanel>
</DockPanel>
Button.FontFamily
不繼承自父控件。 它以基本樣式定義:
<Setter Property="FontFamily" Value="{DynamicResource DefaultFont}" />
您可以使用以下命令覆蓋它:
<Style BasedOn="{StaticResource MetroButton}" TargetType="Button">
<Setter Property="FontFamily" Value="Lucida Sans Unicode" />
</Style>
或者,您也可以針對也恰巧通過它使用它的每種樣式全局覆蓋(但不要這樣做):
<FontFamily x:Key="DefaultFont">Lucida Sans Unicode</FontFamily>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.