Issue with RadTreeViewItem identification

1 Answer 55 Views
TreeListView TreeView Window
Manfredi
Top achievements
Rank 1
Manfredi asked on 02 Sep 2022, 08:41 AM | edited on 02 Sep 2022, 12:41 PM

Hello!

I am a new user of Telerik UI for wpf.
I have encountered a problem in a project in which I am working on.

The problem consist in the unability to identify the RadTreeViewItem on which a MouseRightButtonUp event is executed.

The setting is as follows, 

I have a RadTreeView that I fill dynamically through a databind of its ItemSource property.
And the event mentioned above (MouseRightButtonUp) is bound to the RadTreeView xaml tag,
since I do not have the RadTreeViewItem /s as a tag in my xaml.


How can I recover the child in which the event MouseRightButtonDown/MouseRightButtonUp, was triggered?
Thanks in advance for any help / clarification


Kind regards

1 Answer, 1 is accepted

Sort by
0
Marko
Top achievements
Rank 2
Iron
answered on 05 Sep 2022, 08:56 PM | edited on 05 Sep 2022, 08:57 PM

Instead of binding the MouseRightButtonUp to the RadTreeView. 
you could try to bind it to the individual items using the ItemContainerStyle:

xaml:

    <telerik:RadTreeView ItemsSource="{Binding RadTreeViewItems}">

        <telerik:RadTreeView.ItemContainerStyle>
            <Style TargetType="{x:Type telerik:RadTreeViewItem}">
                <EventSetter Event="MouseRightButtonUp" Handler="RadTreeView_MouseRightButtonUp" />
            </Style>
        </telerik:RadTreeView.ItemContainerStyle>

    </telerik:RadTreeView>

 

cs:

        private void RadTreeView_MouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            RadTreeViewItem selectedItem = (sender as RadTreeViewItem);
        }

 

You could also try using the PreviewMouseRightButtonUp event instead of the regular MouseRightButtonUp.

Tags
TreeListView TreeView Window
Asked by
Manfredi
Top achievements
Rank 1
Answers by
Marko
Top achievements
Rank 2
Iron
Share this question
or