Aggiornamento: trovato un modo migliore, è possibile saltare la parte Border
se si applica il Effect
direttamente allo ScrollViewer
che incapsula il testo nel modello.
<TextBox Text="Shadow Text">
<TextBox.Resources>
<Style TargetType="ScrollViewer">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="4"
Direction="330"
Color="Black"
Opacity="0.5"
BlurRadius="4"/>
</Setter.Value>
</Setter>
</Style>
</TextBox.Resources>
</TextBox>
Aggiornamento 2: perso la parte della creazione del TextBox
nel codice. Ecco il C# equivalente al Xaml sopra
Setter effectSetter = new Setter();
effectSetter.Property = ScrollViewer.EffectProperty;
effectSetter.Value = new DropShadowEffect
{
ShadowDepth = 4,
Direction = 330,
Color = Colors.Black,
Opacity = 0.5,
BlurRadius = 4
};
Style dropShadowScrollViewerStyle = new Style(typeof(ScrollViewer));
dropShadowScrollViewerStyle.Setters.Add(effectSetter);
TextBox dropShadowTextBox = new TextBox();
dropShadowTextBox.Text = "Shadow Text";
dropShadowTextBox.Foreground = Brushes.Teal;
dropShadowTextBox.FontSize = 40;
dropShadowTextBox.Margin = new Thickness(10);
dropShadowTextBox.Resources.Add(typeof(ScrollViewer), dropShadowScrollViewerStyle);
Buona domanda, una sola idea è quella di rendere lo sfondo e BorderBrush trasparente per la TextBox
e posizionarlo in un Border
<Border BorderThickness="1"
BorderBrush="#FF7F9DB9"
SnapsToDevicePixels="True"
UseLayoutRounding="True"
Margin="10">
<TextBox Text="Shadow Text"
Foreground="Teal"
FontSize="40"
Background="Transparent"
BorderBrush="Transparent">
<TextBox.Effect>
<DropShadowEffect ShadowDepth="4"
Direction="330"
Color="Black"
Opacity="0.5"
BlurRadius="4"/>
</TextBox.Effect>
</TextBox>
</Border>
Ecco un confronto con un "normale" TextBox

fonte
2011-08-31 12:54:10
è xaml piuttosto che codice ma ci riuscirò, grazie per la risposta eccellente e anche per lo screenshot aggiunto – mtijn
Aggiunto un approccio migliore, rimuovendo l'uso del 'Border'. Imposta l'effetto su 'ScrollViewer' nel modello –
+1 per trovare una soluzione limitata all'ambito della casella di testo, eccellente! – mtijn