How to hookup TextBox's TextChanged event and Command in order to use MVVM pattern in Silverlight

前端 未结 10 2410
一整个雨季
一整个雨季 2020-12-15 18:19

Recently, I realized that MVVM pattern is so useful for Silverlight application and studying how to adopt it into my project.

BTW, how to hook up the textbox\'s text

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 18:40

    Why not just bind the Text property to a property on your view model? That way you get notified when it has changed, and also get the new value:

    public string MyData
    {
        get { return this.myData; }
        set
        {
            if (this.myData != value)
            {
                this.myData = value;
                this.OnPropertyChanged(() => this.MyData);
            }
        }
    }
    

    XAML:

    
    

提交回复
热议问题