0

我只是想做的是,当用户点击按钮时,它的内容应该根据编码而改变。这是代码。我已经尝试了两种方式,代码隐藏方式和 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;                
    }
}
4

1 回答 1

1

您最好将您的内容与属性名称 (ListHeader) 而不是变量名称 (listHeader) 绑定。所以在你的代码中改变这两行。

<Button x:Name="Header" Content="{Binding ListHeader}"  Click="HeaderClick"/>

PropertyChanged(this, new PropertyChangedEventArgs("ListHeader"));
于 2013-07-22T04:39:17.687 回答