控制效果的模板

时间:2010-07-29 14:56:16

标签: c# silverlight xaml effect

我想知道是否有办法为效果制作模板,所以我可以将它应用到我的所有控件中。这样,如果我是要修改的效果,我只需要在一个位置更改它......

让我说我有:

<Button Content="Foo" Height="50" Width="50" >
   <Button.Effect>
      <DropShadowEffect BlurRadius="10" Color="Black" Opacity="0.5" ShadowDepth="0"/>
   </Button.Effect>
</Button>

我想(我知道这不正确):

<UserControl.Resources>
   <Effect x:Key="MyEffect">
      <DropShadowEffect BlurRadius="10" Color="Black" Opacity="0.5" ShadowDepth="0"/>
   </Effect>
</UserControl.Resources>

...

<Button Content="Foo" Height="50" Width="50" Effect="{StaticResource MyEffect}" />

有没有办法做这样的事情?

1 个答案:

答案 0 :(得分:1)

只需给DropShadowEffect键一个

<UserControl.Resources>
    <DropShadowEffect x:Key="MyEffect" BlurRadius="10" Color="Black" Opacity="0.5" ShadowDepth="0"/>   
</UserControl.Resources>
相关问题