public AddParticleDlg(AddParticleDlgViewModel model)
 {
     InitializeComponent();
     Loaded += (sender, args) =>
     {
         var hwnd = new WindowInteropHelper(this).Handle;
         WindowHelper.SetWindowAsDialog(hwnd);
         DataContext = model;
     };
 }
        public void FormContextMenu(CommonBarItemCollection menuItems)
        {
            menuItems.Clear();

            var createCommentCommand = new DelegateCommand(() =>
            {
                var dlgModel = new CreateCommentDlgViewModel(_particlesManager, _blockManager, _commentManager, _eventAggregator);
                SetParticleIfExist(dlgModel.AddParticleVm);

                var dlg = new CreateCommentDlg(dlgModel);
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value)
                    UpdateBookmarks();

            });
            var createIdeaCommand = new DelegateCommand(() =>
            {
                var dlgModel = new CreateIdeaDlgViewModel(_tagsManager, _particlesManager, _ideaManager, _blockManager,
                    _eventAggregator);
                SetParticleIfExist(dlgModel.AddParticleVm);

                var dlg = new CreateIdeaDlg(dlgModel);
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value)
                    UpdateBookmarks();
            });

            var addToCommentCommand = new DelegateCommand(() =>
            {
                var dlgModel = new AddParticleDlgViewModel(_particlesManager, typeof(Entity.Comment), _blockManager);
                SetParticleIfExist(dlgModel.AddParticleVm);

                var dlg = new AddParticleDlg(dlgModel);
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value)
                    UpdateBookmarks();
            });

            var addToIdeaCommand = new DelegateCommand(() =>
            {
                var dlgModel = new AddParticleDlgViewModel(_particlesManager, typeof(Idea), _blockManager);
                SetParticleIfExist(dlgModel.AddParticleVm);

                var dlg = new AddParticleDlg(dlgModel);
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value)
                    UpdateBookmarks();
            });

            var createRelationCommand = new DelegateCommand(() =>
            {
                var dlgModel = new CreateRelationDlgViewModel(_particlesManager, _ideaManager, _relationManager, _blockManager, _eventAggregator);
                SetParticleIfExist(dlgModel.AddParticleVm);

                var dlg = new CreateRelationDlg(dlgModel);
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value)
                    UpdateBookmarks();
            });

            var createMenu = new BarSubItem() {Content = "Создать..."};
            var createComment = new BarButtonItem() {Content = "Комментарий", Command = createCommentCommand};
            var createIdea = new BarButtonItem() {Content = "Понятие", Command = createIdeaCommand};
            var createRelation = new BarButtonItem() {Content = "Отношение", Command = createRelationCommand};
            createMenu.Items.Add(createComment);
            createMenu.Items.Add(createIdea);
            createMenu.Items.Add(createRelation);

            var addMenu = new BarSubItem() { Content = "Добавить в..." };
            var addComment = new BarButtonItem() {Content = "Комментарий", Command = addToCommentCommand};
            var addIdea = new BarButtonItem() { Content = "Понятие", Command = addToIdeaCommand};
            var addRelation = new BarButtonItem() { Content = "Отношение" };
            addMenu.Items.Add(addComment);
            addMenu.Items.Add(addIdea);
            addMenu.Items.Add(addRelation);

            menuItems.Add(createMenu);
            menuItems.Add(addMenu);

            /*if (MyDocument != null)
            {
                foreach (var bm in MyDocument.Bookmarks)
                {
                    var nextBookmark = new BarButtonItem()
                    {
                        Content = bm.Name,
                        CommandParameter = MyDocument,
                        Command = new DelegateCommand<Document>(document =>
                        {
                            document.Bookmarks.Select(bm);
                        })
                    };
                    menuItems.Add(nextBookmark);
                }
            }*/
        }