c# - Sub-menu for each binding item -
c# - Sub-menu for each binding item -
following example omer van kloeten filled menu menu items bound observable collection. got single menu item single collection item. fine, want more. want able have menu item 2 or 3 sub items 1 collection item. here rough sketch:
what have want + first item + create first item + sec item + sec item + delete + update
here "first item" has property exists = false
, "second item" has true
. current code:
public class collectionitem { public string name { get; set; } public bool exists { get; set; } } public partial class mainwindow : window { observablecollection<collectionitem> items; public mainwindow() { items = new observablecollection<collectionitem>(); items.add(new collectionitem() { name = "first item", exists = false }); items.add(new collectionitem() { name = "second item", exists = true }); allitems.itemssource = items; } } <menuitem x:name="allitems" header="what have"> <menuitem.itemcontainerstyle> <style targettype="{x:type menuitem}"> <setter property="header" value="{binding path=name}" /> </style> </menuitem.itemcontainerstyle> </menuitem>
how mix simple menu items sub items?
how mix simple menu items sub items?
first, need have info structured appropriately, collection properties represent child, or sub menuitem
s. then, need info bind collection property itemssource
property of parent menuitem
using menuitem.itemcontainerstyle
, similar you're doing now. should end this:
public class collectionitem { public string name { get; set; } public bool exists { get; set; } public observablecollection<collectionitem> collectionofsubitems { get; set; } }
...
<menuitem x:name="allitems" header="what have"> <menuitem.itemcontainerstyle> <style targettype="{x:type menuitem}"> <setter property="header" value="{binding path=name}" /> <setter property="itemssource" value="{binding collectionofsubitems}" /> </style> </menuitem.itemcontainerstyle> </menuitem>
c# wpf
Comments
Post a Comment