title: Tagging in Windows 8
body: <p>As hard as I try I can not find how to reference my tag in my CS file.</p>
  
  <p>In my XAML file I have the following</p>
  
  <pre><code>&lt;StackPanel Orientation="Horizontal"  HorizontalAlignment="Center"&gt;
  &lt;TextBlock Text="User Id" Margin="30" Foreground="White" FontSize="25" /&gt;
  &lt;TextBox x:Name="logInUserIdText" IsSpellCheckEnabled="True" Height="40" Margin="13,1" Width="408"  InputScope="EmailSmtpAddress" FontFamily="Global User Interface" KeyDown="logInUserIdKeyDown" Tag="1" /&gt;
  &lt;/StackPanel&gt;
  &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Center"&gt;
  &lt;TextBlock Text="Password" Margin="20" Foreground="White"  FontSize="25" /&gt;
  &lt;PasswordBox  x:Name="logInPasswordText"  IsPasswordRevealButtonEnabled="True" Height="40" Margin="5,1"  Width="408"  KeyDown="logInPasswordKeyDown" Tag="2"/&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>Now in my CS file I have the following</p>
  
  <pre><code> private void logInUserIdKeyDown(object sender, KeyRoutedEventArgs e)
   {
       if (e.Key == VirtualKey.Enter)
       {
           logInUserIdString = logInUserIdText.Text;
           Debug.WriteLine("aa");
           logInPasswordText.Focus(FocusState.Programmatic);
       }
  
   }
  
   private void logInPasswordKeyDown(object sender, KeyRoutedEventArgs e)
   {
       if (e.Key == VirtualKey.Enter)
       {
           logInPasswordString = logInPasswordText.Password;
           Debug.WriteLine("bb");
       }
   }
  </code></pre>
  
  <p>And the issue is that regardless of which box is in focus, if I hit <em>ENTER</em> on the keyboard <strong>both methods get fired</strong> and the output is <strong>aa bb</strong> which are the debug statements in each method.</p>
  
  <p>So I assume that since I set the tag value in XAML I should be able to do something like</p>
  
  <pre><code>if (e.Key == Virtual.Enter)&amp;&amp;(e.Tag == 1)
    Debug.WriteLine("loginuserid method only called");
  </code></pre>
  
  <p>But I can not, it wont let me reference the tag in the CS file.  Why not?</p>
  
  <p>Any help would be much appreciated.</p>