UWP Using Pages from different Project - xaml

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!

Related

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

Using Xamarin.Forms.Behaviors in XAML causes TargetInvocationException in iOS but not in Android

I'm doing a Xamarin.Forms app and I need to use Behaviors. I have added the Xamarin.Forms.Behaviors package to the project and added a behavior to the XAML of one page, so a command is executed when the selection of a ListView changes:
<b:Interaction.Behaviors>
<b:BehaviorCollection>
<b:EventToCommand Command="{Binding ItemSelectedCommand}" EventName="ItemSelected" />
</b:BehaviorCollection>
</b:Interaction.Behaviors>
This works nice on Android but the same project throws a TargetInvocationException when navigating to the same page under iOS. What could be causing this?
The iOS linker of Xamarin is more aggressive when stripping symbols/types that it thinks aren't used or referenced; and Xamarin.Forms XAML is usually the victim of this process.
There are two options to fix this:
- Change the stripping mode of the linker (right click on the Xamarin.iOS project -> Properties -> iOS Build tab -> Set Linker behavior to Link SDK assemblies only or Don't link). This will ensure the minimal amount of symbols (or none at all) are removed when creating the application package, the downside being that the app size will increment dramatically.
- Create a code file that manually references those types (for example creating instances that aren't used) so they aren't automatically stripped. Libraries like MvvmCross use this approach.
The latter method is the recommended although it has a bit more of work to do. The former one should be used when you are using third party libraries with lots of types that are getting stripped and it would take more work to reference all of them.

Any designer-friendly way to reference static resources inside class libraries without importing in every xaml file?

I am building a universal class library with Xaml Views that need to statically reference custom resources (StaticResource) defined inside the same class library.
How can i do that in a designer friendly way without importing the resource file inside every view?
Using VS2013 Update 3. It seems that the designer works only for views inside the specific universal app projects and when the resources are defined inside App.xaml without merging.

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.

How can I setup a project to operate like the 'Window-Based Application' project template from XCode 4.0, in 4.2+?

I'm using XCode 4.2, and I'm struggling with how to create a Single or MultiView application from an Empty Application project.
Previously, XCode had a Window-Based Application template, and it has been removed. After a bit of Googling, I found this highly indexed article that walks through the process of creating an Empty Application project, and manually setting up like the previous Window Based application template.
The problem that I am having is that the books that I own (that aren't to old) reference the Window-Based application, and even after following the instructions on the above linked tutorial, I can't get my projects to work. I'm missing something that bridges the gap between this web tutorial and the projects that are defined in the books.
Could some one either point me to a source or give a decent, high-level walkthrough on how to define a Single-View application, starting from an Empty Application project?
The "Empty project" already creates all window stuff for you. All you need to add is a UIViewController and link it in the app delegate.
To set the UIViewController you should use -[UIWindow setRootViewController:]. The UIViewController is the only part missing from the empty project that needs to be added for the application to work.