通知DataBind更改按钮

时间:2013-06-25 05:23:51

标签: c# xaml mvvm

我已将此属性数据绑定到一个按钮,如下所示,如何更新其他布尔属性以便再次检查时,如何通知按钮?

DataBinding属性

public bool AccountSelectedAndBankFileSelected
{
    get
    {
        return SelectedAccount != null && SelectedAccount.BankFileSelected;
    }
}

按钮

<Button Content="Open bank." IsEnabled="{Binding AccountSelectedAndBankFileSelected}" />

BankFileSelected Property

public bool BankFileSelected
{
    get { return _bankFileSelected; }
    set { _bankFileSelected = value; OnPropertyChanged("BankFileSelected"); }
}

2 个答案:

答案 0 :(得分:2)

你有两个选择。您可以将AccountSelectedAndBankFileSelected更改为依赖项属性,也可以实现INotifyPropertyChanged接口。第二个可能是最简单的。你所做的就是实现这个界面。然后,当决​​定AccountSelectedAndBankFileSelected结果的任何属性发生更改(因此SelectedAccountSelectedAccount.BankFileSelected属性)时,会引发INotifyPropertyChanged接口定义的事件。< / p>

答案 1 :(得分:1)

View不知道该属性是否已更改。 您应该在RaisePropertyChanged("AccountSelectedAndBankFileSelected") setter:

中致电NotifyPropertyChanged("AccountSelectedAndBankFileSelected")(或SelectedAccount.BankFileSelected
    public bool BankFileSelected
    {
        get
        {
            return bankFileSelected;
        }
        set
        {
            bankFileSelected= value;
            yourViewModel.RaisePropertyChanged("AccountSelectedAndBankFileSelected");
        }
    }