.net - Multiple usage of MenuItems declared once (WPF) -
Is it possible to define some menu structure in WPF and by using it in many contexts? For example, I want to use the context menus, menu menus and toolbars (using a set of menu items from resources)
I look something like this:
Announcement in resources:
& lt; MenuItem Order = "MyCommands.CloneObject" CommandPamator = "{Binning Selected Object}" Header = "Clone" & gt; & Lt; MenuItem.Icon & gt; & Lt; Image Source = "Images \ clone" "Height =" 16 "width =" 16 ">
MenuItem Command = "MyCommands.RemoveCommand" CommandPamator = "{Binning Selected Object}" Header = "Remove"> Image Source = "Images \ Remove" "Height =" 16 "Width =" 16 "& gt; & Lt; / Image & gt; & Lt; /MenuItem.Icon> & Lt; / MenuItem & gt; & Lt; Separator / & gt; & Lt; MenuItem command = "MyCommands.CreateChild" CommandPamator = "{Binning Selected Object}" Header = "Create Child" & gt; & Lt; MenuItem.Icon & gt; & Lt; Image source = "images \ Child.png" height = "16" width = "16" & gt; & Lt; / Image & gt; & Lt; /MenuItem.Icon> & Lt; / MenuItem & gt;
Usage:
& lt; Toolbar menu item (?) = "{References to set of objects}" ShowText (?) = "Wrong" />
and
& lt; ContextMenu MenuItems (?) = "{Context to set item}" />
You can do this - to control and reuse the user - Other Desire UIElements function can not be the only parent:
CustomMenu.xaml
& lt; MenuItem x: class = "MyApplication.CustomMenu" xmlns = "http: // schemos Microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml "& Gt; & Lt; MenuItem Order = "MyCommands.CloneObject" CommandPamator = "{Binning Selected Object}" Header = "Clone" & gt; & Lt; MenuItem.Icon & gt; & Lt; Image Source = "Images \ clone" "Height =" 16 "width =" 16 ">
MenuItem Command = "MyCommands.RemoveCommand" CommandPamator = "{Binning Selected Object}" Header = "Remove"> Image Source = "Images \ Remove" "Height =" 16 "Width =" 16 "& gt; & Lt; / Image & gt; & Lt; /MenuItem.Icon> & Lt; / MenuItem & gt; & Lt; Separator / & gt; & Lt; MenuItem command = "MyCommands.CreateChild" CommandPamator = "{Binning Selected Object}" Header = "Create Child" & gt; & Lt; MenuItem.Icon & gt; & Lt; Image source = "images \ Child.png" height = "16" width = "16" & gt; & Lt; / Image & gt; & Lt; /MenuItem.Icon> & Lt; / MenuItem & gt; & Lt; / MenuItem & gt;
Code-Back Custom Menu Xaml.cs:
Public partial class custom menu {public custom menu () {initial group (); }}
and then use it in xaml like this:
& lt; Toolbar & gt; & Lt; Local: CustomMenu / & gt; & Lt; / Toolbar & gt; & Lt; ContextMenu & gt; & Lt; Local: CustomMenu / & gt; & Lt; / ContextMenu & gt;
Hope it helps.
Comments
Post a Comment