我想要將Button IsEnabled綁定到我的ViewModel。所以,我想這一點:WPF按鈕IsEnabled綁定失敗
<Button Content="{Binding Icon}" Command="{Binding Connect}" IsEnabled="{Binding ConnectBtnEnable, Mode=TwoWay}" />
並在視圖模型:
private bool _ConnectBtnEnable = true;
public bool ConnectBtnEnable
{
get { return _ConnectBtnEnable; }
set { _ConnectBtnEnable = value; OnPropertyChanged(); }
}
但是,當我設置使用該屬性:
public void Connect()
{
ConnectBtnEnable = false;
}
它不工作,什麼是問題。提前致謝!
謝謝,但即使我更改爲'ConnectBtnEnable',它仍然不起作用。 – BarryLib
@BarryLib在你的問題中添加更多細節。你確定該按鈕的數據上下文是包含'ConnectBtnEnable'屬性的視圖模型嗎?顯示「OnPropertyChanged」方法的代碼。 – Maxim