我有一个应用于所有文本框的样式,在资源字典中定义。
<Style TargetType="TextBlock">
<Setter Property="TextBlock.FontSize" Value="{Binding Source={StaticResource ApplicationUserSettings}, Path=fontSize, Mode=OneWay}" />
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.VerticalAlignment" Value="Center"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="TextBox.FontFamily" Value="{Binding Source={StaticResource ApplicationUserSettings}, Path=fontName, Mode=OneWay}"/>
</Style>\
fontsize 和 fontstyle 属性绑定到实现 iNotifyPropertyChanged 的特殊用户设置类,该类允许对字体大小和 fontfamily 的更改立即传播到我的应用程序中。
但是,在我创建的 UserControl 中(具有讽刺意味的是,该屏幕允许用户自定义其字体设置),我希望字体大小和字体系列保持静态。无论我尝试什么,我的全局字体设置都会覆盖我在用户控件中设置的内容:
<UserControl x:Class="ctlUserSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:R2D2" Height="400" Width="600">
<Grid>
<Grid.Resources>
<Style x:Key="tbxStyle" TargetType="TextBox">
<Style.Setters>
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontFamily" Value="Tahoma"/>
</Style.Setters>
</Style>
... ETC...
<StackPanel Margin="139,122.943,41,0" Orientation="Horizontal" Height="33" VerticalAlignment="Top">
<TextBox Style="{x:Null}" FontSize="13" FontFamily="Tahoma" HorizontalAlignment="Left" MaxWidth="500" MinWidth="350" Name="txtReaderPath" Height="Auto" VerticalAlignment="Top" />
<TextBox Style="{x:tbxStyle}" Margin="15,0,0,0" HorizontalAlignment="Left" Name="txtPath" Width="43" Height="23" VerticalAlignment="Top">(some text)</Button>
</StackPanel>
我尝试将 Style 设置为 {x:Null},内联设置自定义字体大小,并在此控件的资源中设置样式。没有一个优先于我的资源字典中的样式。
正如您所看到的,我在上面的 XAML 示例中展示了我尝试过的所有内容......
我缺少什么?