Win8 App:绑定到UserControl属性

时间:2012-12-02 12:57:58

标签: binding user-controls

我的主页上的文本框绑定到我的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;
}  

0 个答案:

没有答案