开发者

How to add multiple handlers to an attached event in XAML?

Code Sample:

<DataTemplate x:Key="NodeDataTemplate">
    <Border Style="{StaticResource nodeBorderStyle}"
                        MouseEnter="SetMouseCursor_Arrow"
                        MouseLeave="SetMouseCursor_ScrollAll"
                        MouseLeftButtonDown="ViewLink"
                        MouseLeftButtonDown="SetFlagForCursorTracking">
....
</DataTemplate>

I want to add 2 handlers to a particular event like shown above. However this won't compile - 'attribute can be set more than once'. I have multiple methods because they do differ开发者_如何学Pythonent things (are named appropriately). e.g. the first handler has nothing in common with the second.

My other option was to kludge a SetFlagForCursorTrackingAndCheckForViewLink method - which is "Yech!". Any ideas ?


Please try to just add one handler which will subsequently call some event handling method. Or add just one handler which will subsequently call your desired two event handling methods - this will be more elegant.


You can do that in code behind,

UIObject.AddHandler( AttachedEventContainer.AttachedEvent, your_handler);

UIObject.AddHandler( AttachedEventContainer.AttachedEvent, your_handler);

I have not tried or tested this, if this gives any error then you have no choice but use a method and call two event handlers manually in that method and attached method as event handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