sourcechord / FluentWPF

Fluent Design System for WPF.
MIT License
1.43k stars 111 forks source link

Class library exception issue #74

Open nima70 opened 5 years ago

nima70 commented 5 years ago

Hi I used the package in a normal WPF application. And It worked fine. Now I 'm trying to set up the package inside a class library. But I m getting the following exception.

System.Windows.Markup.XamlParseException HResult=0x80131501 Message=The invocation of the constructor on type 'SourceChord.FluentWPF.ResourceDictionaryEx' that matches the specified binding constraints threw an exception. Source=PresentationFramework StackTrace: at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) at V4.WPF.GUI.MainWindow.InitializeComponent() in D:\Vitrox\V4_x64\V4.WPF.GUI\MainWindow.xaml:line 1

Inner Exception 1: TypeInitializationException: The type initializer for 'SourceChord.FluentWPF.SystemTheme' threw an exception.

Inner Exception 2: NullReferenceException: Object reference not set to an instance of an object.

" at SourceChord.FluentWPF.ThemeHandler..ctor()\r\n at SourceChord.FluentWPF.SystemTheme..ctor()\r\n at SourceChord.FluentWPF.SystemTheme..cctor()"

The exception is being occurred at SystemTheme. The inner exception is

"Object reference not set to an instance of an object."

FluentDesign exception

Does anyone have any idea on how to resolve this problem?

Thanks and have a great day.

sourcechord commented 4 years ago

Hi, @nima70

Sorry for responding so late. I couldn't reproduce it. Please tell me more information.

By the way, FluentWPF needs some ResourceDictionaries. (See also preparation)

If you use FluentWPF in class library, you have to load the ResourceDictionary manualy.

For example, like this in class library.

var dict = new ResourceDictionary();
dict.Source = new Uri("pack://application:,,,/FluentWPF;component/Styles/Controls.xaml");
Application.Current.Resources.MergedDictionaries.Add(dict);

Please try it.

nima70 commented 4 years ago

Hi I added the mentioned code inside my Window code behind . code behind Here is the exception I get exception

milanLavic commented 3 years ago

Hey @nima70 , did you figure it out? I'm trying to use it in a class library, and I have the same problem.