RadTreeViewItem - event MouseLeftButtonDown or Up never fires
2011-03-18 15:25
357 查看
这是借用TeleriK官网论坛上的帖子名字。由于自己也碰到了这个问题,当时也是看了官方的回复才解决的。废话不多说直接说应用场景和解决方案。
应用场景:需要在RadTreeView实现点击节点响应事件,并且当前节点处于Selected状态下点击仍然能触发响应事件。
(原文:I bound the RadTreeViewItem.MouseLeftButtonDown to an event handler in code, but in debug I noticed the event never fires. I didn't use the RadTreeViewItem.Selected event because when a the item is selected, when use click the item again the Selected event don't fire - this is not I want, so I have to handle the MouseLeftButtonDown or Up events but... the two events never fire. Help!)
解决方案:通常情况下会使用RadTreeView的SelectionChanged事件,但该时间只有在改变当前选中节点的时候才能触发,并且设置节点的IsSelected=true时也会被触发(这个点在做节点定位的时候非常不方便,定位到节点后设置节点的IsSelected=true时会触发SelectionChanged),所以SelectionChanged事件在这个场景里不适用。
在项目中习惯性的使用MouseLeftButtonDown事件发现竟然不触发,这点很无语呀。
看了Telerik官方的回复发现官方使用MouseLeftButtonUp事件来处理这个场景。Telerik没解释为什么用Up事件而不是Down事件,有可能Telerik在实现控件的时候没有去获取当前节点,只是在Up事件的时候才去获取。
代码:
private void TreeViewRoot_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ObjTreeNodeClass oNodeEnt = TreeViewRoot.SelectedItem as ObjTreeNodeClass;
if (null == oNodeEnt)
{
return;
}
//处理逻辑
}
对这个处理方式真是很无语,没办法是用别人的控件就得遵守别人的规则,不管别人的规则有时是多么的别扭。
应用场景:需要在RadTreeView实现点击节点响应事件,并且当前节点处于Selected状态下点击仍然能触发响应事件。
(原文:I bound the RadTreeViewItem.MouseLeftButtonDown to an event handler in code, but in debug I noticed the event never fires. I didn't use the RadTreeViewItem.Selected event because when a the item is selected, when use click the item again the Selected event don't fire - this is not I want, so I have to handle the MouseLeftButtonDown or Up events but... the two events never fire. Help!)
解决方案:通常情况下会使用RadTreeView的SelectionChanged事件,但该时间只有在改变当前选中节点的时候才能触发,并且设置节点的IsSelected=true时也会被触发(这个点在做节点定位的时候非常不方便,定位到节点后设置节点的IsSelected=true时会触发SelectionChanged),所以SelectionChanged事件在这个场景里不适用。
在项目中习惯性的使用MouseLeftButtonDown事件发现竟然不触发,这点很无语呀。
看了Telerik官方的回复发现官方使用MouseLeftButtonUp事件来处理这个场景。Telerik没解释为什么用Up事件而不是Down事件,有可能Telerik在实现控件的时候没有去获取当前节点,只是在Up事件的时候才去获取。
代码:
private void TreeViewRoot_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ObjTreeNodeClass oNodeEnt = TreeViewRoot.SelectedItem as ObjTreeNodeClass;
if (null == oNodeEnt)
{
return;
}
//处理逻辑
}
对这个处理方式真是很无语,没办法是用别人的控件就得遵守别人的规则,不管别人的规则有时是多么的别扭。
相关文章推荐
- wpf button的mouse(leftbutton)down/up,click事件不响应解决办法
- SilverLight学习笔记--如何解决Button不响应MouseLeftButtonDown与MouseLeftButtonUp事件的问题
- Button中 MouseLeftButtonDown和MouseLeftButtonUp 事件无法触发的解决方案 (转)
- How to handle the MouseLeftButtonDown and MouseLeftButtonUp events of the Button control?
- WPF 窗体拖转时不触发MouseLeftButtonUpEvent
- MouseLeftButtonDown event not working for Textbox in Silverlight
- Button中MouseLeftButtonDown和MouseLeftButtonUp事件无法触发的解决方案
- C#中 MouseLeftButtonDown MouseLeftButtonUp MouseMove 使用
- C# RaiseEvent MouseLeftButtonDownEvent
- wpf button的mouse(leftbutton)down/up,click事件不响应解决办法
- 如何解决Button不响应MouseLeftButtonDown与MouseLeftButtonUp事件的问题
- wpf button的mouse(leftbutton)down/up,click事件不响应解决办法
- silverlight MouseLeftButtonDown无法触发解决办法
- Button中MouseLeftButtonDown和MouseLeftButtonUp事件无法触发的解决方案
- Unity3D 中鼠标按下时OnMouseDown()、Input.GetMouseButtonDown()和EventType.MouseDown的响应验证
- 错误:“ResourceDictionary”根元素需要 x:Class 特性来支持 XAML 文件中的事件处理程序。请移除 MouseLeftButtonDown 事件的事件处理程序.
- silverlight MouseLeftButtonDown事件总是无法触发
- wpf:关于MouseLeftButtonDown事件失效的问题
- MouseLeftButtonDown事件无法触发
- MouseLeftButtonDown 事件不触发