Ejemplo n.º 1
0
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            object viewModel = null;

            ViewModelLocationProvider.AutoWireViewModelChanged(View, (v, vm) => viewModel = vm);
            return(viewModel);
        }
Ejemplo n.º 2
0
        public MRPMatrix()
        {
            InitializeComponent();
            ViewModelLocationProvider.AutoWireViewModelChanged(this);

            this.rptName.Load += RptName_Load;
        }
Ejemplo n.º 3
0
 private static void OnAutoWireViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if ((bool)e.NewValue)
     {
         ViewModelLocationProvider.AutoWireViewModelChanged(d, Bind);
     }
 }
Ejemplo n.º 4
0
 private static void AutoWireViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (!DesignerProperties.GetIsInDesignMode(d))
     {
         if ((bool)e.NewValue)
         {
             ViewModelLocationProvider.AutoWireViewModelChanged(d, Bind);
         }
     }
 }
        public void ShouldLocateViewModelWithDefaultSettings()
        {
            ResetViewModelLocationProvider();

            Mock view = new Mock();

            Assert.IsNull(view.DataContext);

            ViewModelLocationProvider.AutoWireViewModelChanged(view);
            Assert.IsNotNull(view.DataContext);
            Assert.IsInstanceOfType(view.DataContext, typeof(MockViewModel));
        }
        public void ShouldFailWhenCustomDefaultViewTypeToViewModelTypeResolverIsNull()
        {
            ResetViewModelLocationProvider();
            var view = new Mock();

            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(viewType => null);
            ViewModelLocationProvider.AutoWireViewModelChanged(view, (v, vm) =>
            {
                Assert.NotNull(v);
                Assert.NotNull(vm);
            });
        }
        public void ShouldLocateViewModelWithDefaultSettingsForViewsThatEndWithView()
        {
            ResetViewModelLocationProvider();

            var view = new MockView();

            ViewModelLocationProvider.AutoWireViewModelChanged(view, (v, vm) =>
            {
                Assert.NotNull(v);
                Assert.NotNull(vm);
                Assert.IsType <MockViewModel>(vm);
            });
        }
        public void ShouldLocateViewModelWithDefaultSettings()
        {
            ResetViewModelLocationProvider();

            var view = new Mock();

            ViewModelLocationProvider.AutoWireViewModelChanged(view, (v, vm) =>
            {
                Assert.IsNotNull(v);
                Assert.IsNotNull(vm);
                Assert.IsInstanceOfType(vm, typeof(MockViewModel));
            });
        }
Ejemplo n.º 9
0
        static void AutoWireViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
#if !HAS_WINUI
            if (DesignerProperties.GetIsInDesignMode(d))
            {
                return;
            }
