2

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!

Community
  • 1
  • 1
kshitijgandhi
  • 1,532
  • 1
  • 16
  • 28

2 Answers2

1

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

ZeeMoussa
  • 173
  • 10
  • Could you please elaborate?? – kshitijgandhi Dec 08 '15 at 10:27
  • 1
    When you Compile a dll with xaml file in it, it Converts in into xbf files those files must be copied as well to the bin directory of your app with relative path – ZeeMoussa Dec 08 '15 at 11:26
  • 1
    Check your bin Folder when you compile your DLL you will get what I mean – ZeeMoussa Dec 08 '15 at 11:27
  • 1
    You can Add your DLL as a Project reference in the project this will solve the problem, since it will copy all the bin Content folder automatically, – ZeeMoussa Dec 08 '15 at 11:28
  • I think I understand what you are saying. Could you also tell me whether this was the case with Windows Phone 8, as I have used UserControl before from class library in WP8 and it worked fine. – kshitijgandhi Dec 10 '15 at 05:59
1

I think that this post is just as yours.. :

https://social.msdn.microsoft.com/Forums/en-US/63f071be-a3c5-4f2d-ace2-73ca750e3252/rtm-usercontrol-class-library-and-assembly-name-with-

And, It's known issue:

Dot in the project's name cause XAMLParseException

I hope that this will help you in your issue..

Nasser AlNasser
  • 1,725
  • 2
  • 11
  • 12