A strange question #398
-
Model: public class Tester
{
public float Tester_PA { get; set; }
} ViewModel: public Tester Tester { get; set; }
public void DoTest()
{
Tester = new Tester
{
Tester_PA = 1.2f
};
Tester.Tester_PA = 2.3f;
} View: <TextBlock Text="{Binding Path=Tester.Tester_PA }" /> Why does it show 1.2 instead of 2.3? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
More details please. Cam you post the full classes, not just snippets? How and when is DoTest called? |
Beta Was this translation helpful? Give feedback.
-
That's all the code. |
Beta Was this translation helpful? Give feedback.
-
Right, you're using PropertyChanged.Fody to insert INotifyPropertyChanged events. PropertyChanged.Fody works on classes which implement INotifyPropertyChanged, and it rewrites properties to automatically raise the PropertyChanged event whenever the property is assigned. Your MainViewModel implements INotifyPropertyChanged (it inherits from Screen, which implements that interface). So, PropertyChanged.Fody gets to work and rewrites the The Your |
Beta Was this translation helpful? Give feedback.
-
public class Tester: INotifyPropertyChanged That's working fine. |
Beta Was this translation helpful? Give feedback.
Right, you're using PropertyChanged.Fody to insert INotifyPropertyChanged events.
PropertyChanged.Fody works on classes which implement INotifyPropertyChanged, and it rewrites properties to automatically raise the PropertyChanged event whenever the property is assigned.
Your MainViewModel implements INotifyPropertyChanged (it inherits from Screen, which implements that interface). So, PropertyChanged.Fody gets to work and rewrites the
Tester
property so that when you assign to it, it raises the PropertyChanged event.The
Binding
in your view then listens for that event, and refreshes itself when it's raised. So when you assign toTester
, the view gets a notification that the property has …