Tro*_*unt 14 silverlight xaml coding-style
我正在努力使用一些XAML语法,希望有人可以提供建议.我想创建一个"效果"类型样式资源,其中包含一个DropShadowEffect定义,该定义可以重复使用,而不是总是手动设置属性.这就是我所拥有的:
<Style TargetType="DropShadowEffect" x:Name="DropShadowEffectStyle">
<Setter Property="BlurRadius" Value="5" />
<Setter Property="Direction" Value="315" />
<Setter Property="ShadowDepth" Value="2" />
<Setter Property="Opacity" Value="0.5" />
</Style>
<Style TargetType="TextBlock" x:Name="PageTabLabelStyle">
<Setter Property="FontSize" Value="16" />
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="Foreground" Value="#EFEFEF" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="0, 10, 0, 10" />
<Setter Property="Effect" Value="{StaticResource DropShadowEffectStyle}" />
</Style>
Run Code Online (Sandbox Code Playgroud)
每次运行都会失败,所以我显然错过了一些东西.我认为这是围绕文本块样式的"效果"属性,期望"效果"类型而不是"DopShadowEffect"类型.有任何想法吗?
Kei*_*ney 28
您无法"设置"效果,因为Style是Control的属性,而Effect不是Control.
你真正想要做的是将效果本身放入资源字典中,并使用StaticResource引用指向它.就像是:
<UserControl.Resources>
<DropShadowEffect x:Key="dropShadow" BlurRadius="25" Direction="315" />
<Style TargetType="TextBlock" x:Name="PageTabLabelStyle">
<Setter Property="FontSize" Value="16" />
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="Foreground" Value="#EFEFEF" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="0, 10, 0, 10" />
<Setter Property="Effect" Value="{StaticResource dropShadow}" />
</Style>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10623 次 |
最近记录: |