TextBox.TextChanged & ICommandSource

前端 未结 3 1441
谎友^
谎友^ 2020-12-10 14:42

I am following the M-V-VM pattern for my WPF UI. I would like to hook up a command to the TextChanged event of a TextBox to a command that is in my ViewModel class. The only

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 15:02

    Using the event binding and command method might not be the right thing to use. What exactly will this command do?

    You might want to consider using a Databinding to a string field in your VM. This way you can make a call to a command or function from there rather than having the UI care at all.

    
    ....
    public string WorldName
    {
        get
        {
            return WorldData.Name;
        }
        set
        {
            WorldData.Name = value;
            OnPropertyChanged("WorldName");
            // CallYourCustomFunctionHere();
        }
    }
    

提交回复
热议问题