在我的Silverlight应用程序,我似乎不能把焦点放在一个TextBox控件。在各种帖子的建议,我设置IsTabStop属性为True,我使用TextBox.Focus()。虽然UserControl_Loaded事件正在触发,但TextBox控件未获得焦点。我在下面包含了我非常简单的代码。我缺少什么?谢谢。
Page.xaml
<UserControl x:Class="TextBoxFocusTest.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="UserControl_Loaded" Width="400" Height="300"> <Grid x:Name="LayoutRoot" Background="White"> <StackPanel Width="150" VerticalAlignment="Center"> <TextBox x:Name="RegularTextBox" IsTabStop="True" /> </StackPanel> </Grid> </UserControl>
page.xaml.cs
using System.Windows; using System.Windows.Controls; namespace PasswordTextBoxTest { public partial class Page : UserControl { public Page() { InitializeComponent(); } private void UserControl_Loaded(object sender,RoutedEventArgs e) { RegularTextBox.Focus(); } } }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。