public async void SearchMenuTextChanged() { collapseMenu(true); await SetupSideMenu(); List <TreeViewItemExCategory> newResult = new List <TreeViewItemExCategory>(); MainMenuCategories.ForEach(cat => { var toleave = cat.Items.Where(a => a.Name.ContainsIgniorCase(SearchMenuText)); var newCat = new TreeViewItemExCategory(cat.Name); newCat.Items = new ObservableCollection <TreeViewItemEx>(toleave); if (newCat.Items.Any()) { newResult.Add(newCat); } }); MenuIsExpanded = true; NotifyOfPropertyChange("MenuIsExpanded"); MainMenuCategories = newResult; NotifyOfPropertyChange("MainMenuCategories"); }
public async Task SetupSideMenu() { // Init actions MainMenuCategories.Clear(); // sideMenu.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; // Load config models var models = new List <ExtendedDocument>(); var config = new XmlDocument(); config.Load("Modules/Models.xml"); // get ModulesERP var modules = DataHelpers.GetMongoDataSync("ModuleErp") as IEnumerable <ModuleErp>; config.DocumentElement.RemoveAll(); var TopMenus = modules.Where(z => !string.IsNullOrEmpty(z.GroupeModule)).Select(a => a.GroupeModule).Distinct(); foreach (var groupe in TopMenus) { var moduleOfGroupe = modules.Where(a => a.GroupeModule == groupe); //(2) string.Empty makes cleaner code XmlElement section = config.CreateElement(string.Empty, "section", string.Empty); section.SetAttribute("header", groupe); section.SetAttribute("icon", "Desktop"); foreach (var module in moduleOfGroupe) { XmlElement document = config.CreateElement(string.Empty, "item", string.Empty); //header ="Clients" icon="Users" description="" class="ErpAlgerie.Modules.CRM.Client" document.SetAttribute("header", module.Libelle); document.SetAttribute("icon", "Users"); document.SetAttribute("class", module.ClassName); if (module.IsInstanceModule) { document.SetAttribute("instance", "getInstance"); } section.AppendChild(document); } config.DocumentElement.AppendChild(section); } config.Save("Modules/Models.xml"); config.Load("Modules/Models.xml"); parentStack = new StackPanel(); // Iteerate over items foreach (XmlNode node in config.DocumentElement.ChildNodes) { // iterate over sections Console.Write(node.ChildNodes); var header = node.Attributes["header"].Value; // ExpanderMenu expander = new ExpanderMenu(); // var nodeTree = new TreeViewItemExCategory(header, new Li); var Children = new List <TreeViewItemEx>(); // var items = node.ChildNodes; foreach (XmlNode item in items) { var modelHeader = item.Attributes["header"].Value; var modelClass = item.Attributes["class"].Value; var modelIcon = item.Attributes["icon"].Value; var modelInstance = item.Attributes["instance"]?.Value; var itemNode = new TreeViewItemEx(modelHeader, modelHeader); itemNode.NodeXml = item; // itemNode.HeaderContent = new Button() { Content = modelHeader }; var i = new FontAwesome.WPF.ImageAwesome(); // i.Icon = (FontAwesomeIcon)Enum.Parse(typeof(FontAwesomeIcon), modelIcon); i.Icon = FontAwesomeIcon.Plus; i.Foreground = System.Windows.Media.Brushes.LightGray; // itemNode.HeaderIcon = modelIcon; Children.Add(itemNode); } var Category = new TreeViewItemExCategory(header, Children.ToArray()); MainMenuCategories.Add(Category); } NotifyOfPropertyChange("sideMenu"); }