C# 如何在文本块上添加不模糊的dropshadow

C# 如何在文本块上添加不模糊的dropshadow,c#,.net,wpf,xaml,dropshadow,C#,.net,Wpf,Xaml,Dropshadow,问题说明了一切。我想不出来。我曾尝试添加一个镜像文本元素,但我有一个触发器,当鼠标位于该元素上时,它会更改字体大小,但由于主元素位于顶部,因此不会触发该触发器。如果要删除阴影的是文本本身,则通常的模糊解决方法不起作用 我正在考虑对此进行破解,并添加两个切换可见性的阴影文本块。但是,我不知道如何切换可见性,因为我不能使用TargetName或DataTrigger,因为它基于另一个元素,所以永远不会触发 每个请求(阴影被放大以便可以看到): 我想出来了!我必须使用标签,这样我就可以使用控制模板,这

问题说明了一切。我想不出来。我曾尝试添加一个镜像文本元素,但我有一个触发器,当鼠标位于该元素上时,它会更改字体大小,但由于主元素位于顶部,因此不会触发该触发器。如果要删除阴影的是文本本身,则通常的模糊解决方法不起作用

我正在考虑对此进行破解,并添加两个切换可见性的阴影文本块。但是,我不知道如何切换可见性,因为我不能使用
TargetName
DataTrigger
,因为它基于另一个元素,所以永远不会触发

每个请求(阴影被放大以便可以看到):


我想出来了!我必须使用
标签
,这样我就可以使用
控制模板
,这样我就可以使用
数据触发器
目标名称

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:models="clr-namespace:DesktopDictation.Spelling.Models">
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../FontStyles/TextBlock.DefaultFont.xaml"/>
  </ResourceDictionary.MergedDictionaries>
  <DropShadowEffect x:Key="BlackShadow" ShadowDepth="2" Direction="270" Color="Black" Opacity="75" BlurRadius="2"/>
  <Style x:Key="Spelling.TextGlyph" TargetType="TextBlock" BasedOn="{StaticResource TextBlock.DefaultFontFamilyStyle}">
    <Setter Property="FontWeight" Value="Normal"/>
    <Setter Property="FontSize" Value="12"/>
    <Setter Property="Foreground" Value="#FFFFFF"/>
  </Style>
  <Style x:Key="GlyphList" TargetType="ItemsControl">
    <Setter Property="ItemsPanel">
      <Setter.Value>
        <ItemsPanelTemplate>
          <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/>
        </ItemsPanelTemplate>
      </Setter.Value>
    </Setter>
    <Setter Property="ItemTemplate">
      <Setter.Value>
        <DataTemplate DataType="models:SpellingGlyph">
          <Label x:Name="MainSmall" VerticalAlignment="Bottom">
            <Label.Template>
              <ControlTemplate>
                <Grid>
                  <TextBlock Name="Shadow" Text="{Binding Text}" VerticalAlignment="Bottom" Style="{StaticResource Spelling.TextGlyph}" Effect="{StaticResource BlackShadow}" Margin="0,0,5,0"/>
                  <TextBlock Name="MainText" Text="{Binding Text}" ToolTip="{Binding Pronunciations}" Style="{StaticResource Spelling.TextGlyph}" VerticalAlignment="Bottom" Margin="0,0,5,0"/>
                </Grid>
                <ControlTemplate.Triggers>
                  <DataTrigger Binding="{Binding ElementName=MainText, Path=IsMouseOver}" Value="True">
                    <Setter TargetName="MainText" Property="Foreground" Value="#75BAFF"/>
                    <Setter TargetName="MainText" Property="FontWeight" Value="SemiBold"/>
                    <Setter TargetName="MainText" Property="FontSize" Value="22"/>
                    <Setter TargetName="Shadow" Property="Foreground" Value="#75BAFF"/>
                    <Setter TargetName="Shadow" Property="FontWeight" Value="SemiBold"/>
                    <Setter TargetName="Shadow" Property="FontSize" Value="22"/>
                  </DataTrigger>
                </ControlTemplate.Triggers>
              </ControlTemplate>
            </Label.Template>
          </Label>
        </DataTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>

发布您当前的XAML,以及您当前拥有的内容与预期内容的屏幕截图。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:models="clr-namespace:DesktopDictation.Spelling.Models">
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../FontStyles/TextBlock.DefaultFont.xaml"/>
  </ResourceDictionary.MergedDictionaries>
  <DropShadowEffect x:Key="BlackShadow" ShadowDepth="2" Direction="270" Color="Black" Opacity="75" BlurRadius="2"/>
  <Style x:Key="Spelling.TextGlyph" TargetType="TextBlock" BasedOn="{StaticResource TextBlock.DefaultFontFamilyStyle}">
    <Setter Property="FontWeight" Value="Normal"/>
    <Setter Property="FontSize" Value="12"/>
    <Setter Property="Foreground" Value="#FFFFFF"/>
  </Style>
  <Style x:Key="GlyphList" TargetType="ItemsControl">
    <Setter Property="ItemsPanel">
      <Setter.Value>
        <ItemsPanelTemplate>
          <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/>
        </ItemsPanelTemplate>
      </Setter.Value>
    </Setter>
    <Setter Property="ItemTemplate">
      <Setter.Value>
        <DataTemplate DataType="models:SpellingGlyph">
          <Label x:Name="MainSmall" VerticalAlignment="Bottom">
            <Label.Template>
              <ControlTemplate>
                <Grid>
                  <TextBlock Name="Shadow" Text="{Binding Text}" VerticalAlignment="Bottom" Style="{StaticResource Spelling.TextGlyph}" Effect="{StaticResource BlackShadow}" Margin="0,0,5,0"/>
                  <TextBlock Name="MainText" Text="{Binding Text}" ToolTip="{Binding Pronunciations}" Style="{StaticResource Spelling.TextGlyph}" VerticalAlignment="Bottom" Margin="0,0,5,0"/>
                </Grid>
                <ControlTemplate.Triggers>
                  <DataTrigger Binding="{Binding ElementName=MainText, Path=IsMouseOver}" Value="True">
                    <Setter TargetName="MainText" Property="Foreground" Value="#75BAFF"/>
                    <Setter TargetName="MainText" Property="FontWeight" Value="SemiBold"/>
                    <Setter TargetName="MainText" Property="FontSize" Value="22"/>
                    <Setter TargetName="Shadow" Property="Foreground" Value="#75BAFF"/>
                    <Setter TargetName="Shadow" Property="FontWeight" Value="SemiBold"/>
                    <Setter TargetName="Shadow" Property="FontSize" Value="22"/>
                  </DataTrigger>
                </ControlTemplate.Triggers>
              </ControlTemplate>
            </Label.Template>
          </Label>
        </DataTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>