我的嵌套绑定没有刷新我的主页

我正在做一个 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 在我的代码中各处都正确更改,我的问题是我的应用程序窗口没有更改此值:/有人可以解释我为什么这不起作用:)

预先感谢您的回答,对不起我的英语水平^^


一只斗牛犬
浏览 50回答 1
1回答

白衣非少年

您的DisableButton()方法应该设置属性C anConnect 而不是字段c anConnect 以便OnPropertyChanged调用方法和PropertyChanged引发事件:public void DisableButton(){&nbsp; &nbsp; CanConnect = disconnectMsg;}
打开App,查看更多内容
随时随地看视频慕课网APP