简体   繁体   中英

Silverlight: How to make my custom control act like a button

I have a custom control and I would like it to act like a button ie 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

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

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

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.

您可以从ButtonBase派生控件,就像Button,HyperlinkBut​​ton,Checkbox等一样。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM