Beispiel #1
0
        public View1(ViewModel1 viewModel)
        {
            InitializeComponent();

            // Set the ViewModel as this View's data context.
            this.DataContext = viewModel;
        }
    public void main()
    {
        var vm1 = new ViewModel1();
        var vm2 = new ViewModel2();

        vm1.ChangeValueAction = new Action(() => { vm2.SomeProperty = String.Empty; });
    }
        public static IViewModel GetViewModel <TViewModel>(INavigation navigationService) where TViewModel : BaseViewModel
        {
            IViewModel vm = null;

            if (typeof(TViewModel) == typeof(MainViewModel))
            {
                vm = new MainViewModel();
            }

            if (typeof(TViewModel) == typeof(ViewModel1))
            {
                vm = new ViewModel1();
            }

            if (typeof(TViewModel) == typeof(ViewModel2))
            {
                vm = new ViewModel2();
            }

            if (vm != null)
            {
                vm.NavigationService = navigationService;
            }

            return(vm);
        }
    public ApplicationViewModel()
    {
        ViewModel1 = new ViewModel1(someParameters);
        ViewModel2 = new ViewModel2(otherParameters);

        ViewModel1.PropertyChanged += VM1_PropertyChanged;
    }
Beispiel #5
0
        public EditFach(int c, int r, Button b, ViewModel1 v)//Tag und uhrzeit
        {
            InitializeComponent();
            ViewModel   = v;
            DataContext = ViewModel;
            List <Fach> l = new List <Fach>();

            l.AddRange(ViewModel.Fächer);
            l.AddRange(ViewModel.Übungen);
            ViewModel.Alle = new System.Collections.ObjectModel.ObservableCollection <Fach>(l);
            col            = c;
            row            = r;
            this.b         = b;
            if (ViewModel.CurrentUser.Stundenplan.ContainsKey(b.Name))
            {
                f = ViewModel.CurrentUser.Stundenplan[b.Name];
            }
            if (f != null)//Setzt die vorhanden Properties
            {
                cbxFächer.SelectedValue = f.Name;
                tbRaum.Text             = f.Raum;
                tbInfo.Text             = f.Info;
                tbLänge.Text            = f.Length.ToString();
            }
            if (tbLänge.Text == null || tbLänge.Text.Equals(""))//
            {
                tbLänge.Text = "2";
            }
        }
Beispiel #6
0
        public void PropertyOwnersMarkedForGC_BindingReleased()
        {
            WeakReference <ViewModel1> wr1 = null;
            WeakReference <ViewModel2> wr2 = null;

            new Action(() =>
            {
                var vm1 = new ViewModel1();
                var vm2 = new ViewModel2();

                wr1 = new WeakReference <ViewModel1>(vm1);
                wr2 = new WeakReference <ViewModel2>(vm2);

                PropertyBinding.Bind(() => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.TwoWay);
            })();

            EnforceGC();

            {
                ViewModel1 vm1;
                Assert.That(wr1.TryGetTarget(out vm1), Is.False);

                ViewModel2 vm2;
                Assert.That(wr2.TryGetTarget(out vm2), Is.False);
            }
        }
 private void Add_OnClick(object sender, RoutedEventArgs e)
 {
     Button btn = (Button)sender;
     var nmb = int.Parse(Regex.Replace(btn.Name, "[^0-9.]", ""));
     object ob = null;
     switch (nmb)
     {
         case 1:
             ob = new ViewModel1(App.EventAgrigator);
             break;
         case 2:
             ob = new ViewModel2(App.EventAgrigator);
             break;
         case 3:
             ob = new ViewModel3(App.EventAgrigator);
             break;
         case 4:
             ob = new ViewModel4(App.EventAgrigator);
             break;
         case 5:
             ob = new ViewModel5(App.EventAgrigator);
             break;
     }
     if (ob != null)
         _objectList.Add(ob);
 }
Beispiel #8
0
        public void Create_ExpressionWithLocalVariable_OwnerAndPropertyCorrectlyDetected()
        {
            var vm = new ViewModel1();

            var prop = BindableProperty.Create(() => vm.PrimaryValue);

            Assert.That(prop.Owner, Is.EqualTo(vm));
            Assert.That(prop.PropertyName, Is.EqualTo("PrimaryValue"));
        }
Beispiel #9
0
        public void Create_ExpressionPath_OwnerAndPropertyCorrectlyDetected()
        {
            var vm = new ViewModel1();

            var prop = BindableProperty.Create(() => vm.Model.ModelValue);

            Assert.That(prop.Owner, Is.EqualTo(vm.Model));
            Assert.That(prop.PropertyName, Is.EqualTo("ModelValue"));
        }
Beispiel #10
0
        public void Create_InstanceAndPropertyName_OwnerAndPropertyCorrectlyDetected()
        {
            var vm = new ViewModel1();

            var prop = BindableProperty.Create(vm, "PrimaryValue");

            Assert.That(prop.Owner, Is.EqualTo(vm));
            Assert.That(prop.PropertyName, Is.EqualTo("PrimaryValue"));
        }
