Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Do StaticResource items support multiple levels of value references?

$
0
0

I'd like to define primary palette colors, then assign those values to individual element colors, and finally assign the element colors to style properties in my App.xaml ResourceDictionary.

Is it possible to have something like this in a resource dictionary? I've tried multiple things that either won't compile, or compile without warnings or errors but don't work at runtime.

I'm going to simplify the setup to avoid the problem for now, but I would like to know if there is a way for this to be done. Thanks!

<prism:PrismApplication ...>
    <Application.Resources>
        <ResourceDictionary>
            <!-- Styling: Base Colors -->
            <Color x:Key="PrimaryColor">#000000</Color>
            <Color x:Key="SecondaryColor">#ffffff</Color>

            <!-- Element Colors -->
            <Color x:Key="ButtonBackgroundColor" x:Value="{StaticResource PrimaryColor}" />
            <Color x:Key="ButtonTextColor" x:Value="{StaticResource SecondaryColor}" />

            <!-- Also tried x:Value="{x:Static PrimaryColor}". Both compile, neither work. -->

            <!-- Also tried <Color x:Key="ButtonBackgroundColor">{StaticResource PrimaryColor}</Color>,
            <!-- <Color x:Key="ButtonBackgroundColor">"{StaticResource PrimaryColor}"</Color>,
            <!-- <Color x:Key="ButtonBackgroundColor">{x:Static PrimaryColor}</Color> and
            <!-- <Color x:Key="ButtonBackgroundColor">"{x:Static PrimaryColor}"</Color>.
            <!-- None of these options will compile.

            <!-- Element Styles -->
            <Style TargetType="Button">
                <!-- These setters compile but don't work at runtime. -->
                <!-- The value settings have to refer directly to PrimaryColor and SecondaryColor for the setters to work. -->
                <Setter Property="BackgroundColor" Value="{StaticResource ButtonBackgroundColor}" />
                <Setter Property="TextColor" Value="{StaticResource ButtonTextColor}" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</prism:PrismApplication>

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>