0

I would like to use a theme like MaterialDesignInXamlToolkit in my new project which uses MvvmCross. (first time user)

Since I can't set Resources in a MvxApplication how should I handle this?

My App.xaml

<views:MvxApplication  
    xmlns:views="clr-namespace:MvvmCross.Platforms.Wpf.Views;assembly=MvvmCross.Platforms.Wpf"  
    x:Class="Overseer.Client.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Overseer.Client"
             StartupUri="MainWindow.xaml">
</views:MvxApplication >

Normally I would do it like this.

<Application . . .
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="DeepPurple" SecondaryColor="Lime" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
Achille Depla
  • 97
  • 1
  • 10
  • 1
    Maybe this may help : https://stackoverflow.com/questions/55056085/how-to-add-resourcedictionary-programmatically – Romka Sep 12 '21 at 17:06

1 Answers1

0

Made a ResourceDictionary file.

MaterialDesign.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Grey.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.LightBlue.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBox.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/>
    <SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/>

</ResourceDictionary>

Put it in every view separately in XAML.

<views:MvxWpfView.Resources>
    <ResourceDictionary Source="..\Themes/MaterialDesign.xaml"></ResourceDictionary>
</views:MvxWpfView.Resources>

If anybody has a way to set it globally let me know.

Achille Depla
  • 97
  • 1
  • 10
  • Did you try to set it programmatically? `Application.Current.ResourceDictionary = new ResourceDictionary() { Source = new Uri("...") };` – mm8 Sep 13 '21 at 14:41