I'm a Rookie and I'm having some Problems. Google hasn't helped me as much as I wanted to because I seriously hate asking and taking time of others for something, but since I'm stuck here for a couple of hours, I'm going to ask.
First, I have a xaml.codesource that is working perfectly. I've engulfed about 30 TextBoxes in a StackPanel, named the StackPanel 'ScoreList' and added a MouseLeftButtonDown_Event {ScoreList.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(ScoreList_Click), true); } on it so that once I click a TextBox, it's going to call that Event.
Everything works so far as much as that the TextBoxes (Although you might want to shake your head about my choice of using TextBoxes instead of Buttons) Show various scores depending on a RandomList which isn't important now.
Now in the Event ScoreList_Click..
private void ScoreList_Click(object sender, MouseButtonEventArgs e)
{
TextBox x = e.OriginalSource as TextBox;
if (x != null)
{
MessageBox.Show("Don't try this at home Kiddo");
}
if (x.Text == "1" || x.Text == "2" || x.Text == "3" || x.Text == "4")
{
x.Text = "10";
x.IsEnabled = false;
}
}
I have currently following Problems:
When I try to check TextBox x for null, it throws a NullReferenceException at me. Even without the check, it throws a NullReferenceException.
I am searching for ideas or a way how to completely lock away a TextBox once clicked. What I mean is that since my TextBoxes have a Click_Event on them, that a second Click won't call the Event again. (Unsubscribe won't work because reasons. No, really. Reasons. Since StackPanel is bound to the Event, I can't unsubscribe a whole Event when all I want is to 'unsubscribe to a single TextBox inside StackPanel'.
Sorry for troubling you guys. I might have given too much thought in it as I want to reduce my code heavily from like 80 lines code to 5 with my idea.