c# - Notify Collection changed across viewmodels -


I have a scenario in which the main control in the window is in the window, I through it switch the user control of the special view And I have a visual-model respectively

One of my user controls has user control. Both have a visual-model

  & lt; UserControl DataContext = "ViewModel1" & gt; & Lt; Grid & gt; & Lt; ListView ItemsSource = "{Binding time slot collection}" & lt ;! - This collection is in ViewModel 1 - & gt; "UserControl DataContext =" ViewModel2 "& gt; & lt; Data Grid x: Name =" Data Grid "CanUserAddRows =" True "ItemsSource =" {TimeSlotCollection, Mode = TwoWay, UpdateSourceTrigger = PropertyChanged Binding} "/>   

I want to notify Visual Model 1 collection when View-Modal2 collection changes

MyViewModel 1

  Private Observe Collection & Lieutenant; Attendance SlotsModel & gt; _timeslotCollection; Public Supervision Set & gt; attendance slot mode & gt; timeslot collection {return_timeslotCollection;} set {set (timeslotclip property name, refresh times lot collection, value);}} public construction string emplooselinkproperty name = "employee"; private observation collection & lieutenant amplimodel & gt; Euphrable Counting & Lieutenant Employee MODEL & gt; Set up employee {get {return_employees;} {employee (employee Security selection Krenprotitinam, Refrimeplo Yees, value); }} Public const string IsBusyPropertyName = "IsBusy"; Private bool _isBusy = false; Public bool IsBusy {get {return _isBusy; } Set {set (IsBusyPropertyName, referee _isBusy, value); }}   

MyViewModel 2

  public constant string attendanceTimeSlotCollectionPropertyName = "TimeSlotCollection"; Private observable collection & lieutenant; Attendance slot mode & gt; _timeSlotCollection = Null; Public supervision qualification; Attendance slot mode & gt; TimeSlot Collection {Return_time slot collection; } Set {set (attendance time slot clip property name, ref_time slot collection, value); }} /// Do I try Public Zero AddNewTimeSlot (AttendanceTimeSlotModel slot) {_designdataService.InsertTimeSlot (slot); Var Vm = Simple Ioc.Default.GetInstance & lt; ViewModels.AssignTimeSlotViewModel & gt; (); RaisePropertyChanged (Vm.TimeSlotCollection); }   

When I update my collection within View-Modal 2, I am trying to get it, I want to inform in Vision-Model 1.

While using MVVM, I use only one visual model in one view Want to If you take your inner UserControl to be a part of your original UserControl , you will only need a visual model to rearrange your code like this: < / P>

  & lt; UserControl DataContext = "ViewModel1" & gt; & Lt; Grid & gt; & Lt; ListView ItemsSource = "{Binding Timeline: Slot Collection}" /> & Lt; UserControl DataContext = "{Binding time slot collection}" & gt; ... & lt ;! - Then inside internal control - & gt; & Lt; DataGrid x: name = "datagrid" itemsource = "{binding}" ... ... & gt; ... & lt; / UserControl & gt; & Lt; / Grid & gt; & Lt; / UserControl & gt;   

In this way, you will have to manage a collection in a visual model and your problems will disappear more .

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -