c# - Is it possible to point one Color resource to another Color resource in Xamarin.Forms? -
i building xamarin forms
application , drawing application resources
, colours.
for example have following:
<color x:key="slate">#404040</color> <color x:key="blue">#458623</color> <color x:key="selecteditemcolour">#458623</color>
as can see selecteditemcolour
same blue
.
i have tried following didn't work:
<color x:key="slate">#404040</color> <color x:key="blue">#458623</color> <color x:key="selecteditemcolour" color="{staticresource blue}"/>
i know if wpf
can answer stated here
is possible point colour resource
colour resource
in xamarin.forms?
you can use x:static
in tandem static class in order directly reference colors name. has benefits of keeping colors centralized 1 class , minimizing amount of xaml.
namespace resourcecolors { public static class colors { public static color slate = color.fromhex("#404040"); } }
<?xml version="1.0" encoding="utf-8"?> <contentpage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:resourcecolors;assembly=resourcecolors" x:class="resourcecolors.pageone"> <contentpage.resources> <resourcedictionary> <color x:key="blue">#458623</color> </resourcedictionary> </contentpage.resources> <contentpage.content> <stacklayout horizontaloptions="centerandexpand" verticaloptions="centerandexpand"> <label text="test" textcolor="{x:static local:colors.slate}" /> </stacklayout> </contentpage.content> </contentpage>
Comments
Post a Comment