Iris Classon
Iris Classon - In Love with Code

Example Windows Store App & Portable Class Library: How to access and use PCL resources

I’m currently working on a crossplatform app targeting Windows Store Apps and WP8. For this project I’m using a Portable Class Library so I can share the code. I’m using MVVM pattern, the Model and the ViewModels are in the PCL, while the separate projects have only Views and Adapters(for the things that differ such as file access). I came across a scenario where I needed to access some resources in the PCL, and although I ended up resolving the code in the PCL itself, I realized quite a few are wondering how can you access files in the PCL from another project, so I’ve made a very simple example to show you how to do that. Basically we use reflection and embedded resources. Just remember that embedded resources cant be modified directly.

Lets start from the start. Start a new PCL project.

.

Select targeted platforms.

.

Add a Windows Store Apps blank app project.

.

Delete the cs file in the PCL and add a XML document.

.

.

Add some elements.

Set the document as embedded resource (IMPORTANT)

.

Add a reference to the PCL from the Windows Store App

.

.

Add The View

.

Create a Class to match the document. Hook into the resource in the PCL.

.

Run the App.

.

Comments

Leave a comment below, or by email.


Last modified on 2012-11-01

comments powered by Disqus