0

我有一个超出数据网格,我想绑定列标题的上下文菜单属性。这是我的代码

<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" x:Class="Sedan.Ux.Sheets.Views.SheetView" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="VisibilityConverter"/>
        <Style TargetType="{x:Type xcdg:ColumnManagerCell}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type xcdg:ColumnManagerCell}">

                        <Grid VerticalAlignment="Center" HorizontalAlignment="Stretch">

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" Text="{TemplateBinding Content}" HorizontalAlignment="Stretch"/>
                            <TextBlock Grid.Column="1" Text=" &#x25BC;" HorizontalAlignment="Stretch" >

                            </TextBlock>

                        </Grid>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ContextMenu">
                <Setter.Value>
                    <ContextMenu DataContext="{Binding Menus}" ItemsSource="{Binding Menus}">
                        <ContextMenu.ItemContainerStyle>
                            <Style TargetType="MenuItem">
                                <Setter Property="Header" Value="{Binding Name}"/>
                                <Setter Property="ItemsSource" Value="{Binding SubMenus}"/>
                                <Setter Property="Command" Value="{Binding Command}"/>
                                <Setter Property="CommandParameter" Value="{Binding Name}"></Setter>
                            </Style>
                        </ContextMenu.ItemContainerStyle>
                    </ContextMenu>
                </Setter.Value>
            </Setter>

        </Style>

    </UserControl.Resources>
     <Grid>
        <xcdg:DataGridControl  Grid.Row="0" x:Name="Sheet" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Margin="3" AutoCreateColumns="True" ReadOnly="{Binding ReadOnly}" ItemsSource="{Binding Data}" SelectionMode="Single" SelectedItem="{Binding SelectedItem}">

        </xcdg:DataGridControl>

    </Grid>



</UserControl>

当我在样式中使用 Setter 时,我无法绑定 Menus 属性。

如果我删除绑定和硬代码菜单项,我可以看到上下文菜单。

我已经对如何完成它进行了研究,并且我在 stackoverflow 和其他论坛上找到了关于在绑定中使用“相对源自我”的各种建议,但这对我不起作用。

如果我将菜单绑定到用户控件中任何按钮的上下文菜单(不是通过样式),那么我可以看到菜单。请帮忙。

4

0 回答 0