Dax Pandhi's nAESTHETIC Dax Pandhi's nAESTHETIC Dax Pandhi's nAESTHETIC Subscribe to this Blog's RSS feed Subscribe to my DeviantArt RSS feed

Popular art from my DeviantArt account:


  Monday, October 29, 2007


Simple ImageButton ControlTemplate

This code lets you create a simple button that uses images.

Simple ControlTemplate (put this in your Window, Page, or Application's <Resources /> section).

 

<ControlTemplate x:Key="ImageButton" TargetType="{x:Type Button}"> <ControlTemplate.Resources> <Storyboard x:Key="MouseOver"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="MouseOut"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0.7"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="PressedOn"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.0500000" Value="0.3"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="PressedOff"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0.7"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </ControlTemplate.Resources> <ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Opacity="0.7" x:Name="contentPresenter" Cursor="Hand"> </ContentPresenter> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" SourceName="contentPresenter" Value="True"> <Trigger.EnterActions> <BeginStoryboard Storyboard="{StaticResource MouseOver}"/> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard x:Name="MouseOut_BeginStoryboard" Storyboard="{StaticResource MouseOut}"/> </Trigger.ExitActions> </Trigger> <Trigger Property="IsPressed" Value="True"> <Trigger.EnterActions> <BeginStoryboard x:Name="PressedOn_BeginStoryboard" Storyboard="{StaticResource PressedOn}"/> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard x:Name="PressedOff_BeginStoryboard" Storyboard="{StaticResource PressedOff}"/> </Trigger.ExitActions> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Opacity" TargetName="contentPresenter" Value="0.2"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate>

 

Or if you want to make it look ever cooler (though, a slightly more resource hungry), try the animated flavor!

Animated ControlTemplate

<ControlTemplate x:Key="ImageButton" TargetType="{x:Type Button}"> <ControlTemplate.Resources> <Storyboard x:Key="MouseOver"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="MouseOut"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0.7"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="PressedOn"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.0500000" Value="0.3"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="PressedOff"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0.7"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </ControlTemplate.Resources> <ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Opacity="0.7" x:Name="contentPresenter" Cursor="Hand"> </ContentPresenter> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" SourceName="contentPresenter" Value="True"> <Trigger.EnterActions> <BeginStoryboard Storyboard="{StaticResource MouseOver}"/> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard x:Name="MouseOut_BeginStoryboard" Storyboard="{StaticResource MouseOut}"/> </Trigger.ExitActions> </Trigger> <Trigger Property="IsPressed" Value="True"> <Trigger.EnterActions> <BeginStoryboard x:Name="PressedOn_BeginStoryboard" Storyboard="{StaticResource PressedOn}"/> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard x:Name="PressedOff_BeginStoryboard" Storyboard="{StaticResource PressedOff}"/> </Trigger.ExitActions> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Opacity" TargetName="contentPresenter" Value="0.2"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate>

Usage

1 <Button Template="{DynamicResource ImageButton}" Height="48"> 2 <Image Width="Auto" Height="Auto" Source="images\ok.png" /> 3 </Button>

Enjoy!









4/23/2008 11:51:09 PM (India Standard Time, UTC+05:30)
The source for the Simple and Animated templates are identical.

...Matt
2/8/2009 11:10:36 AM (India Standard Time, UTC+05:30)
I believe that this is merely a phase. I've spent the last month learning everything I can about bulk candy in canada. This is a business. Yeah, didn't happen. That's really an awesome kosher candy in bulk. The point is that you're passionate about that. This is the costly way to get bulk candy jordan which Maybe that was a good example because there are not many that are found online.

Bulk candy is well worth a look. I don't believe that this makes a difference if you have poor bulk candy. This is where having a good bulk candy on is vital. This is a guide to performing bulk sweets.

Most of these wholesale bulk candy techniques can be learned easily. I may not be completely right about this. That is powerful stuff.

I prefer to use a really small number of it then start moving it up as needed. I won't stand for it. Some are giving bulk candy away for free. People are always looking for others with bulk candy.

I can't recommend it enough. When those times come, I stay away from my bulk candy. Here are a few practical suggestions that will reduce this work to a minimum.

I got a wild hair and thought I'd share it with you. The bottom line is this.

Trust me, it's sad. I hate to quibble, but I sort of turn down this weak aim. I have way too much bulk candy new. Here then, we are brought to the question of bulk gummy candy. What a great weekend.

This time I feel like stepping it up a notch. Seems more and more people don't want candy sticks in bulk. Stick around and I?m going to explain. There's usually little point in starting with groovy candies right away. This is what I had first had to say about bulk gummy.

Yep, when it comes to bulk candy, this is the most important element. There is a lot of different discount bulk candy out there to use. Here is the point: I am a few bricks shy of a load.

You can't be so defensive.

Candy groovy is a really easy way to get the most out of bulk candies. People just pull something out of a hat without giving it any thought at all. It does make sense to keep bulk candy. Bulk candy is an illustration of this truth. At this time I don't see what good it will do me. Maybe it does. I mostly use sugar free bulk candy to let off steam and look for new friends. I am alarmed when I see hard candy in bulk. There are many bulk candy sold stores out there but only a few of them are worth visiting. May you're wonder how does candy chocolate work. I think you need to be more positive about it. I advise clients to rethink their bulk candy priorities. Candy in bulk in sucks. This is a great way to get a this thing that annihilates stomping ground for a bulk haribo.
6/3/2009 7:46:56 AM (India Standard Time, UTC+05:30)
thanks for shared..
6/9/2009 1:47:34 AM (India Standard Time, UTC+05:30)
Once the button is clicked, the mouse over animation is not fired anymore. Why? Thanks!
6/22/2009 5:54:52 PM (India Standard Time, UTC+05:30)
hello, this is my first time i visit here. I found so many interesting in your blog especially on how to determine the topic. keep up the good work.
3/1/2010 12:37:07 PM (India Standard Time, UTC+05:30)
So far, this is the best link I've discovered this week. Really helpful. Thanks for sharing.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Copyright � 2005-2007 Dax Pandhi. All rights reserved.
designed by nukeation
Sign In