RadGridView中的组行上下文菜单

时间:2011-09-21 13:09:04

标签: silverlight xaml telerik

我找到了一个旧的解决方案Here

但是GridViewExpander在2009年已经过时了。证明Here

如何以另一种方式实现它(RadGridView中的组行上的上下文菜单)?

1 个答案:

答案 0 :(得分:0)

没有答案...... =(

但我找到了解决方案。 有两种方法可以解决它:

1)如果您需要GridViewGroupRow的自定义样式 - 请阅读Templates Structure

2)如果没有,那就用这样的东西:

<TelerikNavigation:RadContextMenu.ContextMenu>
            <TelerikNavigation:RadContextMenu Opened="RadContextMenuOpened" ItemClick="ContextMenuItemClick" x:Name="contextMenu">
            </TelerikNavigation:RadContextMenu>

private void RadContextMenuOpened(object sender, RoutedEventArgs e)
    {
        var menu = (RadContextMenu)sender;
        if (menu == null)
            return;
        var cell = menu.GetClickedElement<GridViewCell>();
        var row = menu.GetClickedElement<GridViewRow>();
        var groupRow = menu.GetClickedElement<GridViewGroupRow>();
        if (cell != null && row != null)
        {
            if (!cell.DataColumn.IsFrozen)
            {
                //Code for current cell
            }
        }
        if (groupRow != null)
        {
            //Code for groupRow
        }
    }

private void ContextMenuItemClick(object sender, RadRoutedEventArgs e)
    {
        if (_currentCell != null)
        {
            //Code for current cell
        }
        if (_currentGroupRow != null)
        {
            var menu = (RadContextMenu)sender;
            var clickedItem = e.OriginalSource as RadMenuItem;
            if (clickedItem != null)
            {
                foreach (var gridViewRow in _currentGroupRow.ChildrenOfType<GridViewRow>())
                {
                    foreach (var gridViewCellBase in gridViewRow.Cells)
                    {
                        if (gridViewCellBase.Column.UniqueName == "PlanObject")
                        {
                            var val = gridViewCellBase.DataContext as YourObjectName;
                            if (val != null)
                            {
                                //.....
                            }
                        }
                    }
                }
                //....
            }
        }
    }