How to set focus to textbox using MVVM?

前端 未结 4 1421
野性不改
野性不改 2020-12-02 17:49

How to focus a textbox from ViewModel wpf?



        
4条回答
  •  萌比男神i
    2020-12-02 18:34

    The question you should be asking yourself is "why does my ViewModel need to know which control has the focus?"

    I'd argue for focus being a view-only property; it's an interaction property, and has nothing to do with the conceptual state. This is akin to the background color of a control: why would you represent it in the VM? If you need to manage the focus in a custom way, it's probably better to use a view-level object to do the job.

提交回复
热议问题