控制效果模板

发布于 2024-09-12 04:22:11 字数 729 浏览 2 评论 0原文

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

假设我有:

<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}" />

有没有办法做像这样的东西?

I was wondering if there was a way to make a template for an effect so I can apply it to all my controls. That way if i was the effect to be modified, I only have to change it in one location...

Let's say I have:

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

I would like to have (I know it's not correct):

<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}" />

Is there a way to do something like this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你另情深 2024-09-19 04:22:11

只需给 DropShadowEffect 一个键即可

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

Just give a key to DropShadowEffect

<UserControl.Resources>
    <DropShadowEffect x:Key="MyEffect" BlurRadius="10" Color="Black" Opacity="0.5" ShadowDepth="0"/>   
</UserControl.Resources>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文