【发布时间】:2019-05-19 21:31:24
【问题描述】:
我知道How to target all controls (WPF Styles) 的答案 但不能让它工作。
我一定是犯了一些非常简单的错误,但不知道是什么。
我想将 TextOptions.TextFormattingMode 设置为显示表单上的所有控件。但是它没有被应用(下面的 xaml 的所有控件上的文本都是模糊的)。如果我将 TextOptions.TextFormattingMode 添加到所有控件,那就没问题了)
<Window x:Class="WPFFrst.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFFrst"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<Style TargetType="{x:Type Control}">
<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
</Style>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="463*"/>
<ColumnDefinition Width="57*"/>
<ColumnDefinition Width="272*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="textBlock"
HorizontalAlignment="Left"
Margin="197,133,0,0"
TextWrapping="Wrap"
Text="Select a message option and then choose the Display button."
VerticalAlignment="Top"
SnapsToDevicePixels="True"
FontSize="12"
Grid.ColumnSpan="3"/>
<RadioButton
x:Name="HelloButton"
Content="Hello"
IsChecked="True"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="217,196,0,0"/>
<RadioButton
x:Name="GoodByeButton"
Content="Good Bye"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Grid.ColumnSpan="2"
Margin="409,194,0,0"/>
<Button
x:Name="button"
Content="Display"
HorizontalAlignment="Left"
Margin="288,255,0,0"
VerticalAlignment="Top"
Width="75"/>
</Grid>
</Window>
【问题讨论】:
-
不就是
-
请注意,默认样式仅适用于类型与样式的 TargetType 完全匹配的元素。这里是
Control的实例,但不是派生类型的实例。
标签: wpf