Nov 012012
 
 November 1, 2012  Posted by at 10:10 pm Uncategorized, WinRT Tagged with: , , , , , ,

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.
How to access and use PCL resources
Select targeted platforms.
How to access and use PCL resources
Add a Windows Store Apps blank app project.
How to access and use PCL resources
Delete the cs file in the PCL and add a XML document.
How to access and use PCL resources

How to access and use PCL resources
Add some elements.

Set the document as embedded resource (IMPORTANT)
How to access and use PCL resources
Add a reference to the PCL from the Windows Store App
How to access and use PCL resources
How to access and use PCL resources
Add The View
How to access and use PCL resources
Create a Class to match the document. Hook into the resource in the PCL.
How to access and use PCL resources
Run the App.
How to access and use PCL resources

Sorry, the comment form is closed at this time.