点击事件处理程序

问题描述 投票:0回答:2

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

c# windows-8 windows-runtime
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.";
    }
}

就这样。


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.