WPFのコンテンツではなく、ボーダーにエフェクトを適用するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/807420

  •  03-07-2019
  •  | 
  •  

質問

サードパーティのデータグリッドとその周囲の境界線を持つWPFアプリケーションがあります。私は DropShadowEffect を使用して境界線の後ろに影を付けましたが、これはパフォーマンスに多少影響するようです( BitmapEffect ほどではありませんが、まだ顕著です)ファジーなフォントレンダリング。どういうわけか境界線に効果を適用する方法はありますが、その内容はありませんか?

コンテンツへの効果を {x:Null} に設定しようとしましたが、それは役に立ちませんでした。

これが私が思いついたサンプルアプリです。境界線の後ろに影を付けますが、テキストの各行の後ろにも影を付けます。境界線の後ろに影が欲しいのですが、テキストにはなりません。

<Window x:Class="WpfEffectTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Border BorderBrush="Black" BorderThickness="10" CornerRadius="5" Margin="25">
            <Border.Effect>
                <DropShadowEffect BlurRadius="10" ShadowDepth="5" />
            </Border.Effect>
            <StackPanel>
                <TextBlock>This is some text</TextBlock>
                <TextBlock>This is some text</TextBlock>
                <TextBlock>This is some text</TextBlock>
                <TextBlock>This is some text</TextBlock>
                <TextBlock>This is some text</TextBlock>
                <TextBlock>This is some text</TextBlock>
            </StackPanel>
        </Border>

    </Grid>
</Window>
役に立ちましたか?

解決

gcoresからのリンクには、境界線とそのコンテンツを同じグリッドにまとめて、コンテンツが境界線をオーバーレイするという答えがありました。

<Window x:Class="WpfEffectTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Border BorderBrush="Black" BorderThickness="10" CornerRadius="5" Margin="25">
            <Border.Effect>
                <DropShadowEffect BlurRadius="10" ShadowDepth="5" />
            </Border.Effect>
        </Border>
        <StackPanel Margin="35">
            <TextBlock>This is some text</TextBlock>
            <TextBlock>This is some text</TextBlock>
            <TextBlock>This is some text</TextBlock>
            <TextBlock>This is some text</TextBlock>
            <TextBlock>This is some text</TextBlock>
            <TextBlock>This is some text</TextBlock>
        </StackPanel>
    </Grid>
</Window>

他のヒント

簡単な(ハッキング?)ソリューションの1つは、

<StackPanel Background="White">

これにより、ドロップシャドウの問題のあるテキストが解決されます(ただし、パフォーマンスの問題についてはわかりません)。 問題は、WPFが効果をセット要素とビジュアルツリー内のすべての子に適用することです。 このリンクはそれをよりよく説明しています: DropShadowEffectのパフォーマンスの問題

すべてのTextBlockに対して次のブロック(または同様のブロック)を試してください。

<TextBlock>
    <TextBlock.Effect>
        <DropShadowEffect BlurRadius="30" ShadowDepth="5" Color="White"/>
    </TextBlock.Effect>
</TextBlock>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top