You must Sign In to post a response.
  • Category: WPF

    How to Create the Dynamic Menu In WPF ?

    Dear Team ,
    I have back end Table for menu so i have to load the menu dynamically .

    i have 5 main Menu and each Main Menu have "N" of child Menu .
    Child Menu May have Child Menu also .

    I have one Column Like Menu Type "M" , Means that Menu Have Child Menu .
    if Menu Type "U" Means No child Menu .

    So i want Load the Menu Dynamically . Please do need ful .
  • #768818
    Hai HemzChand,
    You can write 2 functions/methods, first one to load all the main menus by using the condition of menu type 'U". Once you get these menus from the database, you can load them.
    The second method will be used to get the child menus by passing the main menu id. So your method will take the parameter for the main menu id and based on this main menu id, it should get the child menus for it.
    By this way, you can retrieve all the main menu and sub menus.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #768819
    Thanks for your reply Pawan .
    Main menu is loaded . But I don't know how to load the child mmenu . Pls give some examples. I was using Mvvm partten .I am waiting for ur reply .

  • #768821
    Hai HemzChand,
    You can try the below links for the code solution and verify if its working.

    http://geekswithblogs.net/shatthi/archive/2010/10/04/dynamic-menu-control-in-wpf.aspx

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #768860
    You need to follow given step
    [1] Create object for Menuitem.
    [2]Edit the properties of MenuItem.
    [3] Add Menu item to the Main Menu
    Here is the example for How to Create the Dynamic Menu In WPF
    public abstract class MenuItem
    {
    private string name;

    private string text;

    private ObservableCollection<MenuItem> subItems;

    private ICommand onSelected;

    private MenuItem parent1;

    public MenuItem(string name, string text)
    {
    this.name = name;
    this.text = text;
    this.subItems = new ObservableCollection<MenuItem>();
    }

    public string Name { get { return this.name; } }

    public string Text { get { return this.text; } }

    public MenuItem Parent1 { get { return this.parent1; } set { this.parent1 = value; } }

    public ICommand OnSelected
    {
    get
    {
    if (this.onSelected == null)
    {
    this.onSelected = new MenuCommand(this.OnItemSelected, this.ItemCanBeSelected);
    }
    return this.onSelected;
    }
    }

    public ObservableCollection<MenuItem> SubItems
    {
    get
    {
    return this.subItems;
    }
    }

    public void AddSubMenu(MenuItem menuItem)
    {
    this.subItems.Add(menuItem);
    }

    public void RemoveSubMenu(MenuItem menuItem)
    {
    if(this.subItems.Contains(menuItem))
    {
    this.subItems.Remove(menuItem);
    }
    }

    public abstract void OnItemSelected();

    public virtual bool ItemCanBeSelected()
    {
    return true;
    }
    }


  • Sign In to post your comments