【发布时间】:2021-01-02 00:16:40
【问题描述】:
我有两个具有相同前景的 TextBlock,但显示方式不同。 TextBlocks 之间的差异是 FontSize。放大/缩小时,颜色也会发生变化。
通过设置<Setter Property="TextOptions.TextFormattingMode" Value="Display" /> 它可以工作,但是 ViewBox 中显示的文本会变得模糊。 TextFormattingMode "Display" 不能在 ViewBox 中使用,请参阅here。
为什么会这样?为什么默认颜色不同?有什么解决办法吗?
<Window x:Class="ColoringWithOpacity.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:ColoringWithOpacity"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"
Background="Black">
<Window.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontFamily" Value="Segoe UI"/>
<Setter Property="FontWeight" Value="Semibold"/>
</Style>
<Style TargetType="{x:Type Run}">
<Setter Property="FontFamily" Value="Segoe UI"/>
<Setter Property="FontWeight" Value="Semibold"/>
</Style>
<SolidColorBrush x:Key="W25" Opacity="0.25" Color="#FFFFFF"/>
</Window.Resources>
<UniformGrid Columns="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Viewbox Grid.RowSpan="2">
<TextBlock Foreground="{StaticResource W25}" Text="13.55" >
<!--<Run Text="13.55"/>--> <!--Works the same-->
</TextBlock>
</Viewbox>
<Viewbox Grid.Row="2" Grid.Column="2">
<TextBlock Foreground="{StaticResource W25}" Text="mm" >
<!--<Run Text="mm"/>--> <!--Works the same-->
</TextBlock>
</Viewbox>
</Grid>
<Viewbox>
<TextBlock Foreground="{StaticResource W25}">
<Run Text="13.55" FontSize="64"/>
<Run Text="mm" FontSize="40"/>
</TextBlock>
</Viewbox>
【问题讨论】:
-
出于好奇,设置
Foreground="#3FFFFFFF"时它的行为是否相同? -
@Clemens 是的,它的行为是一样的。
标签: wpf wpf-controls opacity textblock text-coloring