2014-03-06 56 views
1

我已经试过寻找这个问题的解决方案,但还没有找到任何东西。WPF发光效果没有BitmapEffects

我有一个自定义C++/CLI挂钩的WPF窗口来扩展框架(DWMAPI)并将客户区扩展到框架(Win32/NCCALCSIZE)。我用WPF添加了一个自定义图标和标题。为窗口的标记如下(记住,客户区被调整到玻璃框的边缘):

<Window x:Class="ClrDwmHelper.WpfHost.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:ns="clr-namespace:ClrDwmHelper.WpfHost" 
     Title="My Window Title" Height="350" Width="300" 
     Background="{x:Null}" 
     SourceInitialized="Window_SourceInitialized" 
     Loaded="Window_Loaded"> 
    <Window.Icon> 
    <DrawingImage> 
     <DrawingImage.Drawing> 
     <GeometryDrawing Brush="White"> 
      <GeometryDrawing.Geometry> 
      <RectangleGeometry Rect="0,0 16,16"/> 
      </GeometryDrawing.Geometry> 
     </GeometryDrawing> 
     </DrawingImage.Drawing> 
    </DrawingImage> 
    </Window.Icon> 
    <Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="6"/> 
     <RowDefinition Height="22"/> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="6"/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="6"/> 
     <ColumnDefinition Width="1*"/> 
     <ColumnDefinition Width="6"/> 
    </Grid.ColumnDefinitions> 
    <Grid Grid.RowSpan="2" Grid.ColumnSpan="3"> 
     <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="Auto"/> 
     <ColumnDefinition Width="1*"/> 
     </Grid.ColumnDefinitions> 
     <Image Name="SysMenu" Height="16" Width="16" Margin="6,7,6,5" Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Icon}"/> 
     <Grid Grid.Column="1" Margin="1,6,5,5"> 
     <TextBlock Name="Caption" IsHitTestVisible="False" Foreground="Black" Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Title}" 
        FontFamily="{x:Static SystemFonts.CaptionFontFamily}" 
        FontSize="{x:Static SystemFonts.CaptionFontSize}" 
        FontStretch="Normal" 
        FontStyle="{x:Static SystemFonts.CaptionFontStyle}" 
        TextDecorations="{x:Static SystemFonts.CaptionFontTextDecorations}" 
        FontWeight="{x:Static SystemFonts.CaptionFontWeight}" 
        TextTrimming="WordEllipsis"> 
      <TextBlock.Effect> 
      <DropShadowEffect ShadowDepth="0" Color="#FFFFFF" BlurRadius="15"/> 
      </TextBlock.Effect> 
     </TextBlock> 
     </Grid> 
    </Grid> 

    <Border Grid.Row="2" Grid.Column="1" BorderBrush="#7FFFFFFF" BorderThickness="1" CornerRadius="1" IsHitTestVisible="False"> 
     <Border Background="White" BorderBrush="#9F000000" BorderThickness="1" CornerRadius="1" IsHitTestVisible="False"> 

     </Border> 
    </Border> 
    </Grid> 
</Window> 

窗口看起来是这样的:

Image of the window

我想要文字周围更加不透明的光晕(NOT文本块)比目前有的(半径为15的DropShadowEffect几乎不可见,但半径为15的WINAPI发光更加不透明)。什么是最好的方法来做到这一点? (自定义效果 包含 首选)

回答

0

作为临时解决方案,我在TextBlock下放置了一个模糊的白色半透明Rectangle。工程确定,虽然这是不是我想要的 - 我想模糊的文字,而不必添加一个矩形。

0

据我了解你的要求,我想你应该使用BlurEffect类来实现你的目标。

enter image description here

我创建了一个简单的XAML文件,你可以找到在这个帖子中,我与DropShadowEffect(第一列)和BlurEffect(第二列)的各种参数扮演的结束。

在BlurEffect的情况下,关键是要包括但这种效果的另一个TextBlock的,所以文本保持可读:

<Grid> 
    <!-- Blurred text --> 
    <TextBlock Foreground="#FFCCCCCC" Text="My Window Title"> 
    <TextBlock.Effect> 
     <BlurEffect KernelType="Box" Radius="3.5"/> 
    </TextBlock.Effect> 
    </TextBlock> 
    <!-- Crisp text --> 
    <TextBlock Text="My Window Title"/> 
</Grid> 

以下是完整的标记:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="Tan"> 
    <Grid Margin="20"> 
     <StackPanel Orientation="Horizontal"> 
      <StackPanel Width="200"> 
       <TextBlock Text="My Window Title"/> 
       <TextBlock Text="My Window Title"> 
        <TextBlock.Effect> 
         <DropShadowEffect 
          BlurRadius="5" 
          Color="#FFFFFF" 
          Direction="0" 
          ShadowDepth="0"/> 
        </TextBlock.Effect> 
       </TextBlock> 
       <TextBlock Text="My Window Title"> 
        <TextBlock.Effect> 
         <DropShadowEffect 
          BlurRadius="5" 
          Color="#EEEEEE" 
          Direction="0" 
          ShadowDepth="0"/> 
        </TextBlock.Effect> 
       </TextBlock> 
       <TextBlock Text="My Window Title"> 
        <TextBlock.Effect> 
         <DropShadowEffect 
          BlurRadius="2" 
          Color="#777777" 
          Direction="0" 
          ShadowDepth="0"/> 
        </TextBlock.Effect> 
       </TextBlock> 
       <TextBlock Text="My Window Title"> 
        <TextBlock.Effect> 
         <DropShadowEffect 
          BlurRadius="3" 
          Color="#AAAAAA" 
          Direction="0" 
          ShadowDepth="0"/> 
        </TextBlock.Effect> 
       </TextBlock> 
      </StackPanel> 
      <StackPanel> 
       <TextBlock Text="My Window Title"/> 
       <Grid> 
        <TextBlock Foreground="#FFFFFFFF" Text="My Window Title"> 
         <TextBlock.Effect> 
          <BlurEffect KernelType="Box" Radius="2.0"/> 
         </TextBlock.Effect> 
        </TextBlock> 
        <TextBlock Text="My Window Title"/> 
       </Grid> 
       <Grid> 
        <TextBlock Foreground="#99FFFFFF" Text="My Window Title"> 
         <TextBlock.Effect> 
          <BlurEffect KernelType="Box" Radius="3.0"/> 
         </TextBlock.Effect> 
        </TextBlock> 
        <TextBlock Text="My Window Title"/> 
       </Grid> 
       <Grid> 
        <TextBlock Foreground="#BB999999" Text="My Window Title"> 
         <TextBlock.Effect> 
          <BlurEffect KernelType="Box" Radius="5.0"/> 
         </TextBlock.Effect> 
        </TextBlock> 
        <TextBlock Text="My Window Title"/> 
       </Grid> 
       <Grid> 
        <TextBlock Foreground="#FFCCCCCC" Text="My Window Title"> 
         <TextBlock.Effect> 
          <BlurEffect KernelType="Box" Radius="3.5"/> 
         </TextBlock.Effect> 
        </TextBlock> 
        <TextBlock Text="My Window Title"/> 
       </Grid> 
      </StackPanel> 
     </StackPanel> 
    </Grid> 
</Page>