xaml - Exchange default ControlTemplate for control -


i want modify controltemplate appbarbutton items. possible in onlaunched() or somewhere else?

windows.ui.xaml.controls.appbarbutton.templateproperty = windows.ui.xaml.application.current.resources["defaultappbarbuttoncontroltemplate"] windows.ui.xaml.controls.controltemplate; 

the code above doesn't work (read property), should demonstrate, i'm trying do. overwriting complete style work, overwriting controltemplate too? can't use custom control in case.

if want apply style controls in app of same type, create style without x:key attribute , place in application.resources or in resourcedictionary referenced there.

as sample, i've taken default style appbarbutton , changed place of label , icon. did remove other property setters , changed template. xaml style properties overwritten in order loaded: first system defaults , application resources, followed page/control resources , inline styles. since i'm defining template property, other style properties (e.g. foreground) remain default system ones.

sample xaml style of appbarbutton invert text , icon position:

<application.resources>     <style targettype="appbarbutton">         <setter property="template">             <setter.value>                 <controltemplate targettype="appbarbutton">                     <grid                         x:name="root"                         minwidth="{templatebinding minwidth}"                         maxwidth="{templatebinding maxwidth}"                         background="{templatebinding background}">                         <textblock                             x:name="overflowtextlabel"                             margin="12,0,12,0"                             padding="0,5,0,7"                             horizontalalignment="stretch"                             verticalalignment="top"                             fontfamily="{templatebinding fontfamily}"                             fontsize="15"                             foreground="{templatebinding foreground}"                             text="{templatebinding label}"                             textalignment="left"                             texttrimming="clip"                             textwrapping="nowrap"                             visibility="collapsed" />                          <stackpanel x:name="contentroot" minheight="{themeresource appbarthemecompactheight}">                             <textblock                                 x:name="textlabel"                                 margin="0,0,0,6"                                 fontfamily="{templatebinding fontfamily}"                                 fontsize="12"                                 foreground="{templatebinding foreground}"                                 text="{templatebinding label}"                                 textalignment="center"                                 textwrapping="wrap" />                             <contentpresenter                                 x:name="content"                                 height="20"                                 margin="0,14,0,4"                                 horizontalalignment="stretch"                                 automationproperties.accessibilityview="raw"                                 content="{templatebinding icon}"                                 foreground="{templatebinding foreground}" />                          </stackpanel>                           <visualstatemanager.visualstategroups>                             <visualstategroup x:name="applicationviewstates">                                 <visualstate x:name="fullsize" />                                 <visualstate x:name="compact">                                     <storyboard>                                         <objectanimationusingkeyframes storyboard.targetname="textlabel" storyboard.targetproperty="visibility">                                             <discreteobjectkeyframe keytime="0" value="collapsed" />                                         </objectanimationusingkeyframes>                                     </storyboard>                                 </visualstate>                                 <visualstate x:name="overflow">                                     <storyboard>                                         <objectanimationusingkeyframes storyboard.targetname="contentroot" storyboard.targetproperty="visibility">                                             <discreteobjectkeyframe keytime="0" value="collapsed" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="overflowtextlabel" storyboard.targetproperty="visibility">                                             <discreteobjectkeyframe keytime="0" value="visible" />                                         </objectanimationusingkeyframes>                                     </storyboard>                                 </visualstate>                                 <visualstate x:name="overflowwithtogglebuttons">                                     <storyboard>                                         <objectanimationusingkeyframes storyboard.targetname="contentroot" storyboard.targetproperty="visibility">                                             <discreteobjectkeyframe keytime="0" value="collapsed" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="overflowtextlabel" storyboard.targetproperty="visibility">                                             <discreteobjectkeyframe keytime="0" value="visible" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="overflowtextlabel" storyboard.targetproperty="margin">                                             <discreteobjectkeyframe keytime="0" value="38,0,12,0" />                                         </objectanimationusingkeyframes>                                     </storyboard>                                 </visualstate>                             </visualstategroup>                             <visualstategroup x:name="commonstates">                                 <visualstate x:name="normal">                                     <storyboard>                                         <pointerupthemeanimation storyboard.targetname="overflowtextlabel" />                                     </storyboard>                                 </visualstate>                                 <visualstate x:name="pointerover">                                     <storyboard>                                         <objectanimationusingkeyframes storyboard.targetname="root" storyboard.targetproperty="background">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontrolhighlightlistlowbrush}" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="content" storyboard.targetproperty="foreground">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontrolhighlightaltbasehighbrush}" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="textlabel" storyboard.targetproperty="foreground">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontrolhighlightaltbasehighbrush}" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="overflowtextlabel" storyboard.targetproperty="foreground">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontrolhighlightaltbasehighbrush}" />                                         </objectanimationusingkeyframes>                                         <pointerupthemeanimation storyboard.targetname="overflowtextlabel" />                                     </storyboard>                                 </visualstate>                                 <visualstate x:name="pressed">                                     <storyboard>                                         <objectanimationusingkeyframes storyboard.targetname="root" storyboard.targetproperty="background">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontrolhighlightlistmediumbrush}" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="content" storyboard.targetproperty="foreground">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontrolhighlightaltbasehighbrush}" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="textlabel" storyboard.targetproperty="foreground">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontrolhighlightaltbasehighbrush}" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="overflowtextlabel" storyboard.targetproperty="foreground">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontrolhighlightaltbasehighbrush}" />                                         </objectanimationusingkeyframes>                                         <pointerdownthemeanimation storyboard.targetname="overflowtextlabel" />                                     </storyboard>                                 </visualstate>                                 <visualstate x:name="disabled">                                     <storyboard>                                         <objectanimationusingkeyframes storyboard.targetname="content" storyboard.targetproperty="foreground">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontroldisabledbasemediumlowbrush}" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="textlabel" storyboard.targetproperty="foreground">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontroldisabledbasemediumlowbrush}" />                                         </objectanimationusingkeyframes>                                         <objectanimationusingkeyframes storyboard.targetname="overflowtextlabel" storyboard.targetproperty="foreground">                                             <discreteobjectkeyframe keytime="0" value="{themeresource systemcontroldisabledbasemediumlowbrush}" />                                         </objectanimationusingkeyframes>                                     </storyboard>                                 </visualstate>                             </visualstategroup>                             <visualstategroup x:name="inputmodestates">                                 <visualstate x:name="inputmodedefault" />                                 <visualstate x:name="touchinputmode">                                     <visualstate.setters>                                         <setter target="overflowtextlabel.padding" value="0,11,0,13" />                                     </visualstate.setters>                                 </visualstate>                             </visualstategroup>                         </visualstatemanager.visualstategroups>                     </grid>                 </controltemplate>             </setter.value>         </setter>     </style> </application.resources> 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -