wpf - Implicit Styles not working on Custom Controls -


in app.xaml have few implicit styles

<style targettype="{x:type button}">    ...blah... </style> 

these styles work control long not in custom control create.

my control

 public class navigationcontrol : control  {      public static readonly dependencyproperty buttonstyleproperty =          dependencyproperty.register("buttonstyle", typeof(style), typeof(navigationcontrol));       public style buttonstyle      {          { return (style)getvalue(buttonstyleproperty); }          set { setvalue(buttonstyleproperty, value); }      }  }   static navigationcontrol()  {      defaultstylekeyproperty.overridemetadata(typeof(navigationcontrol), new frameworkpropertymetadata(typeof(navigationcontrol)));  }   public navigationcontrol()  {  } 

my control styles , templates

<controltemplate x:key="navigationcontroltemplate" targettype="{x:type controls:navigationcontrol}">    <button style="{templatebinding buttonstyle}" </controltemplate>  <style x:key="defaultbuttonstyle" targettype="{x:type button}" basedon="{staticresource {x:type button}}">     <setter property="minwidth" value="75"/>     <setter property="height" value="50"/>     <setter property="fontsize" value="12"/>     <setter property="margin" value="-1"/> </style>  <style x:key="buttonstyle" targettype="{x:type button}" basedon="{staticresource defaultbuttonstyle}">     <setter property="template" value="{staticresource navigationbuttontemplate}"/> </style>  <style targettype="{x:type controls:navigationcontrol}">      <setter property="template" value="{staticresource navigationcontroltemplate}"/>      <setter property="buttonstyle" value="{staticresource buttonstyle}"/> </style> 

now assume defaultbuttonstyle's basedon app level. doesnt. way apply app level style override buttonstyle creating style of type navigationcontrol.

is there way implicit style makes work?

setting basedon="{staticresource {x:type button}}" wpf's default button style. if want use style defined in app.xaml, you'll need add key style reference control style:

app.xaml

<!-- style, added x:key --> <style x:key="mybuttonstyle" targettype="{x:type button}">    ... </style>  <!-- set above style default style buttons --> <style targettype="{x:type button}" basedon="{staticresource mybuttonstyle}"> 

your control styles , templates

<style x:key="defaultbuttonstyle" targettype="{x:type button}" basedon="{staticresource mybuttonstyle}">     ... </style> 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -