Results 1 to 3 of 3

Thread: Could someone answer some basic WPF questions?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Location
    Massachusetts
    Posts
    205

    Question Could someone answer some basic WPF questions?

    Hi, I'm just learning to use Expression Blend 4 for making WPF applications. It's going pretty well, however, I've run into a few problems. My first question is, how do you set triggers for mousedown and mouseup events? I tried setting event triggers but they just wouldn't work. However, the isMouseOver and isFocused triggers work fine. My second question is, is it possible to access WPF-specific items using code? For example, if I wanted to start a storyboard from my C# code when a button is clicked, could I? I know you can do that with triggers. The reason I ask is because I need to have it where there are three buttons. When you click one, its background color turns gold and the two others turn blue. I was able to do this in Winforms, but idk how to in WPF. Please help me. Thanks.

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Could someone answer some basic WPF questions?

    Hi RadX,

    I can answer your second question: quite a few things in the code-behind are pretty similar to WinForms, and IntelliSense helps you a lot. If you add a button in the designer, you can double-click it to get a boilerplate handler for it in the window's xaml.cs file. Then you could button1's click handler, for example, like this:
    Code:
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                button1.Background = Brushes.Gold;
                button2.Background = Brushes.Blue;
                button3.Background = Brushes.Blue;
            }
    ... and similarly for button2 and button3.

    Alternatively you could declare the buttons in the code, and assign click handlers in the initialization. Intellisense practically writes it for you:
    Code:
            public Window1()
            {
                InitializeComponent();
                button1.Click+=new RoutedEventHandler(button1_Click);
                ///etc.
             }
    Obviously, some things are different, such defining the Background as Brush instead of the BackgroundColor as a Color. Once again, Intellisense helps you.

    BB

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Location
    Massachusetts
    Posts
    205

    Re: Could someone answer some basic WPF questions?

    Quote Originally Posted by boops boops View Post
    Hi RadX,

    I can answer your second question: quite a few things in the code-behind are pretty similar to WinForms, and IntelliSense helps you a lot. If you add a button in the designer, you can double-click it to get a boilerplate handler for it in the window's xaml.cs file. Then you could button1's click handler, for example, like this:
    Code:
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                button1.Background = Brushes.Gold;
                button2.Background = Brushes.Blue;
                button3.Background = Brushes.Blue;
            }
    ... and similarly for button2 and button3.

    Alternatively you could declare the buttons in the code, and assign click handlers in the initialization. Intellisense practically writes it for you:
    Code:
            public Window1()
            {
                InitializeComponent();
                button1.Click+=new RoutedEventHandler(button1_Click);
                ///etc.
             }
    Obviously, some things are different, such defining the Background as Brush instead of the BackgroundColor as a Color. Once again, Intellisense helps you.

    BB
    Ok, but I want a gradient gold background when a button is clicked. I have a saved storyboard that turns the background into a gold gradient. How do I begin that from the code?

Posting Permissions

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



Click Here to Expand Forum to Full Width