【问题标题】:Why window shows style at design time and not at run time为什么窗口在设计时而不是在运行时显示样式
【发布时间】:2014-10-17 22:43:30
【问题描述】:

我创建了全新的 wpf 应用程序,在 MainWindow.xaml 上我有:

为什么我在运行该应用程序时看不到相同的字体?我拥有的 xaml 代码是:

<Window.Resources>
    <Style TargetType="{x:Type Window}" >
        <Setter Property="FontFamily" Value="Arial Black"/>
    </Style>
</Window.Resources>

<StackPanel>
    <TextBlock>This is a TextBlock</TextBlock>
    <Label>This is a Label</Label>
</StackPanel>

【问题讨论】:

    标签: wpf xaml resources styles


    【解决方案1】:

    这是一个已知问题,您可能需要在窗口上设置显式样式。

    在应用程序资源中定义样式,或者使用资源字典合并样式

    例如

    <Style x:Key="myWindowStyle" TargetType="{x:Type Window}" >
        <Setter Property="FontFamily" Value="Arial Black"/>
    </Style>
    

    使用相同

    <Window Style="{StaticResource myWindowStyle}" ... />
    

    如果你只是想统一应用程序中的字体,那么也许使用TextElement.FontFamily

    样本

    <Window TextElement.FontFamily="Arial Black" ... />
    

    这将帮助您在所有子元素上应用相同的字体,除非明确指定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      • 1970-01-01
      • 2019-06-14
      • 2010-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多