开发者

WPF Databound Property Loosing value

Hi I have a viewmodel where i can tr开发者_如何学运维ack the value of a certain item in the constructor. I am opening a dialog window using the MVVM model.

example

private int _myField;
public ClassName(int MyProperty)
{
  _myField = MyProperty;
}

public int MyIntProperty
{
   get{ return _myField;}
   set { _myField = value;}
} 

this is all perfect obviously. but as soon as the window opens the value in the viewmodel changes. lets say the _myField goes from 1 to 8 with out any interaction. i've walked through the code and there are no other interactions with the field.

also not in the code sample is the bound property.

anyone every came accross this before. it has me stumped.

Edit: included missing property from example


You should either:

1) Implement INotifyPropertyChanged on ClassName. This will allow you to raise the PropertyChanged event when you change MyIntProperty. WPF will listen to this event and update the UI accordingly.

or

2) Make ClassName inherit from DependancyObject and MyIntProperty a dependency property. This will take care of everything for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