开发者

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

开发者 https://www.devze.com 2022-12-21 17:21 出处:网络
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 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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消