c# - Portable XAML Styles in a Class Library -


so have application style put directly app.xaml file such:

<application x:class="test.app"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              startup="onstartup">     <application.resources>         <style x:key="specialbuttonstyle" targettype="button">             <setter property="content" value="{binding relativesource={relativesource templatedparent}, path=content}" />             <setter property="overridesdefaultstyle" value="true"/>             <setter property="background" value="{binding relativesource={relativesource templatedparent}, path=background}" />             <setter property="borderthickness" value="2" />             <setter property="borderbrush" value="{binding relativesource={relativesource templatedparent}, path=background}" />             <setter property="foreground" value="white" />             <setter property="block.foreground" value="white" />             <setter property="textblock.foreground" value="white" />             <setter property="textelement.foreground" value="white" />             <setter property="fontweight" value="bold" />             <style.triggers>                 <trigger property="ismouseover" value="false">                     <setter property="template">                         <setter.value>                             <controltemplate targettype="{x:type button}">                                 <border background="{templatebinding background}" padding="{binding relativesource={relativesource templatedparent}, path=borderthickness}">                                     <border background="{templatebinding borderbrush}">                                         <contentcontrol foreground="white">                                             <contentpresenter horizontalalignment="center" verticalalignment="center"/>                                         </contentcontrol>                                     </border>                                 </border>                             </controltemplate>                         </setter.value>                     </setter>                 </trigger>             </style.triggers>         </style>     </application.resources> </application> 

i want include style in class library, xaml projects reference library can see "specialbuttonstyle" selectable "style" in designer. i've read several articles resourcedictionaries , creating portable xaml controls, i'm still confused. want collection of styles included part of class library.

(i can post 2 links until higher stackoverflow reputation) http://timheuer.com/blog/archive/2012/03/07/creating-custom-controls-for-metro-style-apps.aspx

http://visualstudiomagazine.com/articles/2015/03/01/everyone-gets-xaml-with-xamarinforms.aspx

any appreciated. thanks!

what read correct.

what need create plain resourcedictionary inside shared assembly given name.

in app.xaml can include resourcedictionary mergeddictionary , therefore whole app have access of shared dictionaries resources.

steps:

  1. create project wpf control library project (doesn't matter user or custom)
  2. in new project right click -> add -> resourcedictionary
  3. paste style in looks following:

dictionary1.xaml

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">     <style x:key="specialbuttonstyle" targettype="button">         <setter property="content" value="{binding relativesource={relativesource templatedparent}, path=content}" />         <setter property="overridesdefaultstyle" value="true"/>         <setter property="background" value="{binding relativesource={relativesource templatedparent}, path=background}" />         <setter property="borderthickness" value="2" />         <setter property="borderbrush" value="{binding relativesource={relativesource templatedparent}, path=background}" />         <setter property="foreground" value="white" />         <setter property="block.foreground" value="white" />         <setter property="textblock.foreground" value="white" />         <setter property="textelement.foreground" value="white" />         <setter property="fontweight" value="bold" />         <style.triggers>             <trigger property="ismouseover" value="false">                 <setter property="template">                     <setter.value>                         <controltemplate targettype="{x:type button}">                             <border background="{templatebinding background}" padding="{binding relativesource={relativesource templatedparent}, path=borderthickness}">                                 <border background="{templatebinding borderbrush}">                                     <contentcontrol foreground="white">                                         <contentpresenter horizontalalignment="center" verticalalignment="center"/>                                     </contentcontrol>                                 </border>                             </border>                         </controltemplate>                     </setter.value>                 </setter>             </trigger>         </style.triggers>     </style> </resourcedictionary> 
  1. in main project reference new control library
  2. in app.xaml reference dictionary1.xaml

app.xaml

<application x:class="wpfapplication1.app" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                   startupuri="nestedxamlobjects.xaml">     <application.resources>         <resourcedictionary>             <resourcedictionary.mergeddictionaries>                 <resourcedictionary source="pack://application:,,,/wpfcontrollibrary1;component/dictionary1.xaml" />             </resourcedictionary.mergeddictionaries>         </resourcedictionary>     </application.resources> </application> 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -