Search code examples
windows-8windows-store-appswindows-8.1windows-10uwp

XamlParseException when using UserControl from class library dll


I have created a library which has a Popup UserControl similar to the one here.

When I create a fresh Universal Windows App and create the same UserControl inside an app and open the popup, it opens.

But if I create a Class Library and create the same UserControl inside it and try to use it (by opening the popup) inside an app, I get a XamlParseException.

It is as follows -

Windows.UI.Xaml.Markup.XamlParseException occurred
HResult=-2144665590
Message=XAML parsing failed.
Source=Windows
StackTrace:
at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation)
at PopupTestLibrary.MyUserControl1.InitializeComponent()

I am not able to understand exactly why this is happening, since the code works fine when not called from an external class library.

Some Questions I found to be similar to mine, here on SO -

XamlParseException when consuming a Page from a library

Cannot instantiate UserControl from another assembly

All help is appreciated!


Solution

  • You need to Add a Resource Dictionary in your App and Add the Usercontrol Xaml content to it

    as Xaml is Considered as a Content file not compiled into the code