Sorry for the duplicate, but my low reputation does not allow me to comment on posts.
i am trying to use MaterialDesignXamlToolkit with WPF with class library, exactly as in this post: How to include MaterialDesignXamlToolkit to WPF class library?
-so i installed Material Design nuGet and added ResourceDictionary named MaterialDesign.xaml, where I copied and paste this code:
<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.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
then I created a new WPF page where I added Resource, so my xaml looks like this:
<Page x:Class="test.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:test"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="Page1"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}">
<Page.Resources>
<ResourceDictionary Source="/MyAsembly;component/ResourceDictionary/MaterialDesign.xaml" />
</Page.Resources>
<Grid>
<materialDesign:Card Padding="32" Margin="16">
<TextBlock Style="{DynamicResource MaterialDesignTitleTextBlock}">My First Material Design App</TextBlock>
</materialDesign:Card>
</Grid>
Of course I got an error: The resource {MaterialDesignBody, MaterialDesignPaper, MaterialDesignFont} could not be resolved
as @Marija Rakic mentions in the post, I dried to add dummy lines to my Page1.xaml.cs class
using MaterialDesignColors;
using MaterialDesignThemes.Wpf;
using System.Windows.Controls;
namespace test
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
public Page1()
{
ColorZoneAssist.SetMode(new GroupBox(), ColorZoneMode.Accent);
Hue hue = new Hue("name", System.Windows.Media.Color.FromArgb(1, 2, 3, 4), System.Windows.Media.Color.FromArgb(1, 5, 6, 7));
InitializeComponent();
}
}
}
but it didn't help. The error was still there. So I tried @Trygve solution and created one more class named MaterialDesign.xaml.cs where I added an assembly
using System.IO;
using System.Reflection;
using System.Windows;
namespace test
{
partial class MaterialDesign: ResourceDictionary
{
public MaterialDesign() {
Assembly.LoadFrom(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "MaterialDesignThemes.Wpf.dll"));
Assembly.LoadFrom(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "MaterialDesignColors.dll"));
InitializeComponent();
}
}
}
and added a reference to MaterialDesign.xaml:
x:Class="test.MaterialDesign"
but it also didn't work and mentioned error is still there.I don't know where I'm making a mistake ..