i need to change the format of a textbox in silverlight. the data is binding via MVVM.
for ex there is a int property, i add 1 to the value in setter and call OnPropertyChanged. I suppose if i input 1 in the textbox and lost foucs, the text will change to 2. But actully the text is not changed, still 1.
<TextBox Name="txtTime" Text="{Binding PersonID, Mode=TwoWay}" />
private int _personID;
public int PersonID
{
get
{
return _personID;
}
set
{
_personID = value + 1;
OnPropertyChanged("PersonID");
}
}
is there anything wrong? what’s the right way to do this?
many thanks
When TextBox is setting some value it won’t call get.The solution to this can be like replacing OnPropertyChanged(“PersonID”) with Dispatcher.BeginInvoke(() => OnPropertyChanged(“PersonID”));It will delay firing that event.
Hope this answers your question