Tapped eventhandler

时间:2012-05-31 14:56:56

标签: c# windows-8 windows-runtime

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

2 个答案:

答案 0 :(得分: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.";
    }
}

就是这样。

答案 1 :(得分:0)

您应该可以订阅控件的tapped事件。它是文件here