c# - Is it possible to have a static list of Styles in Xaml -


i have static list of styles in xaml

so far have tried:

<local:styles xmlns="http://xamarin.com/schemas/2014/forms"              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"              xmlns:local="clr-namespace:myapp.core;assembly=myapp.core">   <style x:key="labelstyle" targettype="label">     <setter property="textcolor" value="green" />   </style> </local:styles> 

code behind

public partial class styles : list<style> {     public styles()     {     } } 

but when do

var styles = new styles(); 

the class empty.

as aside can't use application resources or resourcedictionary

you can place styles in resourcedictionary (add -> new item -> resource dictionary):

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">      <!-- styles here -->     <style ...  </resourcedictionary> 

don't forget need add reference in app.xaml:

<application x:class="your.app.namespace"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <application.resources>     <resourcedictionary>         <resourcedictionary.mergeddictionaries>             <resourcedictionary source="pack://application:,,,/your.app.namespace;component/path/to/dictionary.xaml"/>             ... 

to hold of these styles in code-behind, can use findresource method:

style mystyle = app.current.findresource("mystylekey") style; 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -