I'm creating a Windows 8 app and I have the need for events to be raised during a GotFocus event for a TextBox element. I'm not sure what's wrong or which direction to go in exactly as 1. I'm not that good with events in C# to begin with, and 2. I reckon it's a bit different in WindowsRT. The TextBoxListArray() method is started through another event.
public sealed partial class MainPage : Page
{
List<TextBox> textBox = new List<TextBox>();
List<RichEditBox> editBox = new List<RichEditBox>();
static int tally;
public MainPage()
{
this.InitializeComponent();
}
private void TextBoxListArray()
{
textBox.Add(new TextBox());
int i = textBox.Count();
i = i - 1;
tally = i - 1;
textBox[i].HorizontalAlignment = HorizontalAlignment.Stretch;
textBox[i].VerticalAlignment = VerticalAlignment.Top;
textBox[i].TextWrapping = TextWrapping.NoWrap;
textBox[i].Margin = new Thickness(10);
textBox[i].Text = i.ToString();
textBox[i].IsReadOnly = true;
textBox[i].Height = 40;
stackNotes.Children.Add(textBox[i]);
textBox[i].GotFocus += new EventHandler(TextBoxList_GotFocus);
}
private void TextBoxList_GotFocus(object sender, RoutedEventArgs e)
{
textBox[tally] = sender as TextBox;
textBox[tally].Background = new SolidColorBrush(Colors.Yellow);
}
}