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

Binding the visiblity of context menu item with gridview

2 Answers 43 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Zhiyong
Top achievements
Rank 1
Zhiyong asked on 12 Aug 2010, 03:40 AM
May I ask how to bind the visiblity of context menu item with the number of selected items (such as single or multiple), or some property of the selected rows.

Thanks!
Joe

2 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 12 Aug 2010, 09:15 AM
Hi Zhiyong,

You can handle the Opened event of the RadContextMenu and apply the logic you need. In case you want to bind the Visibility of a certain item to the SelectionMode of the grid, you can do as follows:

void rowContextMenu_Opened(object sender, RoutedEventArgs e)
{
    RadContextMenu menu = sender as RadContextMenu;
    var clickedRow = menu.GetClickedElement<GridViewRow>();
 
    if(this.clubsGrid.SelectionMode == System.Windows.Controls.SelectionMode.Single)
    {
        RadMenuItem item = menu.Items[1] as RadMenuItem;
        item.Visibility = System.Windows.Visibility.Collapsed;
    }
}

In case you require to bind the Visibility to some property of the clicked row, you may code it like:
oid rowContextMenu_Opened(object sender, RoutedEventArgs e)
{
    RadContextMenu menu = sender as RadContextMenu;
    var clickedRow = menu.GetClickedElement<GridViewRow>();
 
    Club club = clickedRow.Item as Club;
    if (club != null && club.Name == "Arsenal")
    {
        RadMenuItem item = menu.Items[1] as RadMenuItem;
        item.Visibility = System.Windows.Visibility.Collapsed;
    }          
}



All the best,
Maya
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
Zhiyong
Top achievements
Rank 1
answered on 12 Aug 2010, 04:47 PM
Thanks a lot! It solves the problem.

Best,
zhiyong
Tags
GridView
Asked by
Zhiyong
Top achievements
Rank 1
Answers by
Maya
Telerik team
Zhiyong
Top achievements
Rank 1
Share this question
or