0

I'm looking for a way to use one color in a ResourceDictionary with a few different keys, for organisation (and copy-paste prevention). What I tried to do but didn't work is almost exactly this:

<?xml version="1.0" encoding="UTF-8"?>
<Application
  xmlns="http://xamarin.com/schemas/2014/forms"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  x:Class="Testing.TestApp"
  >
  <Application.Resources>
    <ResourceDictionary>
      <Color x:Key="TextColor">#212121</Color>
      <Color x:Key="BackgroundColor">#FFFFFF</Color>

      <Color x:Key="TextColorInactive">#757575</Color>
      <Color x:Key="BackgroundColorInactive">#E0E0E0</Color>

      <!-- COLORS - BUTTONS -->
      <Color x:Key="TextColorButton">{StaticResource TextColor}</Color>
      <Color x:Key="BackgroundColorButton">#F5F5F5</Color>

      <Color x:Key="TextColorButtonInactive">{StaticResource TextColorInactive}</Color>
      <Color x:Key="BackgroundColorButtonInactive">{StaticResource BackgroundColorInactive}</Color>

      <!-- STYLES -->
      <Style TargetType="Button">
        <Setter Property="BackgroundColor" Value="{StaticResource BackgroundColorButton}" />
        <Setter Property="TextColor" Value="{StaticResource TextColorButton}" />
      </Style>
      <Style x:Key="ButtonInactive" TargetType="Button">
        <Setter Property="BackgroundColor" Value="{StaticResource BackgroundColorButtonInactive}" />
        <Setter Property="TextColor" Value="{StaticResource TextColorButtonInactive}" />
      </Style>
    </ResourceDictionary>
  </Application.Resources>
</Application>

Is there a way of doing this?

EDIT: I want to do this with as little code behind as possible, preferably just in XAML.

Willem
  • 317
  • 2
  • 11
  • 1
    You can use `SolidColorBrushes` for the button colors. There you can set colors as `StaticResource`. – bars222 Feb 16 '16 at 08:16
  • 1
    Possible duplicate of [Is it possible to point one Color resource to another Color resource in Xamarin.Forms?](http://stackoverflow.com/questions/35042013/is-it-possible-to-point-one-color-resource-to-another-color-resource-in-xamarin) – JKennedy Feb 16 '16 at 08:43
  • @bars222 Would brushes also work for text? – Willem Feb 16 '16 at 08:49
  • @user1 Yes, that questions is similar but the answer not acceptable to me. I'll further specify my question to make it distinctive. – Willem Feb 16 '16 at 08:52
  • @bars222 `SolidColorBrushes` are not available in `Xamarin.Forms`. @willem due to the limitation of `Xamarin.Forms` the two answers to that question will be the only way it will be possible. To clarify; using `Xamarin.Forms` this is not possible in pure Xaml – JKennedy Feb 16 '16 at 08:54

0 Answers0