Setting Focus on a Control within a ControlTemplate in WPF

前端 未结 2 2044
半阙折子戏
半阙折子戏 2021-01-14 05:26

In an application I\'m working on, we have a bunch of custom controls with their ControlTemplates defined in Generic.xaml.

For instance, our custom textbox would loo

2条回答
  •  自闭症患者
    2021-01-14 05:59

    Within your control template you can add a Trigger that sets the FocusedElement of the StackPanel's FocusManager to the textbox you want focused. You set the Trigger's property to {TemplateBinding IsFocused} so it fires when the containing control is focused.

提交回复
热议问题