是否可以使用样式或模板来应用Blend行为? [英] Is it possible to apply Blend behavior using style or template?

查看:45
本文介绍了是否可以使用样式或模板来应用Blend行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的Blend行为,动作和触发器的小集合感到非常满意-它们易于使用且功能强大.但是我仍然想不出如何避免在每个元素上应用它们的方法.例如,如果我有这样的行为:

I'm very happy with my small collection of Blend behaviors, actions and triggers - they are easy to use and powerful. But I still can't figure out how to avoid applying them on per element basis. For example, if I have a behavior as such:

<Rectangle>
    <i:Interaction.Behaviors>
        <il:MouseDragElementBehavior/>
    </i:Interaction.Behaviors>
</Rectangle>

,我的窗口中有几个可拖动的矩形,每个矩形都必须具有上述标记才能拖动.我想做的是能够写这样的东西:

and I have a few draggable rectangles in my Window, each of them has to have the above markup to be draggable. What I would like to do is to be able to write something like this:

<Style x:Key="RectangleStyle" TargetType="{x:Type Rectangle}">
    <Setter Property="i:Interaction.Behaviors" 
        Value="il:MouseDragElementBehavior"/>
</Style>

它可以是样式,模板或其他避免行为或动作标记重复的方式.到目前为止,我想到的最好的解决方案是为容器创建一个特殊的行为(当附加容器时,它将枚举附加到子事件的子对象). 有什么想法吗?

It could be style, template, or some other way to avoid behavior or action markup repetition. The best solution I came up so far is creating a special behavior for the container (when attached, it enumerates children attaching to the children events). Any ideas?

推荐答案

我遇到了同样的问题,并且

I ran into the same problem and I posted on my blog on how to create an attached property to work around this shortcoming of the Blend SDK.

这篇关于是否可以使用样式或模板来应用Blend行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