views:

88

answers:

4

Hi there,

I have a custom control and I would like it to act like a button i.e. when you hover over it changes a little so it seems "clickable" to the user

I actually acheived this using the MouseEnter and MouseLeave events and changing the gradient but...

is there a way to apply a style to the user control and say something like TargetType="button" so that it "acts" like a button automatically?

I feel the way i'm doing it is not the best way

A: 

In Expression Blend 3, you can edit the different states (Normal, Hover, pressed, selected etc), of any control how you need it. just select your control and click Edit copy template

Tommy
+2  A: 

Add border object and sets its visibility on mousehover and leave event on the control (This will look like a flat\popup button). Additionally set the control's cursor to hand.

Jojo Sardez
+2  A: 

As sniper says, you can set a Controltemplate for each state.

Alternatively, you can completely replace a control's visual tree with anything you want - while still keeping the control behavior intact. Check out this post by ScottGu on the topic

Gabriel McAdams
This sounds like the best approach to me, depending on what your user control actually does and how complex it is. Remember that a Button is a ContentControl, so you can actually set anything as its Content not just text and then you could tweak the template as you like. If the control starts doing a lot more than a basic button then I might consider deriving from ButtonBase and creating a new default style for the control with the expected parts and states.
Dan Auclair
Please remember to accept this answer if you found it useful.
Gabriel McAdams
A: 

You can derive your control from ButtonBase, just like Button, HyperlinkButton, Checkbox, etc.

Gabe