我的主页上的文本框绑定到我的usercontrol上的字符串属性,这是一个弹出窗口。使用字符串属性的初始值正确显示文本框值,但是对属性的更改不会更新显示的值。如何让该字段观察属性的变化?
**MainPage XAML:**
<TextBox x:Name="textBlockStartDate" Text="{Binding selectedDateString,Mode=OneWay}" DataContext="{Binding ElementName=MyUserControl}"/>
**MyUserControl.cs**
private DateTime selectedDate;
public string selectedDateString {get{return selectedDate.Date.ToString("dd.MM.yyyy");}}
public DatePicker(){
this.InitializeComponent();
selectedDate = DateTime.Today;
}
// Update the value when a button is pressed
private void DayButton_Clicked(object sender, RoutedEventArgs e){
Button button = (Button)sender;
selectedDate = (DateTime)button.Tag;
}