Hi,I currently have a MouseDoubleClick "event handler" (actually using EventToCommand from Cinch, similar to what MVVM Light offers), but this triggers no matter where I double-click on the tree. I would like to be able to restrict double-clicks to when the user clicks on an actual node.I tried setting a style on XamDataTreeNodeControl, but that doesn't do anything. My tree is defined using NodeLayouts which do not have a MouseDoubleClick event. I was hoping that using PreviewMouseDoubleClick to filter using the sender would work, but the type of sender is XamDataTree even when I double-click on a node (the WPF treeview actually distinguishes between the two, and I was hoping for the same behavior).Any idea? I get the feeling I'm missing something really obvious...Thanks,Michel
Hi Michel,
To achieve the results your describing the best way would be to create a style for the XamDataTreeNodeControl that hooks up to the MouseDoubleClick event handler. I'm providing a very simple sample which demonstrates how you would do this. You can reference this to compare how you setup your style with mine.
If you have any questions about the sample or anything else feel free to ask.
Hi Rob,(I tried to post this earlier, but the proxy at work got overzealous and blocked the "post" page... Go figure).The works well outside the MVVM context, but since I'm trying to avoid code-behind as much as possible and also trying to make most things work the same way across the board, I really wanted to get it to work using EventToCommand. Turns out I got things to work my way this morning. At first (after posting this question), I thought of handling PreviewMouseDoubleClick this way: private void xamDataTree1_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) { DependencyObject _do = (DependencyObject)e.MouseDevice.DirectlyOver; XamDataTreeNodeControl node = Infragistics.Windows.Utilities.GetAncestorFromType(_do, typeof(XamDataTreeNodeControl), false) as XamDataTreeNodeControl; if (node == null) e.Handled = true; } It's code-behind, but it's all UI stuff. This ensures that the MouseDoubleClick event is triggered only when the user clicked on something within a XamDataTreeNodeControl. The MouseDoubleClick "EventToCommand" is then at the tree level. It kills the possibility of double-clicking on anything else. But this morning I found there is no need to do this. I had missed something in the debugging output: When applying the style (with a Blend interaction/Cinch EventToCommand), I forgot that the XamDataTreeNodeControl doesn't deal with the same DataContext as the tree, so it wasn't finding the command to bind to in the viewmodel. I used a bindingproxy to resolve the binding, and now everything works the way I want to. I can't get into the details right now because it's a lot of stuff, but if anyone else is interested in the solution, it's a mix of these things: 1) BindingProxy: http://tomlev2.wordpress.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/ 2) Blend interactions in a style: http://stackoverflow.com/questions/1647815/how-to-add-a-blend-behavior-in-a-style-setter/4779168#4779168 Ultimately my XAML looks like this: <MvvmHelpersIg:XamDataTreeEx.Resources> <!-- This will give the NodeLayouts in the tree access to the tree's DataContext --> <CmsCommon:BindingProxy x:Key="DataContextProxy" Data="{Binding}" /> <MvvmHelpers:Triggers x:Key="MouseDoubleClickTriggers" x:Shared="False"> <i:EventTrigger EventName="MouseDoubleClick"> <CinchV2:EventToCommandTrigger Command="{Binding OpenItemEditorCommand, Source={StaticResource DataContextProxy}}" /> </i:EventTrigger> </MvvmHelpers:Triggers> <Style TargetType="{x:Type ig:XamDataTreeNodeControl}" > <Setter Property="MvvmHelpers:SupplementaryInteraction.Triggers" Value="{StaticResource MouseDoubleClickTriggers}" /> </Style> </MvvmHelpersIg:XamDataTreeEx.Resources> Hopefully half of the above won't be chopped off after I post. XamDataTreeEx is a custom control that derives from XamDataTree and supports a SelectedItem property and also the possibility to select a node on right-click, so that can be replaced by the normal XamDataTree. Now I can move on to the next problem... Thanks, Michel