Question

app.xaml

<Application.Resources>
    <local:AppBootstrapper xmlns:local="clr-namespace:Kyms" x:Key="Bootstrapper" />
    <local:LocalizedStrings xmlns:local="clr-namespace:Kyms" x:Key="LocalizedStrings"/>
    <ResourceDictionary x:Key="CustomDictionary">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Styles/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

my resource in a Styles/Styles.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">


<Style x:Key="MyColorButton" TargetType="Button">
   .......
</Style>

In ViewModel (use caliburn micro MVVM Pattern) if i call this code

App.Current.Resources.MergedDictionaries[0]

App.Current.Resources.MergedDictionaries.Count = 0

but not it works, why?

Was it helpful?

Solution

I'm resolved

in my AppBootstrapper.cs i'm insert

 private void LoadDictionary()
    {
        var dictionaries = App.Current.Resources.MergedDictionaries;
        dictionaries.Clear();

        var themeStyles = new ResourceDictionary { Source = new Uri("/MyAssemblyName;component/Styles/Styles.xaml", UriKind.RelativeOrAbsolute) };
        dictionaries.Add(themeStyles);
    }

And it works!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top