Thursday, 15 August 2013

Blue mouse over effect on button in Blend / WPF -



Blue mouse over effect on button in Blend / WPF -

i started getting used wpf using blend visual studio. created previous programs standart windows forms , want more modern. encountered main problem after 5 minutes. added button background image transperancy. worked charm, problem that, when run application, button gets bluish when mouse hovers it. not want bluish effect can't find alternative disable in blend. hope can help me stupid question, windows forms little

what you're describing default state behavior button. have create custom template or style alter it. example:

<button content="button"> <button.style> <style targettype="{x:type button}"> <setter property="background" value="transparent"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type button}"> <border background="{templatebinding background}"> <contentpresenter horizontalalignment="center" verticalalignment="center"/> </border> </controltemplate> </setter.value> </setter> <style.triggers> <trigger property="ismouseover" value="true"> <setter property="background" value="black"/> <setter property="foreground" value="white"/> </trigger> </style.triggers> </style> </button.style> </button>

i demonstrating 2 properties changes here: background & foreground. may have many want , alter them whatever value wish. if don't want changes, remove style.triggers or particular property within it.

here's demo you, since you're new:

here's resource dictionary way:

create resource dictionary , add together style it:

<style x:key="custombuttonstyle" targettype="button"> <setter property="background" value="transparent"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type button}"> <border background="{templatebinding background}"> <contentpresenter horizontalalignment="center" verticalalignment="center"/> </border> </controltemplate> </setter.value> </setter> <style.triggers> <trigger property="ismouseover" value="true"> <setter property="background" value="black"/> <setter property="foreground" value="white"/> </trigger> </style.triggers> </style>

place in app.xaml or wherever merge resource dictionaries:

<resourcedictionary> <resourcedictionary.mergeddictionaries> <resourcedictionary source="buttonstyles.xaml"/> </resourcedictionary.mergeddictionaries> </resourcedictionary>

then specify style button:

style="{staticresource custombuttonstyle}"

wpf button blend

No comments:

Post a Comment