xaml - WPF: How do I create a button "template" that applies a style & has an image in it? -
there multiple places in wpf application need button looks & feels regular button, but:
- it shows specific icon on (defined 
{staticresource editicon}) - it applies style (defined 
{staticresource grayoutbuttonstyle}) 
i prefer define these attributes in single location, rather repeating them each place button used. what appropriate way in xaml?
--
if helps, below i'm doing, told wrong:
updated: wrong way? there way fix "right way"?
i define button template key editbutton:
<controltemplate x:key="editbutton" targettype="{x:type button}">      <button style="{staticresource grayoutbuttonstyle}"               command="{templatebinding command}">         <image x:name="editimage" source="{staticresource editicon}" />      </button> </controltemplate>   then, declare button template editbutton each place want use in application. indicate command invoke here:
<button template="{staticresource editbutton}" command="..." />   is not right? correct way this?
a different approach:
have considered making custom control? way, can create own attributes set image contained in button, , don't have rely on multiple styles.
<mycontrol:mybutton x:name="onebutton" imagesource="mybutton.png" /> <mycontrol:mybutton x:name="anotherbutton" imagesource="myotherbutton.png" />  class mybutton {    private string imagesource;   public string imagesource {     {       return this.imagesource;     }     set {       this.imagesource = value;       //set image control's source this.imagesource     }   } }      
Comments
Post a Comment