我正在做一個 UWP 應(yīng)用程序。我不知道 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; }}}當我點擊我的“連接”按鈕時,我啟動了一種連接到樹莓板的方法,如果連接正常,我想將我的按鈕上的內(nèi)容更改為“斷開手臂”,我在按鈕上使用綁定數(shù)據(jù):Content= “{Binding Bras.Com.CanConnect, Mode=TwoWay}”,當我啟動應(yīng)用程序時,我看到變量 CanConnect 在我的代碼中各處都正確更改,我的問題是我的應(yīng)用程序窗口沒有更改此值:/有人可以解釋我為什么這不起作用:)預(yù)先感謝您的回答,對不起我的英語水平^^
1 回答

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