Beispiel #11
0
 public MainViewModel()
 {
     Add1Command = new Command(() => AddItems(ViewModel1.Items));
     Add2Command = new Command(() =>
     {
         ViewModel1.ReloadData();
         AddItems(ViewModel1.Items);
     });
 }
Beispiel #12
0
        public void OneWayToSourceBinding_ChangesOnTargetNotSyncedtoSource()
        {
            var vm1 = new ViewModel1();
            var vm2 = new ViewModel2();

            PropertyBinding.Bind(() => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.OneWayToSource);

            vm1.PrimaryValue = 42;
            Assert.That(vm2.SecondaryValue, Is.Not.EqualTo(42));
        }
Beispiel #13
0
		private ViewModel1 CreateViewModelAndAssignProperty()
		{
			var viewModel = new ViewModel1();

			viewModel.PropertyChanging += (s, e) => CheckPropertyName(e.PropertyName, ExpectedPropertyName, 0);

			viewModel.PropertyChanged += (s, e) => CheckPropertyName(e.PropertyName, ExpectedPropertyName, 1);

			return viewModel;
		}
Beispiel #14
0
        private ViewModel1 CreateViewModelAndAssignProperty()
        {
            var viewModel = new ViewModel1();

            viewModel.PropertyChanging += (s, e) => CheckPropertyName(e.PropertyName, ExpectedPropertyName, 0);

            viewModel.PropertyChanged += (s, e) => CheckPropertyName(e.PropertyName, ExpectedPropertyName, 1);

            return(viewModel);
        }
Beispiel #15
0
        InfoManager infoManager    = new InfoManager(); //调用BLL层
                                                        //GET: Info

        public ActionResult Index(int page = 1)
        {
            var info1 = infoManager.SelectInfo1();

            var index = new ViewModel1()
            {
                INFO = info1.ToPagedList(page, 6),
            };

            return(View(index));
        }
Beispiel #16
0
        public ActionResult Edit(int Id)
        {
            var customer  = _context.Customer.SingleOrDefault(c => c.Id == Id);
            var viewmodel = new ViewModel1
            {
                Customer   = customer,
                MemberShip = _context.MemberShip.ToList()
            };

            return(View("New", viewmodel));
        }
Beispiel #17
0
        public ActionResult New()

        {
            var membership = _context.MemberShip.ToList();
            var viewmodel  = new ViewModel1
            {
                MemberShip = membership
            };

            return(View(viewmodel));
        }
        public void PropertyChanged01()
        {
            var vm   = new ViewModel1();
            var node = this.Observe(vm, x => x.FirstName);

            node.GetWeakHandlers().Should().HaveCount(1);
            changeCount.Should().Be(0);

            vm.FirstName = "MyFirstName";

            changeCount.Should().Be(1);
        }
Beispiel #19
0
        public void TwoWayBinding_ChangesOnEitherEndSyncedToTheOtherOne()
        {
            var vm1 = new ViewModel1();
            var vm2 = new ViewModel2();

            PropertyBinding.Bind(() => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.TwoWay);

            vm1.PrimaryValue = 42;
            Assert.That(vm2.SecondaryValue, Is.EqualTo(42));

            vm2.SecondaryValue = 24;
            Assert.That(vm1.PrimaryValue, Is.EqualTo(24));
        }
Beispiel #20
0
     public MainWindowViewModel()
     {
     ViewModel1 = new ViewModel1();
     ViewModel2 = new ViewModel2();
     ViewModel3 = new ViewModel3();
     ViewModel1.PropertyChanged += (s,e) => 
     {
         if(e.PropertyName == "IsBusy") 
         { 
           // set the MainWindowViewModel.IsBusy property here
         }
     }
     //IsBusy = true; - its working
 }
        public void GetViewModel_IfDataContextIsNull_ThrowsArgumentNullException()
        {
            // Arrange

            ViewModel1 target = null;

            // Act

            ViewModel1 Call() => target.GetViewModel <ViewModel1>();

            // Assert

            Assert.ThrowsException <ArgumentNullException>(Call);
        }
        public void GetViewModel_IfDataContextHasCorrectType_ReturnsStronglyTypedViewModel()
        {
            // Arrange

            var target = new ViewModel1();

            // Act

            var result = target.GetViewModel <ViewModel1>();

            // Assert

            Assert.AreSame(target, result);
        }
Beispiel #23
0
        public void PropertyOwnersStillAlive_BindingsSurvivesGC()
        {
            var vm1 = new ViewModel1();
            var vm2 = new ViewModel2();

            PropertyBinding.Bind(() => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.TwoWay);

            EnforceGC();

            {
                // lets see whether binding still works
                vm1.PrimaryValue = 42;
                Assert.That(vm2.SecondaryValue, Is.EqualTo(42));
            }
        }
