How to clear text box on click in MVVM

前端 未结 2 1313
傲寒
傲寒 2021-01-23 05:41

I have a textbox and a button I want to clear the contents of textbox on button click. I am using MVVM prism.

My XAML is

  

        
2条回答
  •  遇见更好的自我
    2021-01-23 06:33

    Its because in your setter you are setting the field twice, one without firing PropertyChanged and the other with firing PropertyChanged , in the second set SetProperty will raise PropertyChanged only if there is a new value, but you already set the field to some value so the set through the SetProperty will never raise PropertyChanged because you are setting it to the same value.

    So in your setter you should remove:

    selectedText = value;
    

提交回复
热议问题