xaml - Show border control on hover -
i new xaml , programming in windows store applications, please bare me =)
i've got border control, holds image control. basicly want show border control if image control hovered. similar css :hover effect.
whats easiest way achieve this?
there so many ways achieve this, , depends on setup is.
- is 1 isolated image, or want able reuse functionality elsewhere?
- is image inside
datatemplate
listview
or other items control? - would ok writing code-behind achieve this, or preferably xaml-only solution? (hopefully latter.)
- etc.
if it's 1 image, handle pointerentered
, pointerexited
events on image control set border's borderbrush
color yellow (for example) , transparent, respectively. since said you're new xaml, "easiest" solution can offer. maybe else can suggest other simple alternatives. unfortunately, there no ":hover"-like styling out of box. have write functionality yourself.
my preferred solution bundle functionality kind of reusable component. solutions come mind:
- create
usercontrol
housingborder
,image
necessary code-behind handle pointer enter , exit events. - create new templated
contentcontrol
, allowing set arbitraryuielement
insideborder
. allows usetemplatebinding
s set thingsborderbrush
outside template. - create
behavior
(blend sdk) can attachedborder
houses necessary logic.
on topic of blend sdk, solutions 1 , 2 can achieved 0 code-behind if make use of visualstate
s , blend's eventtriggerbehavior
, gotostateaction
handle changing visual states on pointerentered
, pointerexited
events.
Comments
Post a Comment