TextBox.TextChanged & ICommandSource

前端 未结 3 1442
谎友^
谎友^ 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:09

    Can you not just handle the TextChanged event and execute the command from there?

    private void _textBox_TextChanged(object sender, EventArgs e)
    {
        MyCommand.Execute(null);
    }
    

    The alternative, as you say, is to create a TextBox that acts as a command source, but that does seem like overkill unless it's something you're planning on sharing and leveraging in many places.

提交回复
热议问题