App.xaml中的非键控样式不会应用于用户控件

时间:2014-02-03 14:30:17

标签: c# .net wpf xaml

在我的C#/ WPF / .NET 4.5项目中,我的 App.xaml 包含以下内容:

<Application x:Class="HsWpfApplication.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="MainWindow.xaml">
  <Application.Resources>
    <Style x:Key="h1" TargetType="{x:Type TextBlock}">
      <Setter Property="FontFamily" Value="Segoe UI Light" />
      <Setter Property="FontSize" Value="20pt" />
      <Setter Property="VerticalAlignment" Value="Center"/>
    </Style>
    <!-- ... -->
    <Style TargetType="{x:Type Button}">
      <Setter Property="FontFamily" Value="Segoe UI Symbol" />
      <Setter Property="FontSize" Value="11pt" />
      <Setter Property="Margin" Value="0,10"/>
      <Setter Property="HorizontalAlignment" Value="Center"/>
      <Setter Property="VerticalAlignment" Value="Center"/>
      <Setter Property="BorderBrush" Value="DarkGray"/>
    </Style>
    <!-- ... -->
  </Application.Resources>
</Application>

我还有一个用户控件,在子命名空间HsWpfApplication.Controls下,按以下方式定义:

<UserControl x:Class="HsWpfApplication.Controls.Manager"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    mc:Ignorable="d" 
    d:DesignHeight="600" d:DesignWidth="300">

  <UserControl.Resources>
    <DataTemplate x:Key="ManagerItemDataTemplate">
      <!-- ... -->
    </DataTemplate>
  </UserControl.Resources>

  <Grid>
    <!-- -->
    <Grid Grid.Row="0">
      <TextBlock Style="{StaticResource h1}" Margin="10,0,0,0" HorizontalAlignment="Left">Manager</TextBlock>
      <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
        <Button Command="{Binding CreateNewItemCollectionCommand}"
            ToolTip="New Item Collection"
            Margin="0,10,10,10"
            Width="40" Height="40"
            FontSize="18"
            Content="&#xE130;"/>
        <!-- ... -->
      </StackPanel>
    </Grid>
    <!-- ... -->
  </Grid>
</UserControl>

键控样式h1适用于TextBlock就好了。我想要应用于Button的非键控样式不起作用:

enter image description here

如何在 App.xaml 文件中获取非键控样式以影响我的用户控件?

1 个答案:

答案 0 :(得分:0)

您是否尝试为隐式样式添加一个非常明显的值?我会建议FontSize ='48'或类似的东西。也许问题是您的系统上没有“Segoe UI Symbol”?