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
Post a Comment