Beispiel #1
0
            IDocument IDocumentManagerService.CreateDocument(string documentType, object viewModel, object parameter, object parentViewModel)
            {
                TestDocument doc = new TestDocument(documentType, viewModel, parameter, parentViewModel);

                ViewHelper.CreateAndInitializeView(doc, string.Empty, viewModel, parameter, parentViewModel);
                var vm = new TestSupportServices();

                vm.ParentViewModel = parentViewModel;
                DocumentUIServiceBase.SetTitleBinding(doc, TestDocument.TitleProperty, doc);
                vm.Parameter = parameter;
                doc.Content  = vm;
                docs.Add(doc);
                return(doc);
            }
        public void ViewHelperTest()
        {
            var button          = new Button();
            var viewModel       = new ViewModel();
            var parentViewModel = new ViewModel();
            var textBlock       = new TextBlock()
            {
                Text = "foo"
            };

            Assert.AreEqual(null, ViewHelper.GetViewModelFromView(button));
            ViewHelper.InitializeView(button, null, "test", parentViewModel);
            DocumentUIServiceBase.SetTitleBinding(button, TextBlock.TextProperty, textBlock);
            Assert.AreEqual("foo", textBlock.Text);
            button.DataContext = viewModel;
            Assert.AreEqual(viewModel, ViewHelper.GetViewModelFromView(button));
            ViewHelper.InitializeView(button, null, "test", parentViewModel);
            Assert.AreEqual("test", viewModel.With(x => x as ISupportParameter).Parameter);
            Assert.AreEqual(parentViewModel, viewModel.With(x => x as ISupportParentViewModel).ParentViewModel);
            DocumentUIServiceBase.SetTitleBinding(button, TextBlock.TextProperty, textBlock);
            Assert.AreEqual("title", textBlock.Text);
            viewModel.Title = "title2";
            Assert.AreEqual("title2", textBlock.Text);
            var dObject = new DObject();

            Assert.AreEqual(null, ViewHelper.GetViewModelFromView(dObject));
            ViewHelper.InitializeView(button, null, "test", parentViewModel);

            var button2 = new Button();

            button2.DataContext = new DocumentViewModel();
            DocumentUIServiceBase.SetTitleBinding(button2, TextBlock.TextProperty, textBlock);
            Assert.AreEqual("foo2", textBlock.Text);

            ViewModelWithAnotherTitle anotherViewModel = new ViewModelWithAnotherTitle();

            ViewHelper.InitializeView(button, anotherViewModel, "test", null);
            Assert.AreEqual(anotherViewModel, button.DataContext);
            DocumentUIServiceBase.SetTitleBinding(button, TextBlock.TextProperty, textBlock);
            Assert.AreEqual("title", textBlock.Text);
            viewModel.Title = "title3";
            Assert.AreEqual("title", textBlock.Text);
        }