gpt4 book ai didi

wpf - 是否有与 AddHandler 等效的 XAML,您想在其中捕获已处理的事件?

转载 作者:行者123 更新时间:2023-12-01 06:22:39 25 4
gpt4 key购买 nike

根据 UIElement.AddHandler on MSDN ,您可以为 handledEventsToo 传入一个 bool 值参数,因此您仍然可以收到已处理事件的通知。是否有与此等效的 XAML?

另一种方法是通过 EventSetter class which also specifies that property ,但它明确表示不应在 XAML 中使用它,尽管他们没有说明原因,而且我想不出一个很好的理由。

我唯一能想到的是它在初始化 XAML 时会造成严重破坏,如果您在代码中执行它(很可能)不会是这种情况,因为您很可能在 InitializeComponent 之后这样做。然而,这完全是猜测。

我实际上正在考虑将我自己的 EventSetter 类版本子类化,以添加该属性,尽管我还没有考虑太多,甚至不知道这是否可能,尽管我不明白为什么它不会.

最佳答案

我正在寻找同样的东西,但不幸的是,根据最新的 MSDN documentation :

Setting the InvokeHandledEventsToo characteristics of how an event's handlers will be invoked must always be performed in code, in keeping with the general principle that there is no way to specify InvokeHandledEventsToo when assigning defined event handlers for instances directly to named events in XAML attribute syntax. Although setting this value in XAML does not generate any compile-time errors, the resulting XAML will produce a run-time exception when the style is used.



我认为 handledEventsToo的目的是在代码隐藏不是问题的情况下为自定义控件提供更大的灵活性,而不是使用“正常”MVVM 模式进行编码。

关于wpf - 是否有与 AddHandler 等效的 XAML,您想在其中捕获已处理的事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31881023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com