문제

주위에 테두리가있는 타사 데이터 그리드가있는 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>

다른 팁

간단한 (해킹?) 솔루션 중 하나는해야합니다.

<StackPanel Background="White">

이렇게하면 Drop-Shadow 문제가있는 텍스트를 해결해야합니다 (성능 문제는 확실하지 않음). 문제는 WPF가 세트 요소에 효과를 적용하고 시각적 트리의 모든 어린이에 효과를 적용한다는 것입니다. 이 링크는 더 잘 설명합니다.DropshadowEffect 성능 문제

모든 텍스트 블록에 대해 다음 블록 (또는 이와 유사한)을 시도하십시오.

<TextBlock>
    <TextBlock.Effect>
        <DropShadowEffect BlurRadius="30" ShadowDepth="5" Color="White"/>
    </TextBlock.Effect>
</TextBlock>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top