本文介绍了avalondock覆盖contextmenu-找不到类型ContextMenuElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对-我的窗口打开得很好,我认为这是最困难的部分;但是我很难更改上下文菜单。

This is a follow up question to User control in avalon dock and separate window - I've got the window opening nicely which I thought would be the hard part; but i'm having difficulty in changing the contextmenu.

我是WPF和avalondock的新手,这可能很简单,但是我很想念它。

I'm new to WPF and avalondock and it's probably something simple but i'm missing it.

上一个问题将我指向作为示例。我收到找不到ContextMenuElement错误,因此进行了一些简单的操作:

Previous question pointed me to http://avalondock.codeplex.com/SourceControl/changeset/view/96370#1749982 as an example. I was getting a "ContextMenuElement not found" error so went for something simpler:

-这是要用法语替换文本,但我可以进行修改。我无法使其正常工作,然后尝试逐字复制粘贴并仍然出现相同的错误:

http://avalondock.codeplex.com/discussions/246250 - this is about replacing with French text but I could adapt it. I couldn't get it to work and then tried copy pasting verbatim and still have same error:

Cannot find the type ContextMenuElement. Note that type names are case sensitive

我在资源字典中得到此字,它指向命令的命令部分菜单项,例如:

I get this on the resource dictionary and it points to command part of the menu item eg:

   <MenuItem Header="Fermer"

                  Command="avalonDock:DocumentPaneCommands.CloseThis" />

我缺少什么?

编辑:资源字典的摘录:

Excerpt of resource dictionary:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:avalonDock="clr-namespace:AvalonDock;assembly=AvalonDock">

<!--Menu contextuel des onglets de l'avalonDock-->
<ContextMenu x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type avalonDock:DockingManager}, ResourceId={x:Static avalonDock:ContextMenuElement.DocumentPane}}">
    <MenuItem Header="Fermer"
                  Command="avalonDock:DocumentPaneCommands.CloseThis" />
    <MenuItem Header="Fermer tout sauf cet élément"
                        Command="{Binding Path=DataContext.FermerCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>

    <Separator />


推荐答案

您尝试修改的代码看起来像是版本1.3,则您可能正在使用新的2.0版本。更改DockingManager行为的方式已经发生了很大变化,并且现在比以往更加简单。

The code you are trying to adapt looks like it is for version 1.3 and you might be using the new 2.0 version. The way you change the behaviour of the DockingManager has changed a lot and is now simpler then ever.

这是一个小示例,用于替换DocumentPane中的ContextMenu (在v2.0.1320上进行了测试):

This is a small sample to replace the ContextMenu for a Document in the DocumentPane (tested on v2.0.1320):

<ad:DockingManager>
    <ad:DockingManager.DocumentContextMenu>
        <ContextMenu>
            <MenuItem Header="DEMO"/>
        </ContextMenu>
    </ad:DockingManager.DocumentContextMenu>
</ad:DockingManager>

在主题中,您可以看到如何使用样式完成

In the theme you can see how this is done using a style

<Style x:Key="{x:Type avalonDock:DockingManager}" TargetType="{x:Type avalonDock:DockingManager}">
    <Setter Property="DocumentContextMenu" Value="{StaticResource AvalonDock_ThemeVS2010_DocumentContextMenu}"/>
...

我仍然建议只复制以下主题项目他们的网站,并为您的应用程序构建自己的主题。这样,您就可以将所有修改内容整齐地存储在可重用的dll中。

I would still recommend to just make a copy of the theme project from their website and build your own theme for your application. That way you have all your adaptations neatly stored in a reusable dll.

这篇关于avalondock覆盖contextmenu-找不到类型ContextMenuElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 18:45