#endif
            if ((bool)e.NewValue)
            {
                ViewModelLocationProvider.AutoWireViewModelChanged(d, Bind);
            }
        }
        public void ShouldUseCustomDefaultViewTypeToViewModelTypeResolverWhenSet()
        {
            ResetViewModelLocationProvider();

            Mock view = new Mock();

            Assert.IsNull(view.DataContext);

            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(viewType => typeof(ViewModelLocationProviderFixture));

            ViewModelLocationProvider.AutoWireViewModelChanged(view);
            Assert.IsNotNull(view.DataContext);
            Assert.IsInstanceOfType(view.DataContext, typeof(ViewModelLocationProviderFixture));
        }
        public void ShouldUseCustomTypeWhenSet_Generic()
        {
            ResetViewModelLocationProvider();

            var view = new Mock();

            ViewModelLocationProvider.Register <Mock, ViewModelLocationProviderFixture>();

            ViewModelLocationProvider.AutoWireViewModelChanged(view, (v, vm) =>
            {
                Assert.NotNull(v);
                Assert.NotNull(vm);
                Assert.IsType <ViewModelLocationProviderFixture>(vm);
            });
        }
        public void ShouldUseCustomDefaultViewTypeToViewModelTypeResolverWhenSet()
        {
            ResetViewModelLocationProvider();

            var view = new Mock();

            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(viewType => typeof(ViewModelLocationProviderFixture));

            ViewModelLocationProvider.AutoWireViewModelChanged(view, (v, vm) =>
            {
                Assert.NotNull(v);
                Assert.NotNull(vm);
                Assert.IsType <ViewModelLocationProviderFixture>(vm);
            });
        }
        public void ShouldUseCustomTypeWhenSet()
        {
            ResetViewModelLocationProvider();

            var view = new Mock();

            ViewModelLocationProvider.Register(view.GetType().ToString(), typeof(ViewModelLocationProviderFixture));

            ViewModelLocationProvider.AutoWireViewModelChanged(view, (v, vm) =>
            {
                Assert.NotNull(v);
                Assert.NotNull(vm);
                Assert.IsType <ViewModelLocationProviderFixture>(vm);
            });
        }
        public void ShouldUseCustomFactoryWhenSet()
        {
            ResetViewModelLocationProvider();

            Mock view = new Mock();

            Assert.IsNull(view.DataContext);

            string viewModel = "Test String";

            ViewModelLocationProvider.Register(view.GetType().ToString(), () => viewModel);

            ViewModelLocationProvider.AutoWireViewModelChanged(view);
            Assert.IsNotNull(view.DataContext);
            Assert.ReferenceEquals(view.DataContext, viewModel);
        }
        public void ShouldUseCustomDefaultViewModelFactoryWhenSet()
        {
            ResetViewModelLocationProvider();

            Mock view = new Mock();

            Assert.IsNull(view.DataContext);

            object mockObject = new object();

            ViewModelLocationProvider.SetDefaultViewModelFactory(viewType => mockObject);

            ViewModelLocationProvider.AutoWireViewModelChanged(view);
            Assert.IsNotNull(view.DataContext);
            Assert.ReferenceEquals(view.DataContext, mockObject);
        }
Ejemplo n.º 16
0
        public void ConfigureViewModelLocatorShouldUserServiceLocatorAsResolver()
        {
            var bootstrapper = new DefaultBootstrapper();

            CreateAndConfigureServiceLocatorForViewModelLocator();

            bootstrapper.CallConfigureViewModelLocator();

            var view = new MockView();

            ViewModelLocationProvider.AutoWireViewModelChanged(view, (v, vm) =>
            {
                Assert.IsNotNull(v);
                Assert.IsNotNull(vm);
                Assert.IsInstanceOfType(vm, typeof(MockViewModel));
            });
        }
        public void ShouldUseCustomFactoryWhenSet()
        {
            ResetViewModelLocationProvider();

            var view = new Mock();

            string viewModel = "Test String";

            ViewModelLocationProvider.Register(view.GetType().ToString(), () => viewModel);

            ViewModelLocationProvider.AutoWireViewModelChanged(view, (v, vm) =>
            {
                Assert.NotNull(v);
                Assert.NotNull(vm);
                Assert.Equal(viewModel, vm);
            });
        }
        public void ShouldUseCustomDefaultViewModelFactoryWhenSet()
        {
            ResetViewModelLocationProvider();

            var view = new Mock();

            object mockObject = new object();

            ViewModelLocationProvider.SetDefaultViewModelFactory(viewType => mockObject);

            ViewModelLocationProvider.AutoWireViewModelChanged(view, (v, vm) =>
            {
                Assert.NotNull(v);
                Assert.NotNull(vm);
                Assert.IsType(mockObject.GetType(), vm);
            });
        }
Ejemplo n.º 19
0
 public Welcome()
 {
     InitializeComponent();
     ViewModelLocationProvider.AutoWireViewModelChanged(this);
 }
Ejemplo n.º 20
0
 public BillOfMaterial()
 {
     InitializeComponent();
     ViewModelLocationProvider.AutoWireViewModelChanged(this);
 }
Ejemplo n.º 21
0
 public MainWindow()
 {
     InitializeComponent();
     ViewModelLocationProvider.AutoWireViewModelChanged(this);
 }
Ejemplo n.º 22
0
 public ProductStructure()
 {
     InitializeComponent();
     ViewModelLocationProvider.AutoWireViewModelChanged(this);
 }