2009-04-30 10 views
9

Tengo una aplicación WPF que tiene una cuadrícula de datos de un tercero con un borde alrededor. He usado el DropShadowEffect para poner una sombra detrás del borde, pero esto parece afectar algo el rendimiento (no tanto como un BitmapEffect, pero aún se nota) y hace que la fuente sea borrosa. ¿Hay alguna manera de aplicar de alguna manera el efecto al borde, pero no a su contenido?¿Cómo aplico un efecto a un borde pero no a su contenido en WPF?

Intenté configurar el efecto en el contenido a {x:Null}, pero eso no ayudó.

Aquí hay una aplicación de muestra que se me ocurrió. Coloca una sombra detrás del borde, pero también pone una sombra detrás de cada línea de texto. Quiero la sombra detrás del borde, pero no el texto.

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

Respuesta

12

El enlace desde gcores tenía la respuesta, que es poner la frontera y su contenido juntos en la misma red que el contenido se superpone a la frontera.

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

Una sencilla (piratear?) Solución es hacer

<StackPanel Background="White"> 

Esto debería resolver el problema de texto con las sombras paralelas (no estoy seguro sobre el problema de rendimiento sin embargo). El problema es que WPF aplica efectos al elemento set y a todos sus elementos secundarios en el árbol visual. Este enlace lo explica mejor: DropShadowEffect performance issue

-1

intente lo siguiente bloque (o similar) para todos los TextBlocks:

<TextBlock> 
    <TextBlock.Effect> 
     <DropShadowEffect BlurRadius="30" ShadowDepth="5" Color="White"/> 
    </TextBlock.Effect> 
</TextBlock> 
Cuestiones relacionadas