点击的事件处理程序

本文关键字:程序 事件处理 | 更新日期: 2023-09-27 18:35:49

如何

检测文本框是否已点击。用户通常会在键入内容之前点击文本框。我尝试了textbox.tappped = true , .selected,它不适用于WinRT/Windows 8地铁应用程序。有人可以帮助我吗?谢谢

点击的事件处理程序

它再简单不过了。正如dotNetNinja所说,你必须注册参加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.";
    }
}

就这样。

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