0

如何检测文本框是否已被点击。用户通常会在输入内容之前点击文本框。我试过 textbox.tapped = true , .selected ,它不适用于 WinRT/Windows 8 Metro 应用程序。有人可以帮我吗?谢谢

4

2 回答 2

1

它不能更简单。正如 dotNetNin​​ja 所说,您必须注册 Tapped 活动。示例如下,请注意xaml 代码和后面的 cs 代码中的TextBox_Tapped方法。

.xaml 代码:

<Page x:Class="TappedEventExample.BlankPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TappedEventExample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid Background="{StaticResource ApplicationPageBackgroundBrush}">
        <TextBox
            x:Name="MyTextBox"
            HorizontalAlignment="Left"
            Margin="100,100,0,0"
            TextWrapping="Wrap"
            Text="My TextBox"
            VerticalAlignment="Top"
            Height="100" Width="200"
            Tapped="TextBox_Tapped"/>
    </Grid>
</Page>

.xaml.cs 代码:

public sealed partial class BlankPage : Page
{
    public BlankPage()
    {
        this.InitializeComponent();
    }

    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.  The Parameter
    /// property is typically used to configure the page.</param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    }

    private void TextBox_Tapped(object sender, TappedRoutedEventArgs e)
    {
        this.MyTextBox.Text = "I was tapped.";
    }
}

就这样。

于 2012-05-31T21:13:30.507 回答
0

您应该能够订阅控件的点击事件。这是这里的文件

于 2012-05-31T15:05:12.063 回答