简体   繁体   English

将XAML上下文菜单转换为资源

[英]Turning XAML context menu into resource

I'm trying to edit some code so that a context menu is contained in the resources of a xaml file rather than within the actual code. 我正在尝试编辑一些代码,以便上下文菜单包含在xaml文件的资源中,而不是包含在实际代码中。 The context menu is: 上下文菜单为:

<ContextMenu x:Key="CameraControlContextMenu" x:Shared="False" cal:Action.TargetWithoutContext="{Binding Path=DataContext, RelativeSource={RelativeSource Self}}">
    <exclusiveMenuItem:ExclusiveMenuItem x:Name="Turn" Header="{DynamicResource SetCameraToTurn}" IsCheckable="True" IsChecked="{Binding IsTurnMode}" cal:Message.Attach="[Event Click] = [Action TurnMode]" IsEnabled="{Binding IsAvailable}" Icon="{DynamicResource TurningImageSource}"/>
    <exclusiveMenuItem:ExclusiveMenuItem x:Name="Drag" Header="{DynamicResource SetCameraToDrag}" IsCheckable="True" IsChecked="{Binding IsDragMode}" cal:Message.Attach="[Event Click] = [Action DragMode]" Icon="{DynamicResource DragImageSource}"/>            
</ContextMenu>

Anyway, the context menu works fine and was located within another menu: 无论如何,上下文菜单可以正常工作,并且位于另一个菜单中:

<splitButton:SplitButton.DropDownContextMenu>
    CONTEXTMENUWASHERE
</splitButton:SplitButton.DropDownContextMenu>

I'm trying to extract it into the XAML file's resources so I can use it in more than one place. 我试图将其提取到XAML文件的资源中,以便可以在多个地方使用它。 I'm having a bit of trouble though. 不过我有点麻烦。 I've taken it out fine, the problem is referencing the context menu in the resources from within that splitbutton there. 我已经做好了,问题是从那里的splitbutton引用资源中的上下文菜单。

My XAML is a little shaky and I'm finding this a bit tricky to research, although I imagine the solution is probably something very simple. 我的XAML有点不稳定,尽管我认为解决方案可能非常简单,但是我发现这很难研究。

Any help is appreciated, thanks. 任何帮助表示赞赏,谢谢。

I don't really see your problem, or perhaps I've either misunderstood it, or you're just not seeing the wood for the trees? 我真的看不到您的问题,或者也许我误解了它,或者您只是没有看到树木的木头? How about setting the ContextMenu on your control in the normal short XAML form: 如何以普通的简短XAML形式在控件上设置ContextMenu

<splitButton:SplitButton 
    DropDownContextMenu="{StaticResource CameraControlContextMenu}" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM