Add Icon on WPF

43 Views Asked by At

I'm building a WPF Project with .Net WPF Framework 4.7.2. I'm trying to use MaterialDesign library so I have this App.xaml file:

<Application x:Class="DesfireCodificatoreWPF.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:materialDesign="https://materialdesigninxaml.net/winfx/xaml/themes"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <ResourceDictionary>
        <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.DeepPurple.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
</Application>

But it says that it can't load the file or the assembly 'MaterialDesign...' I can't understand why. I already installed MaterialDesignThemes.Wpf and MaterialDesignColors

2

There are 2 best solutions below

0
Hui Liu-MSFT On

@Francesco Vargas. I encountered a problem when testing. Cannot locate resource 'themes/materialdesigntheme.defaults.xaml'. enter image description here I saw an error message on the nuget package, and I am not sure if it is an error with the nuget package.

If you also have this error message, It is recommended you try raising a question in the materialdesigntheme forum to see if it is a package error.

enter image description here

0
Scott P On

If you downloaded the package recently, there were some breaking changes and the quick start examples haven't quite caught up.

You may need to migrate to v2 or v3 of the MaterialDesign style.

There is a migration guide here: https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/discussions/3466

This XAML worked for me in setting up resources for version 2:

     <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="DeepPurple" SecondaryColor="Lime" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign2.Defaults.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>