Q:

Tapped eventhandler

How do i detect if the textbox has been tapped. User will normally tap on the textbox before they can type something. I tried textbox.tapped = true , .selected , it doesnt work for WinRT/Windows 8 metro application. Can someone help me out? THanks

A:

It cannot be simpler. As dotNetNinja says you have to sign up for the Tapped event. Example follows, notice TextBox_Tapped method in the xaml code and in the cs code behind.
.xaml code:
<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 code:
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.";
    }
}

That's all.

