1

我的主页上的文本框绑定到我的用户控件上的一个字符串属性,这是一个弹出窗口。文本框值与字符串属性的初始值一起正确显示,但是对属性的更改不会更新显示的值。我怎样才能让这个字段观察属性的变化?

**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;
}  
4

0 回答 0