コード例 #1
0
ファイル: MainMenuViewModel.cs プロジェクト: HaKDMoDz/Zazumo
        public MainMenuViewModel(CompositionContainer container)
        {
            _topLevelMenuItems = new ObservableCollection<MenuItemViewModel>();
            _styleSelector = new MainMenuItemStyleSelector();
            
            var menuItemImports =  container.GetExports<IMenuItem, IMenuItemMetaData>();
            var globalCommandImports = container.GetExports<IGlobalCommand>();

            var menuBuilder = new MenuBuilder(globalCommandImports);

            foreach (var import in menuItemImports.Where(x => x.Metadata.IsMainMenuItem))
            {
                menuBuilder.AddItem(import.Value, import.Metadata);
            }

            foreach (var rootItem in menuBuilder.Build().Children)
            {
                MenuItemViewModel viewModel;

                if (rootItem is MenuSeparatorModel)
                {
                    viewModel  = new MenuSeparatorViewModel();
                }
                else
                {
                    viewModel = new MenuItemViewModel(null, rootItem.HeaderText, rootItem.Command, rootItem.GestureText, rootItem.Children);
                }

                _topLevelMenuItems.Add(viewModel);
            }
        }
コード例 #2
0
ファイル: MenuItemViewModel.cs プロジェクト: HaKDMoDz/Zazumo
        public MenuItemViewModel(Object model, String headerText, ICommand command, String gestureText, IEnumerable<MenuItemModel> children)
        {
            this._children = new ObservableCollection<MenuItemViewModel>();
            this.HeaderText = headerText;
            this.Command = command;
            this.GestureText = gestureText;
            this.Model = model;

            foreach (var child in children)
            {
                MenuItemViewModel viewModel = null;

                if (child is MenuSeparatorModel)
                    viewModel = new MenuSeparatorViewModel();
                else
                    viewModel = new MenuItemViewModel(model, child.HeaderText, child.Command, child.GestureText, child.Children);

                this._children.Add(viewModel);
            }
        }
コード例 #3
0
        public PackageTreeNodeViewModel(Object model, PackageDatabaseTreeViewModel parent, CompositionContainer container, String assetType)
        {
            this._parent = parent;
            this._contextMenuTopLevelItems = new ObservableCollection<MenuItemViewModel>();
            this._children = new ObservableCollection<PackageTreeNodeViewModel>();
            this.Model = model;

            var menuItemImports = container.GetExports<IMenuItem, IContextMenuItemMetaData>();
            var globalCommandImports = container.GetExports<IGlobalCommand>();

            var menuBuilder = new MenuBuilder(globalCommandImports);

            foreach (var import in menuItemImports.Where(x => x.Metadata.AssetType == assetType))
            {
                if (import.Metadata.IsPrimary)
                {
                    this.PrimaryCommand = import.Value.Command;
                }

                menuBuilder.AddItem(import.Value, import.Metadata);
            }

            foreach (var rootItem in menuBuilder.Build().Children)
            {
                MenuItemViewModel viewModel;

                if (rootItem is MenuSeparatorModel)
                {
                    viewModel = new MenuSeparatorViewModel();
                }
                else
                {
                    viewModel = new MenuItemViewModel(this.Model, rootItem.HeaderText, rootItem.Command, rootItem.GestureText, rootItem.Children);
                }

                _contextMenuTopLevelItems.Add(viewModel);
            }
        }