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

ResourceDictionary.MergedWith not loading the merged dictionary

$
0
0

I created a new ResourceDictionary XAML file:

<!--MyResources.xaml-->
?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary  xmlns="http://xamarin.com/schemas/2014/forms"
                                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    x:Class="App4.MyResources">
    <Color x:Key="Color1">Aqua</Color>
</ResourceDictionary>

App4.MyResources is declared as:

public partial class MyResources : ResourceDictionary { ... }

In the ContentPage, I'm attempting to merge the MyResources dictionary with the local ContentPage's resources dictionary as follows:

<!--MainPage.xaml is of type ContentPage-->
<ContentPage.Resources>
  <ResourceDictionary MergedWith="local:MyResources">
    <Style x:Key="MyEntryStyle" TargetType="Entry">
      ...
    </Style>

    <Style x:Key="AnotherStyle">...</Style>
  </ResourceDictionary>
</ContentPage.Resources>

Finally, in the same ContentPage when I try to use the Color1 resource from the merged dictionary, it won't load. {StaticResource} gives me an error and {DynamicResource} does not work.

<Button Text="Test" TextColor="{DynamicResource Color1}" />

I included in my code example a simple Color object, but I've tried with <Style> objects too and I can't use them.

In debug mode, the ContentPage.Resources object shows the MergedWith property correctly set, but the Keys property only has 2 keys (the ones from the MainPage.xaml). Attached you can find the Watch Window with the this.Resources inspection.

Is this a bug?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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