C# App.xaml中的非键控样式不会应用于用户控件
在我的C#/WPF/.NET 4.5项目中,我的App.xaml包含以下内容:C# App.xaml中的非键控样式不会应用于用户控件,c#,.net,wpf,xaml,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="Mai
<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>
键控样式h1
应用于TextBlock
很好。我希望应用于按钮的非关键帧样式不起作用:
如何在我的App.xaml文件中获取非关键样式以影响我的用户控件?您是否尝试过为隐式样式添加一个非常明显的值?我建议FontSize='48'或类似的东西。可能问题是您的系统上没有“Segoe UI符号”?您是否在用户控件的其他地方定义了按钮样式?我刚刚尝试了相同的设置,它可以工作。。。问题一定是源于代码中没有包含在此处的部分。直接设置为视图中元素的属性会覆盖样式化属性(样式是回退的,而不是相反)
<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>