在我的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=""/>
<!-- ... -->
</StackPanel>
</Grid>
<!-- ... -->
</Grid>
</UserControl>
键控样式h1
适用于TextBlock
就好了。我想要应用于Button
的非键控样式不起作用:
如何在 App.xaml 文件中获取非键控样式以影响我的用户控件?
答案 0 :(得分:0)
您是否尝试为隐式样式添加一个非常明显的值?我会建议FontSize ='48'或类似的东西。也许问题是您的系统上没有“Segoe UI Symbol”?