Accessing a control from a button click - C#
Hi all,
I've just started looking at WPF after playing with C# for a while. As such I'm starting by using XAML to define my form and then use C# to do the interesting stuff behind. For my first example I have a button on a form - Window1 and I can capture the event in the cs file that sits behind the XAML - Window1.xaml.cs. From here I can modify the button if I want to using code like:
private void button1_Click(object sender, RoutedEventArgs e)
{
Button source = e.Source as Button;
source.Background = Brushes.LemonChiffon;
}
But say I want the button click to modify another control on the form? How would I change the background value of (say) Button2? I've looked around the web and on MSDN and I can't find anyone who seems to be able to answer this question. I guess it can't be that hard - it's childs play in a "normal" C# form!
Thanks for your help,
Steve
Re: Accessing a control from a button click - C#
Hi all,
I can't believe I have been so stupid! Accessing the control is EXACTLY the same as using a Windows Form! Apologies for wasting everyones time - and to think I spent an hour trying to work this out - D'Oh!
Hope this forum gets better than my daft questions!
Cheers,
Steve
Re: Accessing a control from a button click - C#
Accessing the control is not exactly the same. You will learn. I am learning as well. Consider "attached properties" and "dependency properties". WPF is a completely different beast from your comfortable .net experience.