|
-
Dec 10th, 2011, 03:39 PM
#1
Thread Starter
Addicted Member
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.
-
Dec 11th, 2011, 01:53 PM
#2
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
-
Dec 11th, 2011, 04:41 PM
#3
Thread Starter
Addicted Member
Re: Could someone answer some basic WPF questions?
 Originally Posted by boops boops
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|