私はテキストボックスに必要なTimeSpan値に取り組んでいます。入力コンテンツは検証する必要があり、いくつかの異なる形式である可能性があります(たとえば、1300は13:00を意味します)。私はそれをviewmodelでチェックして変換するためにいくつかの作業を行います。しかし、その後、テキストボックスのテキストを更新するにはどうすればよいですか?
<TextBox Text="{Binding Path= OpenHourFromText, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}" ></TextBox>
OpenHourFromValueは、検証とデータバインディングに使用した文字列プロパティです
public class MainPageViewModel : NotificationObject{
public string OpenHourFromText
{
get
{
//OpenHourFrom is a TimeSpan property that contain the value
if (OpenHourFrom != null)
{
return GetOpeningHourText(OpenHourFrom); //fomat the time
}
else
{
return "";
}
}
set
{
//do validation and convert here. 1300 will be changed to 13:00 TimeSpan type
OpenHourFrom = ConvertToTimeSpan(value);
RaisePropertyChanged("OpenHourFromText");
}
}
public TimeSpan OpenHourFrom { get; set; }
}
ビューモデルはMicrosoft.Practices.Prism.ViewModel.NotificationObjectから継承されます
テキストボックスに1300を入力すると、OpenHourFromが更新されます。ただし、テキストボックスのテキストは13:00に変更されません。なぜ?助けてください、多くのthx。