WPF - Set Focus when a button is clicked - No Code Behind

前端 未结 7 1288
小蘑菇
小蘑菇 2020-11-29 03:53

Is there a way to set Focus from one control to another using WPF Triggers?

Like the following example:



        
7条回答
  •  [愿得一人]
    2020-11-29 03:55

    I'm not near visual studio so I can't actually try this right now, but off the top of my head, you should be able to do something like this:

    FocusManager.FocusedElement="{Binding ElementName=txtName}">
    

    Edit:

    There is a followup question (asked more recently) about this here: How to set autofocus only in xaml? which contains this method, and a few different ideas on how to use it.

提交回复
热议问题