Monday 15 July 2013

c# - Notify viewmodel that model has changed (from combobox) -


I have a model that implements INotifyPropertyChanged through the INMOMET class. There is another model in the form of element inside it.

  class SIDPoslJavnaUstanova: betamodel {Private int? _sid_posl_javna_ustanova_id; ... personal decimals? _udaljenost; Private SIDJavnaUstanova _sid_javna_ustanova; Public SIDJavnaUstanova SidJavnaUstanova {Get {return _sid_javna_ustanova; } Set {if (_sid_javna_ustanova! = Value) {_sid_javna_ustanova = value; If (_sid_javna_ustanova! = Null) {_sid_javna_ustanova_id = _sid_javna_ustanova.SidJavnaUstanovaId; } And {_sid_javna_ustanova_id = null; } RaisePropertyChanged ("SidJavnaUstanova"); }}}   

I have a visual model that is a collectable collection of this model object.

  Class BaseViewModel & lt; T & gt; : Observe Objects {Private Observable Collection & lt; T & gt; _Legment = new inspection qualification & lt; T & gt; (); Public supervision qualification & lt; T & gt; Element ... class SIDPoslJavnaUstanovaViewModel: baseview model & lt; SIDPoslJavnaUstanova & gt; {}}   

And finally, the mainviewmodel is bound to that scene:

  class MainViewModel: BaseViewModel & LT; Store & gt; {Private SIDJovanAustownVoiceModel_SidzhanAustanovavyModel; Private SIDJAVANA Yustan_SidjawanUstonova; Public SIDPoslJavnaUstanovaViewModel SidPoslJavnaUstanovaViewModel {receive {back _sidPoslJavnaUstanovaViewModel; } Set {if (_sidPoslJavnaUstanovaViewModel! = Value) {_sidPoslJavnaUstanovaViewModel = value; RaisePropertyChanged ("SidPoslJavnaUstanovaViewModel"); }}} Public SIDJavnaUstanovaViewModel SidJavnaUstanovaViewModel {get {_sidJavnaUstanovaViewModel; } Set {if (_sidJavnaUstanovaViewModel! = Value) {_sidJavnaUstanovaViewModel = value; RaisePropertyChanged ("SidJavnaUstanovaViewModel"); }}}   

SidJavnaUstanova is only told to populate, and when bound object is bound to object.

I told in datagrid, that is the multiple lines. Element is Sidwannushanova, and dropdown Sidvawanustanovavy Model's dropdown SIDJAVNAUSTANOVAVIEWMODEL.ELEMENTS (you can not show the image a sufficient reputation)

   & Lt; / Src: BaseWindow.Resources & gt; & Lt; DataGrid.Columns & gt; & Lt; DataGridTemplateColumn Width = "140" header = "{StaticResource name}" & gt; & Lt; DataGridTemplateColumn.CellTemplate & gt; & Lt; DataTemplate & gt; & Lt; ComboBox ItemsSource = "{Binding Path = SidJavnaUstanovaViewModel.Elements, Source = {StaticResource StoreViewM}}" SelectedItem = "{Binding Path = SidJavnaUstanova, UpdateSourceTrigger = PropertyChanged, mode = TwoWay}" DisplayMemberPath = "Naziv" SelectedValue = "{Binding Path = Sidjewen Eustenva, Mode = Two) "& ​​gt; & Lt; / ComboBox & gt; ...   

When Konbboks doing some turns, until then working properly, has been changed element Saidijvn Ustanova element Saideepossl Jwana Ustonwa, and I in the model property I can catch it. But what I should be, is to capture the change of SidJavnaUstanova in viewmodel, so I can apply check-out, then duplicate of sidjavnaustanova in sidposljavnaustanovaviewmodel.elements there. I do not know how to do this.

  SIDPoslJavnaUstanova.Elements ??? SIDJavnaUstanova   

I can not do this because the element is an observation archive. Maybe this is a bad model, please give some suggestion or help with the current code.

i) i.e. SIDPoslJavnaUstanova in your case) elements in your collection ( specify as, SelectedItem b) Tie SelectedItem source property of the same type. I think this should work:

  & lt; ComboBox ItemsSource = "{Binding Path = SidJavnaUstanovaViewModelkElements, Source = {StaticResource StoreViewM}}" SelectedItem = "{Binding Path = SelectedModel, UpdateSourceTrigger = converted property, mode = Dova, Source = {static resource store ViewM}}" DisplayMemberPath = "Naziv" & gt; & Lt; / ComboBox & gt; ......................................... // Main viewModel public SIDPoslJavnaUstanova selected model { Received {Returns selected from the model; } Set {if (_selectedModel! = Value) {_selectedModel = value; RaisePropertyChanged ("SelectedModel"); }}}   

And yes, it is a terrible design.

No comments:

Post a Comment