WPF: Unable to access a style from App.xaml -
i facing weird scenario while accessing style app.xaml , 1 style.
app.xaml:
<style x:key="custombuttonstyle" targettype="local:buttoncontrol"> <setter property="template"> <setter.value> <controltemplate targettype="local:buttoncontrol"> <grid datacontext="{templatebinding datacontext}"> <border x:name="borderimg" visibility="{templatebinding visibility}" borderthickness="{templatebinding borderthickness}" borderbrush="{templatebinding borderbrush}" background="{templatebinding background}" cornerradius="{templatebinding bordercornerradius}" datacontext="{templatebinding datacontext}"> <image x:name="image" source="{templatebinding bgimage}" verticalalignment="{templatebinding verticalcontentalignment}" horizontalalignment="{templatebinding horizontalcontentalignment}" datacontext="{templatebinding datacontext}" stretch="{templatebinding stretch}" visibility="{templatebinding bgimagevisibility}"/> </border> <border x:name="borderfocusimg" visibility="{templatebinding visibility}" borderthickness="{templatebinding borderthickness}" borderbrush="{templatebinding borderbrush}" background="{templatebinding background}" cornerradius="{templatebinding bordercornerradius}" datacontext="{templatebinding datacontext}"> <image x:name="focusimage" source="{templatebinding bgfocusimage}" verticalalignment="{templatebinding verticalcontentalignment}" horizontalalignment="{templatebinding horizontalcontentalignment}" datacontext="{templatebinding datacontext}" stretch="{templatebinding stretch}" visibility="{templatebinding bgfocusimagevisibility}"/> </border> <border x:name="bordername" visibility="{templatebinding visibility}" borderthickness="{templatebinding borderthickness}" borderbrush="{templatebinding borderbrush}" background="{templatebinding background}" cornerradius="{templatebinding bordercornerradius}" datacontext="{templatebinding datacontext}"> <textblock x:name="text" opacity="{templatebinding displaytext}" margin="{templatebinding padding}" textwrapping="wrap" foreground="{templatebinding foreground}" text="{templatebinding content}" verticalalignment="{templatebinding verticalcontentalignment}" fontsize="{templatebinding fontsize}" fontweight="{templatebinding fontweight}" textdecorations="{templatebinding fontdecorations}" fontstyle="{templatebinding fontstyle}" horizontalalignment="{templatebinding horizontalcontentalignment}" datacontext="{templatebinding datacontext}"/> </border> </grid> </controltemplate> </setter.value> </setter> </style> <style x:name="customscrollviewerstyle" targettype="local:customscrollviewer"> <setter property="template"> <setter.value> <controltemplate targettype="local:customscrollviewer"> <grid margin="{templatebinding padding}" horizontalalignment="{templatebinding horizontalcontentalignment}" verticalalignment="{templatebinding verticalcontentalignment}" > <grid.resources> <style x:name="scrollviewerwithcompressionstyle" targettype="scrollviewer"> <setter property="verticalscrollbarvisibility" value="auto"/> <setter property="horizontalscrollbarvisibility" value="auto"/> <setter property="background" value="transparent"/> <setter property="padding" value="0"/> <setter property="borderthickness" value="0"/> <setter property="borderbrush" value="transparent"/> <setter property="template"> <setter.value> <controltemplate targettype="scrollviewer"> <border borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}"> <visualstatemanager.visualstategroups> <visualstategroup x:name="scrollstates"> <visualstategroup.transitions> <visualtransition generatedduration="00:00:00.5"/> </visualstategroup.transitions> <visualstate x:name="scrolling"> <storyboard> <doubleanimation storyboard.targetname="verticalscrollbar" storyboard.targetproperty="opacity" to="1" duration="0"/> <doubleanimation storyboard.targetname="horizontalscrollbar" storyboard.targetproperty="opacity" to="1" duration="0"/> </storyboard> </visualstate> <visualstate x:name="notscrolling"> </visualstate> </visualstategroup> <visualstategroup x:name="verticalcompression"> <visualstate x:name="noverticalcompression"/> <visualstate x:name="compressiontop"/> <visualstate x:name="compressionbottom"/> </visualstategroup> <visualstategroup x:name="horizontalcompression"> <visualstate x:name="nohorizontalcompression"/> <visualstate x:name="compressionleft"/> <visualstate x:name="compressionright"/> </visualstategroup> </visualstatemanager.visualstategroups> <grid margin="{templatebinding padding}"> <scrollcontentpresenter x:name="scrollcontentpresenter" content="{templatebinding content}" contenttemplate="{templatebinding contenttemplate}"/> <scrollbar x:name="verticalscrollbar" ishittestvisible="false" height="auto" width="5" horizontalalignment="right" verticalalignment="stretch" visibility="{templatebinding computedverticalscrollbarvisibility}" istabstop="false" maximum="{templatebinding scrollableheight}" minimum="0" value="{templatebinding verticaloffset}" orientation="vertical" viewportsize="{templatebinding viewportheight}" /> <scrollbar x:name="horizontalscrollbar" ishittestvisible="false" width="auto" height="5" horizontalalignment="stretch" verticalalignment="bottom" visibility="{templatebinding computedhorizontalscrollbarvisibility}" istabstop="false" maximum="{templatebinding scrollablewidth}" minimum="0" value="{templatebinding horizontaloffset}" orientation="horizontal" viewportsize="{templatebinding viewportwidth}" /> </grid> </border> </controltemplate> </setter.value> </setter> </style> </grid.resources> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition/> <columndefinition width="auto"/> </grid.columndefinitions> <scrollviewer x:name="scrollviewer" grid.column="0" grid.columnspan="3" style="{staticresource scrollviewerwithcompressionstyle}" contenttemplate="{templatebinding contenttemplate}" content="{templatebinding content}" horizontalscrollbarvisibility="{templatebinding horizontalscrollbarvisibility}" verticalscrollbarvisibility="{templatebinding verticalscrollbarvisibility}" /> <contentcontrol grid.column="0" grid.columnspan="1" canvas.zindex="2" visibility="{templatebinding arrowsvisiblity}" horizontalalignment="left"> <image x:name="leftimage" source="{templatebinding leftimagesource}" visibility="{templatebinding leftimagevisibility}" stretch="uniformtofill" height="50"/> </contentcontrol> <contentcontrol grid.column="2" grid.columnspan="1" canvas.zindex="2" visibility="{templatebinding arrowsvisiblity}" horizontalalignment="right"> <image x:name="rightimage" source="{templatebinding rightimagesource}" visibility="{templatebinding rightimagevisibility}" stretch="uniformtofill" height="50"/> </contentcontrol> </grid> </controltemplate> </setter.value> </setter> </style>
i trying assign style by
var temp= (style)application.current.resources["customscrollviewerstyle"]; this.style = temp;
here getting value of temp variable null "customscrollviewerstyle". when use "custombuttonstyle" getting style object. why there difference in these 2 styles, both of them placed in same file(app.xaml)? or issue within "customscrollviewerstyle". did noticed these kind of issue earlier?
note
this ported code windows phone 8.
Comments
Post a Comment