Thursday, September 6, 2012

Loading Resources

There are various places file resources can be stored.  Here is a list plus a representative sample of how to access these files.  Most information take from here: How to Load File Resources

URIs available in metro applications:

General form
<scheme>://<domain name>/<path>

Web Reference:
<Image Margin="5" Source="http://www.microsoft.com/favicon.ico?v2" Height="100"/>

 
Application Package Reference:

<!--Relative To Project-->
<Image Margin="5" Source="/Images/favicon.ico" Height="100"/>


<!--Relative To Current Page-->
<Image Margin="5" Source="favicon.ico" Height="100"/>


<!--Relative To Current Page - Loads an image from a separate project-->
<Image Margin="5" Source="/ImageLibrary/favicon.ico" Height="100"/>


Application State:

<!--From Temp folder - image Created in App.xaml.cs-->
<Image Margin="5" Source="ms-appdata:///temp/favicon.scale-100.ico" Height="100" />



Application State From Code Behind:

<Image Margin="5" Source="{Binding BMImage}" Height="100"/>
 
bmImage = new BitmapImage();

bmImage.UriSource = new Uri(new Uri(
     Windows.Storage.ApplicationData.Current.TemporaryFolder.Path + "\\" +
     Windows.Storage.ApplicationData.Current.TemporaryFolder.Name),
     "favicon.scale-100.ico");
BitmapImage bmImage;

public BitmapImage BMImage
{
    get
    {
        return bmImage;
    }
}


Demonstration Project