开发者

Extending Checked event in derived TreeView control - how to temporarily remove event handlers?

开发者 https://www.devze.com 2023-03-23 15:08 出处:网络
There is this Telerik\'s RadTreeView (Silverlight Version) control I\'d like to extend (inherit from).

There is this Telerik's RadTreeView (Silverlight Version) control I'd like to extend (inherit from). Let's call the new control MyTreeView.

The thing I'd like to achieve is that when an item is checked in MyTreeView, it will automatically check all its children items. Also, if after checking the node its parent has all its children checked, I'd like to check the parent too. That would go recursively throughout the tree up to the root. I seem to be unable to find this feature by default.

I don't need a solution for the recursive algorithm that would check the items, I can manage that easily myself. What I see as a problem is the fact that a user can subscribe on the Checked and Unchecked events. So if a user has subscribed to a Checked event, whenever an item is checked all its children will be checked, thus raising an event for each children node that was automatically checked as a consequence of checking its parent. In my scenario, this is not a desirable behaviour. I want the event to fire only for the manually checked item, not for any other node that will be automatically checked as a consequence.

I thought I could override the OnChecked method but it is either private or there is no such a method, so I have no access to it. I could add another event handler to the Checked event in a constructor, that would be called before any other event handlers subscribed to an event, but that does not prevent the children nodes from raising the event. I would like to be able to unsubscribe the handlers on the Checked temporarily, then resubscribe them again after checking the nodes. However, since I don't know who is s开发者_运维知识库ubscribed to an event, I can't unsubscribe them manually (the event is public) and I don't seem to be able to get the invocation list.

Is there a way to iterate through the subscribed events or any other ways to turn them off temporarily? Is there any better approach to the problem described?


There is a RadTreeViewCheckEventArgs.IsUserInitiated property that you can use.

0

精彩评论

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

关注公众号