WPF MVVM Focus Field on Load

后端 未结 6 2047
梦谈多话
梦谈多话 2020-12-13 01:58

I have a View that has a single TextBox and a couple Buttons below it. When the window loads I want that TextBox to have focus.

6条回答
  •  心在旅途
    2020-12-13 02:46

    Actually, isn't focus a UI concern? MVVM is about separating concerns - what belongs to model is in model, what belongs to view is in view, and what bind model and view together is in ViewModel (this is of course oversimplified description).

    This means, that UI logic remains in View - TextBox.Focus() is, in my opinion, appropriate way to make this happen.

提交回复
热议问题