wpf - How to properly set the BasedOn in XAML style -



wpf - How to properly set the BasedOn in XAML style -

i have style template:

<style x:key="mydogtogglebutton1" targettype="togglebutton" basedon="{x:null}"> <setter property="focusvisualstyle" value="{x:null}"/> <setter property="template"> <setter.value> <controltemplate targettype="togglebutton"> <grid> <image name="normal" source="/images/dogs/dog1.png"/> <image name="pressed" source="/images/dogs/dog3.png" visibility="hidden"/> <image name="disabled" source="images/dogs/dog5.png" visibility="hidden"/> </grid> <controltemplate.triggers> <trigger property="ispressed" value="true"> <setter targetname="normal" property="visibility" value="hidden"/> <setter targetname="pressed" property="visibility" value="visible"/> </trigger> <trigger property="isenabled" value="false"> <setter targetname="normal" property="visibility" value="hidden"/> <setter targetname="disabled" property="visibility" value="visible"/> </trigger> </controltemplate.triggers> </controltemplate> </setter.value> </setter> </style>

and want 1 based on upper one, , doesn't work:

<style x:key="mydogtogglebutton2" targettype="togglebutton" basedon="{dynamicresource mydogtogglebutton1}"> <setter property="normal" value="/images/dogs/dog2.png" /> <setter property="pressed" value="/images/dogs/dog2.png" /> <setter property="disabled" value="/images/dogs/dog2.png" /> </style>

the error message is:

the fellow member "pressed" not recognized or not accessible. fellow member "normal" not recognized or not accessible. fellow member "disabled" not recognized or not accessible.

i suspect different style calling wrong, please point out error.

try this

resource

<window.resources> <style x:key="mydogtogglebutton1" targettype="togglebutton"> <style.resources> <bitmapimage x:key="normal" urisource="images/darblue_tab.png"/> <bitmapimage x:key="pressed" urisource="images/img-whitebg.png" /> <bitmapimage x:key="disabled" urisource="images/img-greenbg.png"/> </style.resources> <setter property="focusvisualstyle" value="{x:null}"/> <setter property="template"> <setter.value> <controltemplate targettype="togglebutton"> <grid> <image name="normal" source="{dynamicresource resourcekey=normal}" stretch="fill"/> <image name="pressed" source="{dynamicresource resourcekey=pressed}" visibility="hidden"/> <image name="disabled" source="{dynamicresource resourcekey=disabled}" visibility="hidden"/> </grid> <controltemplate.triggers> <trigger property="ispressed" value="true"> <setter targetname="normal" property="visibility" value="hidden"/> <setter targetname="pressed" property="visibility" value="visible"/> </trigger> <trigger property="isenabled" value="false"> <setter targetname="normal" property="visibility" value="hidden"/> <setter targetname="disabled" property="visibility" value="visible"/> </trigger> </controltemplate.triggers> </controltemplate> </setter.value> </setter> </style> <style x:key="mydogtogglebutton2" targettype="togglebutton" basedon="{staticresource mydogtogglebutton1}"> <style.resources> <bitmapimage x:key="normal" urisource="images/img-darkbg.png" /> <bitmapimage x:key="pressed" urisource="images/screenshot_5.png"/> <bitmapimage x:key="disabled" urisource="images/img-bluebg.png"/> </style.resources> </style> </window.resources>

xaml

<grid> <togglebutton horizontalalignment="left" style="{staticresource mydogtogglebutton1}"/> <togglebutton horizontalalignment="right" style="{staticresource mydogtogglebutton2}"/> </grid>

update using single style.

<grid> <togglebutton height="300" width="300" horizontalalignment="left" style="{staticresource mydogtogglebutton1}"/> <togglebutton height="300" width="300" style="{staticresource mydogtogglebutton1}" horizontalalignment="right"> <togglebutton.resources> <bitmapimage x:key="normal" urisource="images/img-darkbg.png" /> <bitmapimage x:key="pressed" urisource="images/screenshot_5.png"/> <bitmapimage x:key="disabled" urisource="images/img-bluebg.png"/> </togglebutton.resources> </togglebutton> </grid>

wpf xaml

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -