How to clear text box on click in MVVM

前端 未结 2 1282
傲寒
傲寒 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:29

    You are not triggering the PropertyChanged-event with the correct property name "TextProperty" - or am I missing something? I've never used Prism. Try:

    public string TextProperty
    {
    
        get
        {
            return selectedText;
        }
        set
        {
            SetProperty(ref selectedText, value, "TextProperty");
        }
    }
    

    or better yet:

    private void MyCommandExecuted(object obj)
    {
        SetProperty(TextProperty, string.Empty);
        MessageBox.Show("Command Executed");
    }
    

    and remove the SetProperty call from the property setter.

提交回复
热议问题