This is a migrated thread and some comments may be shown as answers.

MouseDoubleClick on Item

5 Answers 197 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
GuillaumeR
Top achievements
Rank 1
GuillaumeR asked on 30 Jun 2010, 10:46 AM
Hello,

I have problem using the event "MouseDoubleClick" on RadTreeViewItem.
It is handled for each branch item and it don't care about e.Handled = true.

Example :

        <telerik:RadTreeView IsDragDropEnabled="True" MouseDoubleClick="treeView_MouseDoubleClick">  
            <telerik:RadTreeView.ItemContainerStyle> 
                <Style TargetType="{x:Type telerik:RadTreeViewItem}">  
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>  
                    <Setter Property="IsExpanded" Value="True"/>  
                    <EventSetter Event="MouseDoubleClick" Handler="treeViewItem_MouseDoubleClick"/>  
                </Style> 
            </telerik:RadTreeView.ItemContainerStyle> 
            <telerik:RadTreeView.ItemTemplate> 
                <HierarchicalDataTemplate ItemsSource="{Binding Children}">  
                    <Border BorderThickness="1" BorderBrush="LightGray" Margin="2" CornerRadius="5">  
                        <Grid> 
                            <Grid.ColumnDefinitions> 
                                <ColumnDefinition Width="Auto"/>  
                                <ColumnDefinition Width="*"/>  
                            </Grid.ColumnDefinitions> 
                            <TextBlock Grid.Column="0" Text="{Binding Key}" Margin="3,0,10,0"/>  
                            <GridSplitter Grid.Column="0" Width="1" Background="LightGray" ResizeDirection="Columns" dragDrop:RadDragAndDropManager.AllowDrag="True" dragDrop:RadDragAndDropManager.DragQuery="GridSplitter_DragQuery"/>  
                            <TextBlock Grid.Column="1" Text="{Binding Text}" Margin="3,0,0,0"/>  
                        </Grid> 
                    </Border> 
                </HierarchicalDataTemplate> 
            </telerik:RadTreeView.ItemTemplate> 
            <telerik:RadTreeView.Items> 
                <local:PairText Key="line1" Text="Some text for line1"/>  
                <local:PairText Key="line2" Text="Some text for line2"/>  
                <local:PairText Key="line3" Text="Some text for line3">  
                    <local:PairText.Children> 
                        <local:PairText Key="line3.1" Text="Some text for line3.1"/>  
                        <local:PairText Key="line3.2" Text="Some text for line3.2"/>  
                        <local:PairText Key="line3.3" Text="Some text for line3.3"/>  
                    </local:PairText.Children> 
                </local:PairText> 
                <local:PairText Key="line4" Text="Some text for line4"/>  
                <local:PairText Key="line5" Text="Some text for line5"/>  
            </telerik:RadTreeView.Items> 
        </telerik:RadTreeView> 
        private void treeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)  
        {  
            MessageBox.Show("Tree");  
            e.Handled = true;  
        }  
 
        private void treeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)  
        {  
            PairText pair = (sender as RadTreeViewItem).Item as PairText;  
            MessageBox.Show("Item : " + pair.Key);  
            e.Handled = true;  
        }  
 

When I double click on "line3.2" I want to obtain only the "Item : line3.2" message but there is "Item : line3" and "Tree" messages too.

Have you any suggestions ?

Thanks,
Guillaume R.

5 Answers, 1 is accepted

Sort by
0
Miro Miroslavov
Telerik team
answered on 02 Jul 2010, 01:50 PM
Hello GuillaumeR,

This is the expected behavior for the MouseDoubleClick event (even it is routed event). You can read more about this and how to workaround at this msdn article.
Hope will be helpful for you.

Regards,
Miro Miroslavov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
GuillaumeR
Top achievements
Rank 1
answered on 02 Jul 2010, 03:29 PM
Thanks for this answer, this is helpful for me.

But, the MouseLeftButtonDown seems to be handled before we can themself handle it. (for selection ?)

I tried with PreviewMouseLeftButtonDown and for it I receive events, but I want catch event in the other order (item before container) so I need to handle the MouseLeftButtonDown event.

Thanks,
Guillaume R.
0
Miro Miroslavov
Telerik team
answered on 07 Jul 2010, 12:59 PM
Hello GuillaumeR,

This is also expected behavior, since we use the event for the Selection and the end users can use SelectionChanged event instead. However you can hook events that are handler using the so called Class handlers - read more.

Regards,
Miro Miroslavov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ristogod
Top achievements
Rank 2
answered on 08 Oct 2010, 10:23 PM
Can you show an example of how you would code for a double click then. I don't seem to understand this. If I use the double click event handler, it goes up the whole tree. That is wrong. It maybe intended, but it's still wrong as rain.

Using the MouseLeftButtonDown doesn't do anything, the event doesn't fire. So how do you get it to fire. I looked at the above link, but doesn't make a bit of sense to me. Can you show a code example?
0
Tina Stancheva
Telerik team
answered on 14 Oct 2010, 02:35 PM
Hello Ristogod,

The routing strategy of the MouseDoubleClick event is Direct. Therefore, it is raised along the element tree by each UIElement. If you set the Handled property to true in a MouseDoubleClick event handler, subsequent MouseDoubleClick events along the route will occur with Handled set to false.

If your scenario, however, requires you to implement custom logic only on the initially double clicked item, then you can implement this logic only if the RadTereView.SelectedContainer is the sender of the MouseDoubleClick event.

I prepared a sample project illustrating this approach. Give it a try and let me know if you need more info.

Greetings,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
GuillaumeR
Top achievements
Rank 1
Answers by
Miro Miroslavov
Telerik team
GuillaumeR
Top achievements
Rank 1
Ristogod
Top achievements
Rank 2
Tina Stancheva
Telerik team
Share this question
or