Hello
I'm trying to build a menu using the treeview control by building a List collection just like the DataBinding example of the demo
Right now, I have these three pieces of code :
When I execute this code, I can see the first level of the menu displaying fine, with the proper text.
I know by debbuging that the menuStruct variable holds the second level when I set the itemsource, but somehow, when I try to display it by clicking on the parent node, it won't expand.
FYI : MenuTreeView is declared earlier in the code, and Zone_Menu is a stackpanel in the xaml file.
Any idea why ?
I'm trying to build a menu using the treeview control by building a List collection just like the DataBinding example of the demo
Right now, I have these three pieces of code :
using System; |
using System.Net; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Documents; |
using System.Windows.Ink; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Animation; |
using System.Windows.Shapes; |
using System.Collections.Generic; |
namespace T2J_Application.Classes |
{ |
public class MenuStruct |
{ |
public MenuStruct(MenuItem menu) |
{ |
_menu = menu; |
_sous_menu = new List<SousMenu>(); |
} |
MenuItem _menu; |
public MenuItem _Menu { get { return _menu; } } |
List<SousMenu> _sous_menu; |
public List<SousMenu> _Sous_menu { get { return _sous_menu; } } |
} |
public class SousMenu |
{ |
public SousMenu(MenuItem sousMenu) |
{ |
_menu = sousMenu; |
_teams = new List<SousSousMenu>(); |
} |
MenuItem _menu; |
public MenuItem _Menu { get { return _menu; } } |
List<SousSousMenu> _teams; |
public List<SousSousMenu> Teams { get { return _teams; } } |
} |
public class SousSousMenu |
{ |
public SousSousMenu(MenuItem soussousmenu) |
{ |
_menu = soussousmenu; |
} |
MenuItem _menu; |
public MenuItem _Menu { get { return _menu; } } |
} |
} |
using System; |
using System.Net; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Documents; |
using System.Windows.Ink; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Animation; |
using System.Windows.Shapes; |
using System.Xml.Linq; |
using T2J_Application.ApplicationService; |
namespace T2J_Application.Classes |
{ |
public class MenuItem |
{ |
public MenuItem(MenuItemBO menuItem) |
{ |
Id_objet = menuItem.Id_objet; |
Code_objet = menuItem.Code_objet; |
Lib_objet = menuItem.Lib_objet; |
Action = menuItem.Action; |
Menu = menuItem.Menu; |
Position = menuItem.Position; |
Afficher = menuItem.Afficher; |
Modifier = menuItem.Modifier; |
Lib_categorie_partenaire = menuItem.Lib_categorie_partenaire; |
Id_objet_categorie = menuItem.Id_objet_categorie; |
Id_categorie_partenaire = menuItem.Id_categorie_partenaire; |
Id_objet_pere = menuItem.Id_objet_pere; |
Id_objet_type = menuItem.Id_objet_type; |
Id_objet_avant = menuItem.Id_objet_avant; |
Est_defaut = menuItem.Est_defaut; |
Id_societe = menuItem.Id_societe; |
} |
public int Id_objet { get; set; } |
public String Code_objet { get; set; } |
public String Lib_objet { get; set; } |
public String Action { get; set; } |
public Boolean Menu { get; set; } |
public int Position { get; set; } |
public Boolean Afficher { get; set; } |
public Boolean Modifier { get; set; } |
public String Lib_categorie_partenaire { get; set; } |
public int Id_objet_categorie { get; set; } |
public int Id_categorie_partenaire { get; set; } |
public int Id_objet_pere { get; set; } |
public int Id_objet_type { get; set; } |
public int Id_objet_avant { get; set; } |
public Boolean Est_defaut { get; set; } |
public int Id_societe { get; set; } |
} |
} |
IList<MenuStruct> menuStruct = new List<MenuStruct>(); |
IList<MenuItemBO> result = e.Result; |
IList<MenuItemBO> ItemParent = new List<MenuItemBO>(); |
IList<MenuItemBO> ItemEnfants = new List<MenuItemBO>(); |
IList<MenuItemBO> ItemSousMenuParents = new List<MenuItemBO>(); |
foreach (MenuItemBO item in result) |
{ |
if (item.Id_objet_type == 4) |
{ |
if (item.Id_objet_pere == 0) |
{ |
ItemParent.Add(item); |
} |
else |
{ |
ItemSousMenuParents.Add(item); |
} |
} |
else |
{ |
ItemEnfants.Add(item); |
} |
} |
foreach (MenuItemBO itemMenu in ItemParent) |
{ |
MenuStruct menus; |
menuStruct.Add(menus = new MenuStruct(new MenuItem(itemMenu))); |
foreach (MenuItemBO enfants in ItemEnfants) |
{ |
SousMenu ssmenu; |
if (menus._Menu.Id_objet == enfants.Id_objet_pere) |
{ |
menus._Sous_menu.Add(ssmenu = new SousMenu(new MenuItem(enfants))); |
} |
} |
} |
MenuTreeView.ItemsSource = menuStruct; |
MenuTreeView.DisplayMemberPath = "_Menu.Lib_objet"; |
MenuTreeView.Margin = new Thickness(0, 30, 0, 0); |
Zone_menu.Children.Add(MenuTreeView); |
When I execute this code, I can see the first level of the menu displaying fine, with the proper text.
I know by debbuging that the menuStruct variable holds the second level when I set the itemsource, but somehow, when I try to display it by clicking on the parent node, it won't expand.
FYI : MenuTreeView is declared earlier in the code, and Zone_Menu is a stackpanel in the xaml file.
Any idea why ?