简单地尝试做的是,当用户点击按钮时,其内容应根据编码而改变。这是代码。我已尝试过两种方式,代码隐藏方式和XAML绑定方式。但它不起作用。
<Button x:Name="Header" Content="{Binding listHeader}" Click="HeaderClick"/>
private string listHeader;
public string ListHeader
{
get { return listHeader; }
set
{
listHeader = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("listHeader"));
}
}
}
public Calendar()
{
this.selectedDate = DateTime.Now;
this.ListHeader = selectedDate.ToString("MMMM");
}
private void HeaderClick(object sender, RoutedEventArgs e)
{
switch (StateOfList)
{
case StatesOfList.ListOfDates:
{
this.listHeader = selectedDate.Year.ToString();
this.StateOfList = StatesOfList.ListOfMonths;
}
break;
case StatesOfList.ListOfMonths:
{
this.FillList(ListDataTypes.Years);
this.StateOfList = StatesOfList.ListOfYears;
}
break;
case StatesOfList.ListOfYears:
{
}
break;
}
}
答案 0 :(得分:1)
您最好使用属性名称(ListHeader)绑定内容,而不是变量名称(listHeader)。因此,请在代码中更改这两行。
<Button x:Name="Header" Content="{Binding ListHeader}" Click="HeaderClick"/>
和
PropertyChanged(this, new PropertyChangedEventArgs("ListHeader"));