public void TestQ536034()
        {
            object parameter = 1;

            TestViewElement view = new TestViewElement()
            {
                DataContext = null
            };

            BindingOperations.SetBinding(view, ViewModelExtensions.ParameterProperty, new Binding()
            {
                Source = parameter
            });
            TestView viewModel = new TestView();

            view.DataContext = viewModel;
            Assert.AreEqual(1, ((ISupportParameter)viewModel).Parameter);

            viewModel        = new TestView();
            view.DataContext = viewModel;
            Assert.AreEqual(1, ((ISupportParameter)viewModel).Parameter);
            parameter = 2;

            ViewModelExtensions.SetParameter(view, 2);
            Assert.AreEqual(2, ((ISupportParameter)viewModel).Parameter);

            Assert.AreEqual(1, Interaction.GetBehaviors(view).Count);
        }
        public void ResolveViewTest()
        {
            var parentViewModel = new ViewModel();
            DependencyObject fallbackView;
            TextBlock        fallbackElement;

#if !SILVERLIGHT
            fallbackView    = (DependencyObject)ViewHelper.CreateAndInitializeView(null, "TestView", null, "param", parentViewModel);
            fallbackElement = LayoutTreeHelper.GetVisualChildren(fallbackView).OfType <TextBlock>().First();
            Assert.AreEqual("\"TestView\" type not found.", fallbackElement.Text);
            ViewLocator.Default = new ViewLocator(new[] { this.GetType().Assembly });
#endif
            try {
                var testView = ViewHelper.CreateAndInitializeView(null, "TestView", null, "param", parentViewModel);
                Assert.IsInstanceOf(typeof(TestView), testView);
                fallbackView    = (DependencyObject)ViewHelper.CreateAndInitializeView(null, "foo", null, "param", parentViewModel);
                fallbackElement = LayoutTreeHelper.GetVisualChildren(fallbackView).OfType <TextBlock>().First();
                Assert.AreEqual("\"foo\" type not found.", fallbackElement.Text);

                TestViewElement testViewElement = (TestViewElement)ViewHelper.CreateAndInitializeView(null, "TestViewElement", null, "param", parentViewModel);
                ViewModelBase   viewModel       = ViewHelper.GetViewModelFromView(testViewElement).With(x => x as ViewModelBase);
                Assert.AreEqual("param", viewModel.With(x => x as ISupportParameter).Parameter);
                Assert.AreEqual(parentViewModel, viewModel.With(x => x as ISupportParentViewModel).ParentViewModel);

                testViewElement = (TestViewElement)ViewHelper.CreateAndInitializeView(new TestViewLocator(), "foo", null, "param", parentViewModel);
                viewModel       = ViewHelper.GetViewModelFromView(testViewElement).With(x => x as ViewModelBase);
                Assert.AreEqual("param", viewModel.With(x => x as ISupportParameter).Parameter);
                Assert.AreEqual(parentViewModel, viewModel.With(x => x as ISupportParentViewModel).ParentViewModel);

                ViewLocator.Default = new TestViewLocator();
                testViewElement     = (TestViewElement)ViewHelper.CreateAndInitializeView(null, "foo", null, "param", parentViewModel);
                viewModel           = ViewHelper.GetViewModelFromView(testViewElement).With(x => x as ViewModelBase);
                Assert.AreEqual("param", viewModel.With(x => x as ISupportParameter).Parameter);
                Assert.AreEqual(parentViewModel, viewModel.With(x => x as ISupportParentViewModel).ParentViewModel);

                testViewElement = (TestViewElement)ViewHelper.CreateAndInitializeView(null, "foo", "param", "param", parentViewModel);
                Assert.AreEqual("param", testViewElement.DataContext);
            } finally {
                ViewLocator.Default = null;
            }
        }
        public void TestQ536034() {
            object parameter = 1;

            TestViewElement view = new TestViewElement() { DataContext = null };
            BindingOperations.SetBinding(view, ViewModelExtensions.ParameterProperty, new Binding() { Source = parameter });
            TestView viewModel = new TestView();
            view.DataContext = viewModel;
            Assert.AreEqual(1, ((ISupportParameter)viewModel).Parameter);

            viewModel = new TestView();
            view.DataContext = viewModel;
            Assert.AreEqual(1, ((ISupportParameter)viewModel).Parameter);
            parameter = 2;

            ViewModelExtensions.SetParameter(view, 2);
            Assert.AreEqual(2, ((ISupportParameter)viewModel).Parameter);

            Assert.AreEqual(1, Interaction.GetBehaviors(view).Count);
        }