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

Friday, August 17, 2012

C# Grid App Template

For the sake of reducing duplication, this template overview will only note the differences between it and the Blank App template.

    Grid App
        Assets
            In addition to the .pngs in the Blank App template, this template contains:
            DarkGray.png
            LightGray.png
            MediumGray.png

        Common
            BindableBase.cs
                Implements INotifyPropertyChanged (surprise surprise)
                Has a "SetProperty" method which fires the event handler when the value changes on
                    set
            BooleanNegationConverter.cs
                A value converter to negate values in xaml when binding
            BooleanToVisibilityConverter.cs
                A value converter to convert a bool to visibility (either true to visible or false to collapsed)
            LayoutAwarePage.cs
                This is the base class of all the premade views like GroupDetailPage
                Handles display state changes (like snapped to full screen) through various event
                    handlers
                Handles navigation events (GoBack, GoHome etc)
                Adds mouse and keyboard shortcuts for navigation
                Handles state management for navigation and process lifetime management
                Contains a default view model
            Readme.txt
                Contains a brief description of the purpose and use of items in the "Common" directory
            RichTextColumns.cs
                The same as a rich text block except it allows for additional overflow columns of text
            StandardStyles.xaml
                The same as in the Blank App template
            SuspensionManager.cs
                Acts on registered frames
                For the Grid App there is only one frame, so this is done in App.xaml.cs
                Captures and restores global sessions state for registered frames
                Keeps track of navigation history for registered frames
                Items to be saved are specified in the "SaveState" method of the layout aware page

        DataModel
            SampleDataSource.cs
                Example of how to subclass BindableBase.  Also provides a static class to provide
                    run-time and design-time data.
        App.xaml
            Main xaml of the application
            Adds the StandardStyles to the application resources
        App.xaml.cs (under App.xaml)
            Restores (if a previous session exists) and loads the first page, and saves state on
                suspend.

        GroupedItemsPage.xaml
            Example of how to display groups of items
            General layout and layout for snapped view
            Shows how to control views using the visual state manager
        GroupedItemsPage.xaml.cs
            Loads the page state on LoadState()
            Navigates to the GroupDetailPage on Header_Click()
            Navigates to the ItemDetailPage on ItemView_ItemClick()

        GroupDetailPage.xaml
            Same as GroupDetailPage.xaml except shows a single group
        GroupDetailPage.xaml.cs (under GroupDetailPage.xaml)
            Loads the page state on LoadState()
            Navigates to the ItemDetailPage on ItemView_ItemClick()

        ItemDetailPage.xaml
            Same as GroupDetailPage.xaml except shows a single item
        ItemDetailPage.xaml.cs
            Loads the page state on LoadState() - if an item was selected it navigates to it
            Saves the page state on SaveState()

Thursday, August 2, 2012

CSharp Blank App Template

This is an overview of the basic Blank App template for a C# metro application.

Blank App
    Properties
        AssemblyInfo.cs
            Title
            Description
            etc

    References
        .NET for Metro style apps   
            OVERVIEW
                http://msdn.microsoft.com/en-us/library/windows/apps/br230302(v=vs.110).aspx
                This is a subset of the normal .net types.  Has a focus on Metro.  Does not include:
                    -non-metro types and members
                    -Obsolete and legacy types
                    -Types that overlap with the Windows Runtime types
                    -Types and members that wrap operating system functionality
                    -Members that cause confusion (such as the Close method on I/O types)
            API
                http://msdn.microsoft.com/en-us/library/windows/apps/br230232(v=vs.110).aspx
      Windows
            API
                http://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx

    Assets
        These are the project defaults in the application manifest
        Logo.png
        SmallLogo.png
        SplashScreen.png
        StoreLogo.png

    Common
        StandardStyles.xaml
            This contains a bunch of standard styles used by default item templates

    App.xaml
        Sets the basic application resources

    App.xaml.cs (under App.xaml)
        This is the application entry point.
        protected override void OnLaunched(LaunchActivatedEventArgs args) sets up the main
        application frame and puts it in the application window.  This can also involve restoring
        previous application state.  Also saves the current application state on application shutdown

    BlankAppCSharp_TemporaryKey.pfx
        http://msdn.microsoft.com/en-us/library/ms537361.aspx
        This is a signing Certificate similar to the ones used by click-once installations.

    MainPage.xaml
        An empty page

    MainPage.xaml.cs
        Contains an empty implementation of OnNavigatedTo which is called when a page is
        displayed

    Package.appmanifest
        Basic Application setup (Application UI)
            -orientation
            -name
            -Logo
        Capabilities
            http://msdn.microsoft.com/en-us/library/windows/apps/hh464936.aspx
            This gives the application file system access permissions
        Declarations
            http://msdn.microsoft.com/en-us/library/windows/apps/hh464906.aspx
            This section appears to be misnamed.  The options in this section correspond to the App
            contracts and Extensions section in the documentation.  It declares the interactions with
            other applications which this app supports.
        Packaging
            Store packaging attributes