WPF MVVM Focus Field on Load

后端 未结 6 2041
梦谈多话
梦谈多话 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:51

    1. Have a property in your ViewModel which indicates which is the currently focused element.
    2. Use the FocusManager to bind to that property.

      
      

    Your ViewModel is a translator which exists solely to provide information to the View, so you can add whatever information to the VM that the View needs to function.

提交回复
热议问题