如何仅在 xaml 中设置自动对焦? [英] How to set autofocus only in xaml?
本文介绍了如何仅在 xaml 中设置自动对焦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将自动对焦设置为我的 xaml 文件中的文本框?
Is it possible, to set the autofocus to the textbox in my xaml file?
<Window x:Class="WpfApplication1.Views.Test1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="100"
Width="210"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
ResizeMode="CanResizeWithGrip">
<TextBox HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible" TextWrapping="Wrap" AcceptsReturn="True" Text="{Binding Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Window>
推荐答案
<TextBox FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" />
这篇关于如何仅在 xaml 中设置自动对焦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文