如何检测文本框是否已被点击。用户通常会在键入内容之前点击文本框。我尝试了textbox.tapped = true,.selected,它不适用于WinRT/Windows8 metro应用程序。有人能帮帮我吗?谢谢
发布于 2012-06-01 05:13:31
这不能再简单了。正如dotNetNinja所说,你必须注册参加点击活动。示例如下,请注意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-31 23:05:12
您应该能够订阅控件的tapped事件。它是文档here
https://stackoverflow.com/questions/10836079
复制相似问题