[英]Non-keyed styles in App.xaml do not get applied to user controls
在我的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文件中获得非键样式来影响用户控件?
您是否尝试过为隐式样式添加非常明显的价值? 我建议FontSize = '48'或类似的东西。 也许问题在于您的系统上没有“ Segoe UI符号”?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.