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

ContextMenu with RadTreeListView - GetClickedElement problem

5 Answers 208 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Dario
Top achievements
Rank 2
Dario asked on 16 May 2015, 10:37 AM

Hi guys,

I have this XAML

<telerik:RadTreeListView AutoGenerateColumns="False" ItemsSource="{Binding Categories}" SelectedItem="{Binding SelectedCategory,Mode=TwoWay}">
   <telerik:RadContextMenu.ContextMenu>
     <telerik:RadContextMenu x:Name="CategoryContextMenu" Opened="CategoryContextMenu_Opened">
       <telerik:RadMenuItem Header="Aggiungi" />
     </telerik:RadContextMenu>
   </telerik:RadContextMenu.ContextMenu>
   <telerik:RadTreeListView.ChildTableDefinitions>
     <telerik:TreeListViewTableDefinition ItemsSource="{Binding Categories}" />
   </telerik:RadTreeListView.ChildTableDefinitions>
   <telerik:RadTreeListView.Columns>
     <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}" Header="Categoria" />
     <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding Positive}" Header="Positivo" />
   </telerik:RadTreeListView.Columns>
</telerik:RadTreeListView>

 Now, if I click on anything node, enter in CategoryContextMenu_Opened but GetClickedElement return null ever!

private void CategoryContextMenu_Opened(object sender, RoutedEventArgs e)
{
   RadTreeViewItem item = this.CategoryContextMenu.GetClickedElement<RadTreeViewItem>();
   if (item != null) //It never true!!!
   {
     viewModel.SelectedCategory = (LocalCategory)item.DataContext; //Can I do it?
    }
}

5 Answers, 1 is accepted

Sort by
0
Dario
Top achievements
Rank 2
answered on 16 May 2015, 10:39 AM

Hi guys,I have this XAML

<telerik:RadTreeListView AutoGenerateColumns="False" ItemsSource="{Binding Categories}" SelectedItem="{Binding SelectedCategory,Mode=TwoWay}">
    <telerik:RadContextMenu.ContextMenu>
      <telerik:RadContextMenu x:Name="CategoryContextMenu" Opened="CategoryContextMenu_Opened">
        <telerik:RadMenuItem Header="Aggiungi" />
      </telerik:RadContextMenu>
    </telerik:RadContextMenu.ContextMenu>
    <telerik:RadTreeListView.ChildTableDefinitions>
      <telerik:TreeListViewTableDefinition ItemsSource="{Binding Categories}" />
    </telerik:RadTreeListView.ChildTableDefinitions>
    <telerik:RadTreeListView.Columns>
      <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}" Header="Categoria" />
      <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding Positive}" Header="Positivo" />
    </telerik:RadTreeListView.Columns>
 </telerik:RadTreeListView>
null ever!

1.private void CategoryContextMenu_Opened(object sender, RoutedEventArgs e)
2.{
3.   RadTreeViewItem item = this.CategoryContextMenu.GetClickedElement<RadTreeViewItem>();
4.    if (item != null) //It never true!!!
5.    {
6.      viewModel.SelectedCategory = (LocalCategory)item.DataContext; //Can I do it?
7.     }
8. }

0
Kalin
Telerik team
answered on 20 May 2015, 10:43 AM
Hi Dario,

If you need to get whole row you would need to look for TreeListViewRow item and if need only the clicked cell you would need to look for GridViewCell item:

var item1 = this.CategoryContextMenu.GetClickedElement<TreeListViewRow>();
var item2 = this.CategoryContextMenu.GetClickedElement<GridViewCell>();

Hope this helps.

Regards,
Kalin
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Dario
Top achievements
Rank 2
answered on 20 May 2015, 01:25 PM

This it's clear, my question is why it is never initalized, into ContextMenu_Opened event the this.CategoryContextMenu.GetClickedElement return EVER null.

 

1
Accepted
Kalin
Telerik team
answered on 21 May 2015, 08:12 AM
Hi Dario,

The issue was that you were looking for RadTreeViewItem clicked item and there isn't such. RadTreeListView uses elements of type TreeListViewRow for the rows and GridViewCell for the cells.

Hope this helps.

Regards,
Kalin
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Dario
Top achievements
Rank 2
answered on 05 Jun 2015, 02:47 PM
Perferct! Thank you!
Tags
ContextMenu
Asked by
Dario
Top achievements
Rank 2
Answers by
Dario
Top achievements
Rank 2
Kalin
Telerik team
Share this question
or