c# - Inheriting Styles in WPF -


i have following code in mainwindow.xaml follows josh smith's mvvm workspace model.

<grid grid.row="1"        grid.rowspan="2">     <contentcontrol         content="{binding}"          contenttemplate="{staticresource workspacetemplate}">     </contentcontrol> </grid> 

where workspace template

<datatemplate x:key="workspacetemplate">     <tabcontrol x:name="tabcontrol"                  issynchronizedwithcurrentitem="true"                  itemssource="{binding workspaces}"                  selectedindex="{binding selectedindex}"                 horizontalcontentalignment="stretch"                  verticalcontentalignment="stretch"                  horizontalalignment="stretch"                  verticalalignment="stretch"                  tabstripplacement="top"                  margin="5,0,5,0">         <tabcontrol.itemcontainerstyle>             <style targettype="tabitem">                 <setter property="header" value="{binding path=displayname}"/>                 <setter property="horizontalcontentalignment" value="stretch"/>                 <setter property="verticalcontentalignment" value="stretch"/>             </style>         </tabcontrol.itemcontainerstyle>     </tabcontrol> </datatemplate> 

now have created tabcontrol style close button contained in seperate resource dictionary. code like

<style x:key="studiotabcontrol" targettype="{x:type tabcontrol}">     <style.resources>         <style x:key="studiotabitem" targettype="{x:type tabitem}">             <setter property="focusvisualstyle" value="{x:null}"/>             <setter property="background" value="transparent"/>             <setter property="template">                 <setter.value>                     <controltemplate targettype="{x:type tabitem}">                         <grid height="20"                                background="{templatebinding background}"                                snapstodevicepixels="true">                             <grid.columndefinitions>                                 <columndefinition width="auto"/>                                 <columndefinition width="35"/>                             </grid.columndefinitions>                             <contentpresenter grid.column="0"                                                margin="10,0,10,0"                                                horizontalalignment="center"                                                verticalalignment="center"                                                contentsource="header" />                             <button grid.column="1"                                      width="15"                                      height="15"                                      horizontalalignment="center"                                      verticalalignment="center"                                      dockpanel.dock="right">                             ... ect. 

the question how can inherite studiotabcontrol style <datatemplate x:key="workspacetemplate"> definiation. have tried

<datatemplate x:key="workspacetemplate">     <tabcontrol x:name="tabcontrol"                  itemssource="{binding workspaces}"                  selectedindex="{binding selectedindex}"                 style="{staticresource studiotabcontrol}"                 ... ect. 

but due fact specify <tabcontrol.itemcontainerstyle>... in <datatemplate x:key="workspacetemplate"> definiation style not work. how can studiotabitem style work existing workspacetemplate?

thanks time.

the resource defined in resources of element can used inside element style defined in tabcontrol.style not available outside , hence won't applied.

so in order use style take out of tabcontrol.style i.e. define in parallel tabcontrol style in resource dictionary.

secondly if have defined style key not applied automatically. have apply explicitly using {staticresource=key}.

once define outside tabcontrol.style, can inherit using basedon keyword in itemcontainerstyle like

<style targettype="{x:type tabitem}" basedon="{staticresource studiotabitem}"> 

thanks


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -