Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How do I reference one XAML MergedDictionary from another?

$
0
0

I am struggling with XAML Merged Dictionaries. Is it possible to get something like the following working?

File Colours.xaml contains this:

<?xml version="1.0" encoding="utf-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <Color x:Key="WarningTextColour">#FF0000</Color>

</ResourceDictionary>

Another file Text.xaml contains something like this:

<?xml version="1.0" encoding="utf-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <Style x:Key="WarningTextStyle" TargetType="Label">
        <Setter Property="TextColor" Value="{StaticResource WarningTextColour}"/>
        <Setter Property="FontSize" Value="Large"/>
    </Style>
</ResourceDictionary>

Then somewhere like my main App.xaml file, I bring them together like this:

<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="myProject.Forms.App">

    <Application.Resources>
        <ResourceDictionary Source="Styles/Colours.xaml"/>
        <ResourceDictionary Source="Styles/Text.xaml"/>
    </Application.Resources>

</Application>

I've read the guides and tried various combinations of syntax, trying both the old and the new ways, but I can't find a way to do this. I am beginning to wonder if I am maybe approaching this completely the wrong way.

Even with all my XAML set to compile, the project builds okay (which is disappointing if I have something wrong), but the MainPage.xaml that tries to use the WarningTextStyle gives an exception.

Any help or advice would be very much appreciated.

Kind wishes ~ Patrick


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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