Sunday 15 August 2010

wpf - How to notify viewmodel collection that property on model class has changed -


I have a class with a Bullyan property that is known as IsChecked . A collection of this scene is present in my view-model. I have built a Data Grid in this collection in my opinion. The checkbox changes in the view, so I need to call a method in my view-model I have implemented INotifyPropertyChanged on the class and when I check the box, firing happens, but I Do not know how to call the method in my view model.

Here's the square of my model ...

  Public class account company: INotifyPropertyChanged {public string name {get; Set; } Receive the public decimal amount { Set; } Private Bull _'s check; Public Bull Eyescacked {Receive {Return _ Check; } Set {_is checked = value; NotifyPropertyChanged ("IsChecked"); }} Public Bull Enabled {get; Set; } Private Event PropertyChangedEventHandler PropertyChanged; Public Zero NotifyPropertyChanged (String Info) {if (PropertyChanged! = Null) {PropertyChanged (New, PropertyChangedEventArgs (info)); }}}   

My Vimeoddal has a collection ...

  Private Observale Collection & lt; Account Commonat & gt; _accountComponents; Private string _accountStatus; Public Supervision Collection & lt; Accountcompany & gt; Accountcompanies {return_accountComponents; } Set {_accountComponents = value; NotifyPropertyChanged ("AccountComponents"); CalculateComponentTotal (); }}   

My view is in this view ...

  DataGrade itemsource = "{binding accountcompany}" auto generated column = "wrong" margin = "5" & gt; & Lt; DataGrid.Columns & gt; & Lt; DataGridTemplateColumn & gt; & Lt; DataGridTemplateColumn.CellTemplate & gt; & Lt; DataTemplate & gt; & Lt; Grid & gt; & Lt; Check box IsChecked = "{Binding IsChecked, UpdateSourceTrigger = PropertyChanged, Mode = TwoWay}" IsEnabled = "{Binding Enabled}" /> & Lt; / Grid & gt; & Lt; / DataTemplate & gt; & Lt; /DataGridTemplateColumn.CellTemplate> & Lt; / DataGridTemplateColumn & gt; & Lt; DataGridTextColumn binding = "{binding name}" header = "component" width = "*" isReadOnly = "true" ElementStyle = "{DynamicResource TextBlock-Sketch}" /> & Lt; DataGridTextColumn binding = "{binding amount, string formatting = {} {0: c}}" israelically = "true" header = "charging" elementstyle = "{dynamic resource text block-sketch}" & gt; & Lt; DataGridTextColumn.CellStyle & gt; & Lt; Style & gt; & Lt; Setter Property = "Text Block. Textile" Value = "Right" /> & Lt; / Style & gt; & Lt; /DataGridTextColumn.CellStyle> & Lt; / DataGridTextColumn & gt; & Lt; /DataGrid.Columns> & Lt; / Data grid & gt;    

Since account company implements INPC you can see assets in your VM.

Say in your VM constructor:

  accountcommand = new Observe Collection & lt; Accountcompany & gt; (); Account Components. Collection Change + = Account Component OnClub Bank changed; ... Private Zero AccountConfonTonconnected account (Object Sender, Notification ChangedEventErgus Elgies) {If (Elggs NewNews! = Null & amp; AGR.New Eatms.Count! = 0) Foreign Currency Account (Accountant Account) in New Eights. Property Change + = AccountOnProperty changed; If (Logic only! = Null & amp; awkward. Late calculation! = 0) foreach (Accounting accounts in account.OldItems) account.PropertyChanged - = AccountOnPropertyChanged; } Private Zero AccountOnProperty Change (Object Sender, Property Changed Event ARGs) {if (args.PropertyName == "IshankiCaked") // Get your VM Function here}   

It should be so.

No comments:

Post a Comment