c# - Why can't I override the default BasedOn Style? WPF -
i have default label style
<style x:key="labelstyle" targettype="{x:type label}"> <setter property="fontfamily" value="segoe ui" /> <setter property="fontsize" value="13.333" /> <setter property="foreground" value="{staticresource foregroundbrush}" /> <setter property="istabstop" value="false" /> <setter property="horizontalcontentalignment" value="left" /> </style> <style basedon="{staticresource labelstyle}" targettype="{x:type label}" />
i try use different style single label
<style x:key="headerlabelstyle" targettype="{x:type label}"> <setter property="fontfamily" value="segoe ui" /> <setter property="fontsize" value="16" /> <setter property="foreground" value="{staticresource headerforegroundbrush}" /> <setter property="istabstop" value="false" /> <setter property="horizontalcontentalignment" value="left" /> </style> <label content="text here" name="somename" style="{staticresource headerlabelstyle}"/>
but reason label gets default style. why? can overridden?
thanks
so realised default (string) template label indented textblock (styles inherited)
since defining global style textblock
<style x:key="textblockstyle" targettype="textblock"> <setter property="foreground" value="{staticresource foregroundbrush}" /> <setter property="fontsize" value="13.333" /> <setter property="fontfamily" value="segoe ui" /> <style basedon="{staticresource textblockstyle}" targettype="{x:type textblock}" />
no matter how many types of label had bound use template textblock
so solution define dummy textblock class
namespace theme { public class headertextblock : textblock { } }
then assign own global style
xmlns:this="clr-namespace:theme" <style x:key="headertextblockstyle" targettype="this:headertextblock"> <setter property="foreground" value="{staticresource headerforegroundbrush}" /> <setter property="fontsize" value="13.333" /> <setter property="fontfamily" value="segoe ui" /> </style> <style basedon="{staticresource headertextblockstyle}" targettype="{x:type this:headertextblock}" />
and use textblocks instead of labels (haven't figured out how implement label child yet since (label : textblock) = false
xmlns:theme="clr-namespace:theme;assembly=theme" <theme:headertextblock text="some text" name="titlelabel" style="{staticresource headertextblockstyle}"/>
wiki
Comments
Post a Comment