xaml - Change property of "super/base" style wpf -
i creating base style. using inheritance implement base style. know how add properties on derived class don't know how change property. let me give example:
let have base style:
<!-- srollviewer scrollbar repeat buttons (at each end) --> <style x:key="scrollbarlinebutton" targettype="{x:type repeatbutton}"> <setter property="snapstodevicepixels" value="true"/> <setter property="overridesdefaultstyle" value="true"/> <setter property="focusable" value="false"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type repeatbutton}"> <border name="border" margin="1" cornerradius="2" background="whitesmoke" borderthickness="1"> <image stretch="uniform" source="/filespro;component/images/scrollarrow.png" height="40" verticalalignment="center" horizontalalignment="center" width="52" > <image.rendertransform> <transformgroup> <scaletransform scaley="-1" /> <translatetransform y="40"/> <skewtransform/> <rotatetransform/> <translatetransform/> </transformgroup> </image.rendertransform> </image> <!-- <path horizontalalignment="center" verticalalignment="center" fill="{staticresource glyphbrush}" data="{binding path=content, relativesource={relativesource templatedparent}}" > </path> --> </border> </controltemplate> </setter.value> </setter> </style>
i create new style has same properties scrollbarlinebutton image transfrom scaley=1 instead of -1.
when do:
<style x:key="scrollbarlinebuttonverticalup" basedon="{staticresource scrollbarlinebutton}" targettype="{x:type repeatbutton}"> <setter property="template"> <setter.value> <controltemplate targettype="{x:type repeatbutton}"> <border> <image stretch="uniform" source="/filespro;component/images/scrollarrow.png" height="40" verticalalignment="center" horizontalalignment="center" width="52" > <image.rendertransform> <transformgroup> <scaletransform scaley="1" /> .... ...
border no longer has base style margin, background color etc.. how inherit style , change 1 property. know can copy paste change lot , convenient if change in 1 place changes in other places.
you can create dynamicresource
reference this, here's example:
<stackpanel> <stackpanel.resources> <style x:key="buttonstylea" targettype="{x:type button}"> <style.resources> <solidcolorbrush x:key="textbrush" color="yellow" /> </style.resources> <setter property="template"> <setter.value> <controltemplate targettype="{x:type button}"> <border cornerradius="10" borderthickness="1" borderbrush="red"> <contentpresenter textelement.foreground="{dynamicresource textbrush}"/> </border> </controltemplate> </setter.value> </setter> </style> <style x:key="buttonstyleb" targettype="{x:type button}" basedon="{staticresource buttonstylea}"> <style.resources> <solidcolorbrush x:key="textbrush" color="blue" /> </style.resources> </style> </stackpanel.resources> <button style="{staticresource buttonstylea}" content="lorem ipsum" /> <button style="{staticresource buttonstyleb}" content="lorem ipsum" /> </stackpanel>
in styleb
textbrush
overridden causes template change since references resource.
Comments
Post a Comment