我希望用戶能夠輸入310312並且自動將日期選擇器的文本屬性更新爲31/03/12;我已經將日期選擇器綁定到視圖模型'日期'屬性如下。Wpf DatePicker文本在綁定源更新後未更新
使用WPF4.0,綁定現在自動執行一組get(不需要INotifyPropertyChanged);這發生在下面的代碼中,但雖然'get'日期字段值是正確的'31/03/12',但datepicker文本屬性未更新,並且保持在310312(NB UpdateSourceTrigger = PropertyChanged)。
文本框屬性確實變化(例如在設置代碼,未顯示,轉換爲大寫)
我真的很感激一些指針,因爲這是爲什麼。
<Grid>
<DatePicker Text="{Binding Path=Date,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Height="25" HorizontalAlignment="Left" Name="datePicker1"/>
<TextBox Text="{Binding Path=State,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="23" HorizontalAlignment="Left" Name="textBox1" />
</Grid>
private string date;
public string Date
{
get
{
return date;
}
set
{
if (value != null)
{
Regex abbreviatedDateFormat = new Regex(@"\A\d{6}\Z");
if (abbreviatedDateFormat.IsMatch(value))
{
value = value.Insert(2, "/");
value = value.Insert(5, "/");
}
}
date = value;
}
}
我想達到同樣的效果。你有沒有找到解決方案? – mosquito87 2015-02-23 17:40:14