【问题标题】:Xceed PropertyGrid AdvancedOptionsMenu context menu exampleXceed PropertyGrid AdvancedOptionsMenu 上下文菜单示例
【发布时间】:2020-09-04 04:43:59
【问题描述】:

我正在尝试在单击任何属性的高级选项图标时显示“复制”上下文菜单。我需要添加什么才能使其正常工作?

<xctk:PropertyGrid
        x:Name="PropertyGrid"  
        Grid.Column="1" Margin="8"
        ShowSummary="False"    
        AutoGenerateProperties="True" 
        HideInheritedProperties="False"
        SelectedObject="{Binding InspectedObject}"
        SelectedObjectName="{Binding InspectedObject, Converter={StaticResource PropertyGridPropertyNameConverter}}"
        SelectedObjectTypeName="{Binding InspectedObject, Converter={StaticResource PropertyGridPropertyTypeConverter}}"
        SelectedObjectChanged="PropertyGrid_OnSelectedObjectChanged"
        ShowAdvancedOptions="True"

    >
    <xctk:PropertyGrid.AdvancedOptionsMenu >
        <ContextMenu>
            <MenuItem Header="Copy" Click="MenuItem_OnClick"></MenuItem>
        </ContextMenu>
    </xctk:PropertyGrid.AdvancedOptionsMenu>
</xctk:PropertyGrid>

无论属性是否为只读,我都希望显示“复制”上下文项并单击。

【问题讨论】:

  • 你找到答案了吗?你能分享吗?谢谢:)
  • 不,抱歉,我还没有解决这个问题 - 我一直在推迟解决这个问题,方法是使属性可写或制作允许复制的自定义控件(我有很多属性)
  • @IgorMF 我分叉了原始存储库,并将复制值菜单项添加到 AdvancedOptionsMenu。看看:github.com/kmatyaszek/wpftoolkit

标签: wpf propertygrid xceed


【解决方案1】:

在MenuItem点击事件处理程序中,可以通过sender对象中的属性DataContext来访问属性数据。

private void MenuItem_OnClick(object sender, RoutedEventArgs e)
{
    MenuItem menuItem = sender as MenuItem;
    if (menuItem != null && menuItem.DataContext is PropertyItem)
    {
        Clipboard.SetData(DataFormats.Text, ((PropertyItem)menuItem.DataContext).Value);
    }
}

在以下链接中,您可以找到有关此主题的更多信息: https://kmatyaszek.github.io/2018/08/22/extended-wpftoolkit-propertygrid-copybutton.html

我注意到,当您在 AdvancedOptionsMenu 图标上单击(鼠标左键)时,此解决方案有效,鼠标右键单击属性项时出现问题。为了解决这个问题,我分叉了原始 repo,并将复制值菜单项添加到 AdvancedOptionsMenu。看看吧:https://github.com/kmatyaszek/wpftoolkit

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多