xaml - WinRT - ImageButton for transparent PNGs -
i'm using xaml toolkit imagebutton control able create normal , pressed states button. code is:
<toolkit:imagebutton normalstateimagesource="ms-appx:///assets/1_off.png" pressedstateimagesource="ms-appx:///assets/1_on.png" width="500" height="200"> </toolkit:imagebutton>
issue i'm facing is, have shape isn't rectangle or square. example have pngs star , arrow object. there way set boundary corresponding shape? if not, please advice best approach handle such scenarios.
there 2 options tried
when clicking using mouse or touch - you'd check last position of pointer before click , see if image in button has non-transparent pixel @ position.
- pros:
- it's simpler option 2.
- you precise information
- cons:
- you can't tell if button got clicked mouse, touch, pen, keyboard or narrator using automation, end filtering out keyboard clicks because mouse cursor bit off. possibly use heuristics how long ago pointer move or pointer down event before click event, it's bit hacky , might unreliable.
- pros:
generate vector path image , put in button template
path
elementfill="transparent"
, mark other non-transparent or hit testable template elements (buttons, borders background="transparent", etc.)ishittestvisible="false"
.- pros:
- doesn't break input methods
- can quite precise
- for shapes circle -
path.data
quite simple or useellipse
element instead
- cons:
- you need generate path somehow
- a complex path might adversely affect performance
- pros:
a better solution overall in cases leave hit-testable area rectangular. reason - arbitrary shape finicky , unreliable hit test target makes clicking button more difficult. using default rectangular border or @ - ellipse shape lot simpler , more usable.
Comments
Post a Comment