我正在做一個 UWP 應用程序。我不知道 UWP 或 XAML,所以我正在學習。我有我的課程 _Viewmodel.cs:namespace IHM_UWP{public class _ViewModel : INotifyPropertyChanged{ private GestionBras bras= new GestionBras(); //On peut ajouter cet instance dans la classe App.Xaml.cs? public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged([CallerMemberName] string str = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(str)); } } /// <summary> /// Commande pour lancer la connexion au bras /// </summary> private ICommand connect; public ICommand Connect { get { if (this.connect == null) this.connect = new RelayCommand(() => this.Bras.ConnectAsync()); return this.connect; } } public GestionBras Bras { get => bras; set => bras = value; }}}當我點擊我的“連接”按鈕時,我啟動了一種連接到樹莓板的方法,如果連接正常,我想將我的按鈕上的內容更改為“斷開手臂”,我在按鈕上使用綁定數據:Content= “{Binding Bras.Com.CanConnect, Mode=TwoWay}”,當我啟動應用程序時,我看到變量 CanConnect 在我的代碼中各處都正確更改,我的問題是我的應用程序窗口沒有更改此值:/有人可以解釋我為什么這不起作用:)預先感謝您的回答,對不起我的英語水平^^
1 回答

白衣非少年
TA貢獻1155條經驗 獲得超0個贊
您的DisableButton()方法應該設置屬性C anConnect 而不是字段c anConnect 以便OnPropertyChanged調用方法和PropertyChanged引發事件:
public void DisableButton()
{
CanConnect = disconnectMsg;
}
- 1 回答
- 0 關注
- 80 瀏覽
添加回答
舉報
0/150
提交
取消