ContextMenu with RadTreeListView - GetClickedElement problem

6 posts, 1 answers
  1. Dario
    Dario avatar
    61 posts
    Member since:
    Apr 2011

    Posted 16 May 2015 Link to this post

    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?
        }
    }

  2. Dario
    Dario avatar
    61 posts
    Member since:
    Apr 2011

    Posted 16 May 2015 Link to this post

    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. }

  3. UI for WPF is Visual Studio 2017 Ready
  4. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 20 May 2015 Link to this post

    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
  5. Dario
    Dario avatar
    61 posts
    Member since:
    Apr 2011

    Posted 20 May 2015 in reply to Kalin Link to this post

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

     

  6. Answer
    Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 21 May 2015 Link to this post

    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
  7. Dario
    Dario avatar
    61 posts
    Member since:
    Apr 2011

    Posted 05 Jun 2015 in reply to Kalin Link to this post

    Perferct! Thank you!
Back to Top
UI for WPF is Visual Studio 2017 Ready