0

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

数据绑定属性

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

按钮

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

BankFileSelected 属性

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

2 回答 2

2

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

于 2013-06-25T05:29:12.823 回答
1

View不知道该属性是否已更改。您应该在setter中调用RaisePropertyChanged("AccountSelectedAndBankFileSelected")(或NotifyPropertyChanged("AccountSelectedAndBankFileSelected")) :SelectedAccount.BankFileSelected

    public bool BankFileSelected
    {
        get
        {
            return bankFileSelected;
        }
        set
        {
            bankFileSelected= value;
            yourViewModel.RaisePropertyChanged("AccountSelectedAndBankFileSelected");
        }
    }
于 2013-06-25T06:01:47.393 回答