c# - Disable default button click effect -


i have button created programatically:

button button = new button(); imagebrush background = new imagebrush(); background.imagesource = new system.windows.media.imaging.bitmapimage(new uri(@"assets/image1.png", urikind.relative)); button.background = background;  button.click += button_click; 

now when click on button need remove default click effect , add own image, when click on button image have added should displayed.

edit

the above had 2 upvotes works replacing background image, want both images displayed, onclick should add foreground image button.

how can acheive ?

you need play visual states of button , of style

just @ style below

<style x:key="style_colorbutton" targettype="button">         <setter property="background" value="transparent"/>         <setter property="borderbrush" value="{staticresource phoneforegroundbrush}"/>         <setter property="foreground" value="{staticresource phoneforegroundbrush}"/>         <setter property="borderthickness" value="{staticresource phoneborderthickness}"/>         <setter property="fontfamily" value="{staticresource phonefontfamilysemibold}"/>         <setter property="fontsize" value="{staticresource phonefontsizemediumlarge}"/>         <setter property="padding" value="10,3,10,5"/>         <setter property="template">             <setter.value>                 <controltemplate targettype="button">                     <grid background="transparent">                         <visualstatemanager.visualstategroups>                             <visualstategroup x:name="commonstates">                                 <visualstate x:name="normal"/>                                 <visualstate x:name="mouseover"/>                                 <visualstate x:name="pressed">                                     <storyboard>                                         <objectanimationusingkeyframes storyboard.targetproperty="foreground" storyboard.targetname="contentcontainer">                                             <discreteobjectkeyframe keytime="0" value="{staticresource phonebackgroundbrush}"/>                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetproperty="background" storyboard.targetname="buttonbackground">                                             <discreteobjectkeyframe keytime="0">                                                 <discreteobjectkeyframe.value>                                                     <imagebrush stretch="fill" imagesource="/images/colorclicked.png"/>                                                 </discreteobjectkeyframe.value>                                             </discreteobjectkeyframe>                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetproperty="borderbrush" storyboard.targetname="buttonbackground">                                             <discreteobjectkeyframe keytime="0" value="{staticresource phoneforegroundbrush}"/>                                         </objectanimationusingkeyframes>                                     </storyboard>                                 </visualstate>                                 <visualstate x:name="disabled">                                     <storyboard>                                         <objectanimationusingkeyframes storyboard.targetproperty="foreground" storyboard.targetname="contentcontainer">                                             <discreteobjectkeyframe keytime="0" value="{staticresource phonedisabledbrush}"/>                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetproperty="borderbrush" storyboard.targetname="buttonbackground">                                             <discreteobjectkeyframe keytime="0" value="{staticresource phonedisabledbrush}"/>                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetproperty="background" storyboard.targetname="buttonbackground">                                             <discreteobjectkeyframe keytime="0" value="transparent"/>                                         </objectanimationusingkeyframes>                                     </storyboard>                                 </visualstate>                             </visualstategroup>                         </visualstatemanager.visualstategroups>                         <border x:name="buttonbackground" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}" cornerradius="0">                             <contentcontrol x:name="contentcontainer" contenttemplate="{templatebinding contenttemplate}" content="{templatebinding content}" foreground="{templatebinding foreground}" horizontalcontentalignment="{templatebinding horizontalcontentalignment}" padding="{templatebinding padding}" verticalcontentalignment="{templatebinding verticalcontentalignment}"/>                         </border>                     </grid>                 </controltemplate>             </setter.value>         </setter>     </style> 

in style above visualstate "pressed" handles requirement , have given image source there.

using style button.

<button height="40" width="40" borderthickness="0" name="btnacceptcrop" click="btnacceptcrop_click" style="{staticresource style_colorbutton}" background="black" foreground="white"/> 

setting style in code

btnacceptcrop.style = (style)app.current.resources["style_colorbutton"]; 

declaring style in page

below namespace declaration in page

just make tag

<phone:phoneapplicationpage.resources> </phone:phoneapplicationpage.resources> 

and declare style inside it.

hope helps.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -