/// <summary> /// Method to property changed in <see cref="MenuMergingViewModel"/>class. /// </summary> /// <param name="sender">Specifies the object </param> /// <param name="e">Speciifes the EventArgs</param> void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "ActiveDocument") { if (ActiveDocument is GridView) { if (!OtherCollection.Contains(GridModel)) { OtherCollection.Remove(HelpModel); OtherCollection.Add(GridModel); OtherCollection.Add(HelpModel); OtherToolBarCollection = GridModel.MenuMergingCollection; OtherCollection.Remove(ChartModel); OtherCollection.Remove(Chart1Model); } } else { if (!OtherCollection.Contains(ChartModel)) { OtherCollection.Remove(HelpModel); OtherCollection.Add(ChartModel); OtherToolBarCollection = ChartModel.MenuMergingCollection; OtherCollection.Add(Chart1Model); OtherCollection.Remove(GridModel); OtherCollection.Add(HelpModel); } } } else if (e.PropertyName == "IsChecked") { if (checkedModel != null) { checkedModel.IsChecked = false; } checkedModel = sender as MenuMergingModel; } }
/// <summary> /// Initializes the instance of <see cref="MenuMergingViewModel"/> class. /// </summary> public MenuMergingViewModel() { this.Products = new ObservableCollection <ChartModel>(); Random rndm = new Random(); CommonResourceDictionary = new ResourceDictionary() { Source = new Uri("/syncfusion.navigationdemos.wpf;component/Assets/Menu/Icon.xaml", UriKind.RelativeOrAbsolute) }; newGridCommand = new DelegateCommand <object>(OpenNewGrid); newChartCommand = new DelegateCommand <object>(OpenNewChart); newCommand = new DelegateCommand <object>(OpenNew); tileHorizontalCommand = new DelegateCommand <object>(TileHorizontal); tileVerticallCommand = new DelegateCommand <object>(TileVertical); tileCascadeCommand = new DelegateCommand <object>(Cascade); helpCommand = new DelegateCommand <object>(ExecuteHelpCommand); aboutCommand = new DelegateCommand <object>(ExecuteAboutCommand); Products.Add(new ChartModel() { ProductId = 1, ProductName = "Rice", OldPrice = rndm.Next(5, 40), NewPrice = rndm.Next(10, 60) }); Products.Add(new ChartModel() { ProductId = 2, ProductName = "Wheat", OldPrice = rndm.Next(5, 80), NewPrice = rndm.Next(10, 60) }); Products.Add(new ChartModel() { ProductId = 1, ProductName = "Oil", OldPrice = rndm.Next(5, 60), NewPrice = rndm.Next(10, 60) }); Products.Add(new ChartModel() { ProductId = 4, ProductName = "Corn", OldPrice = rndm.Next(5, 40), NewPrice = rndm.Next(10, 60) }); Products.Add(new ChartModel() { ProductId = 5, ProductName = "Gram", OldPrice = rndm.Next(5, 40), NewPrice = rndm.Next(10, 60) }); Products.Add(new ChartModel() { ProductId = 6, ProductName = "Milk", OldPrice = rndm.Next(5, 90), NewPrice = rndm.Next(10, 60) }); Products.Add(new ChartModel() { ProductId = 7, ProductName = "Butter", OldPrice = rndm.Next(5, 40), NewPrice = rndm.Next(10, 60) }); Products.Add(new ChartModel() { ProductId = 8, ProductName = "Oil", OldPrice = rndm.Next(5, 60), NewPrice = rndm.Next(10, 60) }); FileCollection = new ObservableCollection <MenuMergingModel>(); WindowCollection = new ObservableCollection <MenuMergingModel>(); FileModel = new MenuMergingModel() { Name = "File" }; FileModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "New Product Details", Icon = CommonResourceDictionary["New"] as object, ImageTemplate = CommonResourceDictionary["NewPathIcon"] as DataTemplate, Command = NewGridCommand }); FileModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "New product Statistics", Icon = CommonResourceDictionary["FileChart"] as object, ImageTemplate = CommonResourceDictionary["ChartPathIcon"] as DataTemplate, Command = NewChartCommand }); FileModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Open", Icon = CommonResourceDictionary["Open"] as object, ImageTemplate = CommonResourceDictionary["OpenPathIcon"] as DataTemplate, Command = NewCommand }); FileModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Exit", Icon = CommonResourceDictionary["FileDelete"] as object, ImageTemplate = CommonResourceDictionary["DeletePathIcon"] as DataTemplate, Command = NewCommand }); WindowModel = new MenuMergingModel() { Name = "Windows" }; WindowModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Cascade", Icon = CommonResourceDictionary["CascadeWindow"] as object, ImageTemplate = CommonResourceDictionary["CascadeWindowPathIcon"] as DataTemplate, Command = TileCascadeCommand, IsCheckable = true }); WindowModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Tile Horizontally", Icon = CommonResourceDictionary["ArrangeWindow"] as object, ImageTemplate = CommonResourceDictionary["ArrangeWindowPathIcon"] as DataTemplate, Command = TileHorizontalCommand, IsCheckable = true }); WindowModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Tile Vertically", Icon = CommonResourceDictionary["SideBySide"] as object, ImageTemplate = CommonResourceDictionary["SideBySidePathIcon"] as DataTemplate, Command = TileVerticalCommand, IsCheckable = true }); WindowModel.MenuMergingCollection[0].PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged); WindowModel.MenuMergingCollection[1].PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged); WindowModel.MenuMergingCollection[2].PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged); ChartModel = new MenuMergingModel() { Name = "Chart View" }; ChartModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "New Statistics", Icon = CommonResourceDictionary["Chart"] as object, ImageTemplate = CommonResourceDictionary["ChartPathIcon"] as DataTemplate, Command = NewCommand }); ChartModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Refresh Chart", Icon = CommonResourceDictionary["Repeat"] as object, ImageTemplate = CommonResourceDictionary["RepeatPathIcon"] as DataTemplate, Command = NewCommand }); ChartModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Publish Data", Icon = CommonResourceDictionary["PublishWeb"] as object, ImageTemplate = CommonResourceDictionary["PublishWebPathIcon"] as DataTemplate, Command = NewCommand }); ChartModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Close View", Icon = CommonResourceDictionary["Delete"] as object, ImageTemplate = CommonResourceDictionary["DeletePathIcon"] as DataTemplate, Command = NewCommand }); Chart1Model = new MenuMergingModel() { Name = "Customize Chart" }; Chart1Model.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Change Chart Type", Icon = CommonResourceDictionary["Pie"] as object, ImageTemplate = CommonResourceDictionary["AlignToBottomPathIcon"] as DataTemplate, Command = NewCommand }); Chart1Model.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Add Series", Icon = CommonResourceDictionary["AlignToBottom"] as object, ImageTemplate = CommonResourceDictionary["DeletePathIcon"] as DataTemplate, Command = NewCommand }); this.PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged); GridModel = new MenuMergingModel() { Name = "Grid View" }; GridModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Refresh Grid", Icon = CommonResourceDictionary["GridRepeat"] as object, ImageTemplate = CommonResourceDictionary["RepeatPathIcon"] as DataTemplate, Command = NewCommand }); GridModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Close View", Icon = CommonResourceDictionary["GridDelete"] as object, ImageTemplate = CommonResourceDictionary["DeletePathIcon"] as DataTemplate, Command = NewCommand }); HelpModel = new MenuMergingModel() { Name = "Help" }; HelpModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "Online Help", Icon = CommonResourceDictionary["Help"] as object }); HelpModel.MenuMergingCollection.Add(new MenuMergingModel() { Name = "About" }); OtherCollection = new ObservableCollection <MenuMergingModel>(); OtherToolBarCollection = new ObservableCollection <MenuMergingModel>(); OtherCollection.Add(FileModel); FileCollection = FileModel.MenuMergingCollection; OtherCollection.Add(WindowModel); WindowCollection = WindowModel.MenuMergingCollection; }