XamlParseException when using UserControl from class library dll - windows-8

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!

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

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..

Related

UWP Using Pages from different Project

Is it possible to have all pages in a different project from where the app.xaml/cs is in?
I tested this by creating a new "Class Library (Universal Windows)" or "Windows Runtime Component" project, then I created the new pages in those projects.
After I add this project as a reference to the main UWP app and call the page(s) in the "rootFrame.Navigate(typeof(MainShellView), e.Arguments)" I get the exception
system.accessviolationexception attempted to read or write protected memory
Is it possible to have the pages, controls in different projects than the UWP main project and use them as references?
You will need to keep an empty/dummy MainPage.xaml page in the main project as there is a hard-coded reference to it in the project system. With that in place you can load all your pages (incl. the initial start page) from other projects that you are referencing in the solution.
I will log a bug on the hard-coded dependency on the existence of "MainPage.xaml". Thanks for reporting!

Can I ignore Xamarin.Forms error warnings in XAML code if the app still works?

I am using the latest stable build of Xamarin Forms (2.3.4.247), and I'm getting errors (in the form of green underlining) in my XAML code.
One of the errors, "The type 'ContentPage' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built", seems to be a bug according to here, although this link talks about a much older version. When I rebuild the solution the green underlining and error messages disappear (until I edit the XAML page, and the errors reappear)
Another error I get is "The Page is not usable as an object element because it is not public or doesn't define a public parameterless constructor or type converter". This error also disappears after a rebuild, but then reappears when I start editing the file.
The app works as intended on both Windows and Android (can't test IOS for now). Should I just ignore these errors?
On the second error, I am passing an object to the base constructor of my XAML page (that is not related to layout in anyway). Is this a problem?
My XAML class layout looks something like this:
public partial class BaseView : ContentPage { public BaseView(Obj obj) {}}
public partial class SubPage: BaseView { public SubPage(Obj ob) : base(obj) {}}
If I add parameterless overloads of the constructor, I get the same error message. Having read a bit on Google it seems that this error (the second one I mention) will stop any of the XAML from the child page being drawn. If there is a way to have XAML page hierarchies that can add their own objects to a parent, I would prefer that (i.e. I would like the child page's XAML to be drawn).
===== EDIT
It looks like Xamarin officially suggests passing data between pages via the page constructor HERE. This directly contradicts that warning messages should be avoided (at least that is what I have always thought).

Windows Phone 8.1 File Picker UnauthorizedAccessException

I have a problem trying to replicate the File Picker example in link, I create a new application using a Universal Application Windows store template.
I extract the content of the class Scenario02 and create a similar one in my example. This class implements an interface called IFileOpenPickerContinuable which I extract from the class ContinuationManager and create a file in my project with the same name to implement that interface.
I don't get any compilation errors when I run the application. When the line openPicker.PickMultipleFilesAndContinue(); is executed, it throw a exception.
'UnauthorizedAccessException'(Access is denied. Exception from HRESULT: 0x80070005) exception.
In the Microsoft example they don't modify any of the manifests of the application. Do you know what can I be missing?
(Question solved in a question edit. Converted to a community wiki answer.)
The OP wrote:
Solved! The problem was trying to launch the data picker in the class constructor.

navigationservice.navigate not available on the vs2013 project

I have two page application and the main page is default is "MainPage.xaml" and the second one is "AddPerson.xaml" when user click a button on main page I want the app to take user to "AddPerson" page.
And I wrote following for the Click event of the button
Me.Frame.Navigate(System.Type.GetType("AddPerson.xaml"))
and I am getting the following error
An exception of type 'System.NullReferenceException' occurred in MedicineSchedule.exe but was not handled in user code
Additional information: Object reference not set to an instance of an object.
If there is a handler for this exception, the program may be safely continued.
I tried other method of navigationservice.navigate which I cannot find the class in VS2013 express at all. The only method available is Me.Frame.Navigate in my project, please let me know how I can get this simple thing to work.
If it was .net 2.0 I would simple called new form with form.lod or something similar.
This doesn't work?
this.Frame.Navigate(typeof(AddPerson));
If you want/have to use a string take a look at the reply here:
convert string to type of page

Using ResourceDictionary from a DLL in Windows 8

How can I use the ResourceDictionary resource from the same DLL?
Basically I am trying to create a UI library with all classes derived from Page class. I want to keep all user interface pages in the same DLL.
To see the problem, from VS2012, create a Windows 8 library project, then add the Item Detailed Page. Now, if you open the created page from the editor, you will get some errors like "The resource "LayoutRootStyle" could not be resolved".
This is just a Xaml Designer error, so that will not prevent your project from building or running .
The only thing needed is that all the ResourceDictonary need to be referenced by the main application App.xaml (for example by using <ResourceDictionary Source="/<myLibraryName>/Common/StandardStyles.xaml"/> or by creating calling an Init method in the Library which will dynamically add the Resource dictionary).
A quick workaround for the error in the Xaml Designer is to just copy an App.xaml/App.xaml.cs in your library (but at runtime the main application will still need to have a reference on the needed ResourceDictionary since the App.xaml of the library will not be used).
Another posibility is to just add a refrence on the ResourceDictionary on each page but I believe that will be much more costly since it will create an instance of the dictionary for each page.