avalondock override contextmenu - cannot find the type ContextMenuElement

淺唱寂寞╮ 提交于 2019-12-11 11:58:13

问题


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.

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

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" />

What am I missing ?

Edit: 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:


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.

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}"/>
...

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.



来源:https://stackoverflow.com/questions/12925520/avalondock-override-contextmenu-cannot-find-the-type-contextmenuelement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!