相关疑难解决方法(0)

如何在Silverlight中提供文本框焦点?

在我的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>
Run Code Online (Sandbox Code Playgroud)

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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

silverlight textbox focus

32
推荐指数
3
解决办法
4万
查看次数

标签 统计

focus ×1

silverlight ×1

textbox ×1