Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 两个具有相同颜色(不透明度)和不同字体大小的文本块显示不同_Wpf_Wpf Controls_Opacity_Textblock_Text Coloring - Fatal编程技术网

Wpf 两个具有相同颜色(不透明度)和不同字体大小的文本块显示不同

Wpf 两个具有相同颜色(不透明度)和不同字体大小的文本块显示不同,wpf,wpf-controls,opacity,textblock,text-coloring,Wpf,Wpf Controls,Opacity,Textblock,Text Coloring,我有两个前景相同的文本块,但显示方式不同。文本块之间的差异是字体大小。放大/缩小时,颜色也会发生变化 通过设置,它可以工作,但随后视图框中显示的文本会变得模糊。TextFormattingMode“Display”不能在ViewBox中使用,请参阅 为什么是这样?为什么默认情况下颜色不同?有什么解决办法吗 <Window x:Class="ColoringWithOpacity.MainWindow" xmlns="http://schemas

我有两个前景相同的文本块,但显示方式不同。文本块之间的差异是字体大小。放大/缩小时,颜色也会发生变化

通过设置
,它可以工作,但随后视图框中显示的文本会变得模糊。TextFormattingMode“Display”不能在ViewBox中使用,请参阅

为什么是这样?为什么默认情况下颜色不同?有什么解决办法吗

<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>

我在使用WPF应用程序时也遇到过同样的问题。我不明白为什么
solidcolorbush
上的
Opacity
不起作用,但解决方案是将UI元素上的不透明度移动到
solidcolorbush

<Window x:Class="WpfApp1.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:WpfApp1"
        mc:Ignorable="d"  Background="Black"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="FontFamily" Value="Segoe UI"/>
            <Setter Property="FontWeight" Value="Semibold"/>
            <Setter Property="Opacity" Value="0.25"/>
        </Style>

        <Style TargetType="{x:Type Run}">
            <Setter Property="FontFamily" Value="Segoe UI"/>
            <Setter Property="FontWeight" Value="Semibold"/>
        </Style>

        <SolidColorBrush x:Key="W25" 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>
    </UniformGrid>
</Window>


出于好奇,当您设置
前台=“#3FFFFFFF”
时,它的行为是否相同?@Clemens是的,它的行为相同。我们使用画笔的原因之一是出于性能考虑:。我们有多个不同不透明的项目,需要混合。使用元素不透明度将非常耗时,并且可能会影响性能;(.我使用if来呈现图表标签,没有任何性能问题,但您的情况可能不同。