Accessing a control from a button click - C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Accessing a control from a button click - C#

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Posts
    7

    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

  2. #2
    Join Date
    Mar 2005
    Posts
    7

    Talking 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

  3. #3
    Join Date
    Mar 2007
    Posts
    274

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center