Beispiel #24
0
        public void Unbind_RemovesBindingAgain()
        {
            var vm1 = new ViewModel1();
            var vm2 = new ViewModel2();

            var id = PropertyBinding.Bind(() => vm1.PrimaryValue, () => vm2.SecondaryValue);

            vm2.SecondaryValue = 42;
            Assert.That(vm1.PrimaryValue, Is.EqualTo(42));

            PropertyBinding.Unbind(id);

            vm2.SecondaryValue = 2525;
            Assert.That(vm1.PrimaryValue, Is.EqualTo(42));
        }
        public void GetViewModel_IfDataContextHasIncorrectType_ThrowsInvalidOperationException()
        {
            // Arrange

            var target = new ViewModel1();

            // Act

            ViewModel2 Call() => target.GetViewModel <ViewModel2>();

            // Assert

            var exception = Assert.ThrowsException <InvalidOperationException>(Call);

            Assert.AreEqual("Unexpected type of DataContext: Expected CodeFuller.Library.Wpf.UnitTests.Extensions.ObjectExtensionsTests+ViewModel2, actual is CodeFuller.Library.Wpf.UnitTests.Extensions.ObjectExtensionsTests+ViewModel1", exception.Message);
        }
        public void PropertyChanged04()
        {
            var vm = new ViewModel1();

            vm.ViewModel2      = new ViewModel2();
            vm.ViewModel2.Name = "hello";

            var node = this.Observe(vm, x => x.FirstName + x.LastName + x.ViewModel2.Name);

            node.GetWeakHandlers().Should().HaveCount(2);
            changeCount.Should().Be(0);

            vm.ViewModel2.Name = "Name";

            changeCount.Should().Be(1);
        }
Beispiel #27
0
 public MainViewModel()
 {
     Add1Command = new Command(() => AddItems(ViewModel1.Items));
     Add2Command = new Command(() => AddItems(ViewModel2.Items));
     Add3Command = new Command(() => AddItems(ViewModel3.Items));
     Add4Command = new Command(() =>
     {
         ViewModel1.ReloadData();
         ViewModel2.ReloadData();
         ViewModel3.ReloadData();
     });
     Add5Command = new Command(() =>
     {
         ViewModel1.ChangeListViewVisability();
         ViewModel2.ChangeListViewVisability();
         ViewModel3.ReloadData();
     });
 }
        public void PropertyChanged06()
        {
            var vm = new ViewModel1();

            vm.ViewModel2          = new ViewModel2();
            vm.ViewModel2.Name     = "hello";
            vm.NotViewModel1       = new NotViewModel1();
            vm.NotViewModel1.Index = 4;

            var node = this.Observe(vm, x => x.FirstName + x.ViewModel2.Name + x.NotViewModel1.Index);

            node.GetWeakHandlers().Should().HaveCount(2);
            changeCount.Should().Be(0);

            vm.NotViewModel1.Index = 5;

            changeCount.Should().Be(0);
        }
        public void PropertyChanged03()
        {
            var vm   = new ViewModel1();
            var node = this.Observe(vm, x => x.FirstName + x.LastName + x.ViewModel2.Name);

            // Only 1 because ViewModel2 is null;
            node.GetWeakHandlers().Should().HaveCount(1);
            changeCount.Should().Be(0);

            vm.ViewModel2 = new ViewModel2();

            // ViewModel2 changed and its not null, so now there are 2 weak handlers.
            node.GetWeakHandlers().Should().HaveCount(2);

            vm.ViewModel2.Name = "Name";

            changeCount.Should().Be(2);
        }
        public void PropertyChanged02()
        {
            var vm   = new ViewModel1();
            var node = this.Observe(vm, x => x.FirstName + x.LastName);

            node.GetWeakHandlers().Should().HaveCount(1);
            changeCount.Should().Be(0);

            // Was null, so +1;
            vm.FirstName = "MyFirstName";

            // Was null, so +1;
            vm.LastName = "MyLastName";

            // Same
            vm.FirstName = "MyFirstName";

            // Was MyLastName, so +1;
            vm.LastName = "MyLastName2";

            changeCount.Should().Be(3);
        }
Beispiel #31
0
        static void Main(string[] args)
        {
            var app = new Application();

            if (args.Length > 1)
            {
                MessageBox.Show("SimpleOutline only accepts zero or one arguments.",
                                "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            var viewModel = new ViewModel1();

            if (args.Length == 1)
            {
                try
                {
                    viewModel.LoadDocument(args[0]);
                }
                catch (Exception)
                {
                    var errorMessage = $"SimpleOutline could not load the file specified: {args[0]}";

                    MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }
            }
            else
            {
                viewModel.LoadNewDocument();
            }

            var mainWindow = new DocumentWindow();

            mainWindow.DataContext = viewModel;
            viewModel.View         = mainWindow;

            app.Run(mainWindow);
        }
 public ViewModel3 JsonAndHtml(ViewModel1 m)
 {
     return null;
 }
 public ViewModel2 XmlOnly(ViewModel1 m)
 {
     return null;
 }
 public ViewModel3 XmlAndJson(ViewModel1 m)
 {
     return null;
 }
 public ViewModel3 XmlAndHtml(ViewModel1 m)
 {
     return null;
 }
 public ViewModel3 JsonOnly(ViewModel1 m)
 {
     return null;
 }
 public ViewModel1 All(ViewModel1 m)
 {
     return null;
 }