<TextBlock Text="Shadow Text" Margin="309,473,96,142" Foreground="Teal"> <TextBlock.Effect> <DropShadowEffect ShadowDepth="4" Direction="330" Color="Black" Opacity="0.5" BlurRadius="4"/> </TextBlock.Effect> </TextBlock>
我只会把 textblock中 foreground这种属性加入到资源字典,例如
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style TargetType="TextBlock" x:Key="TitleText"> <Setter Property="Background" Value="Yellow"/> <Setter Property="FontSize" Value="24"/> <Setter Property="FontFamily" Value="微软雅黑"/> <Setter Property="Foreground" Value="Blue"/> </Style> </ResourceDictionary>
要是把 textblock.effect加入到资源字典我就不会了。。。求帮助
由于style的target不能直接嵌套,所以分开写就行了
<Window x:Class="WpfApplication32.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"> <Window.Resources> <ResourceDictionary> <Style x:Key="shadow" TargetType="TextBlock"> <Setter Property="Effect" > <Setter.Value> <DropShadowEffect ShadowDepth="4" Direction="330" Color="Black" Opacity="0.5" BlurRadius="4"/> </Setter.Value> </Setter> <Setter Property="FontSize" Value="24"/> <Setter Property="FontFamily" Value="微软雅黑"/> <Setter Property="Foreground" Value="Blue"/> </Style> </ResourceDictionary> </Window.Resources> <Grid> <TextBlock Text="Shadow Text" Foreground="Teal" Style="{StaticResource shadow}" > </TextBlock> </Grid> </Window>
大哥,我问的问题都是你解决的,真牛
@混沌奇迹: - -!才发现是你