Getting started

1. Using the framework

1.1. Prerequisites
To use the framework, the following assemblies must be referenced in the Windows Phone Application:
  • AppBarUtils (NuGet package)
  • PrismInteractivity (NuGet package)
  • Silverlight Toolkit (NuGet package)
  • Microsoft.Expression.Interactions

1.2. Referencing libraries
References to the following WPForms libraries have to be added:
  • WPForms.Common
  • WPForms.Phone

2. Create a form

To create a form add a new xaml file to your Windows Phone application. Set the build action to Resource

Add Form Content
Use the model classes to create a form:
<model:FormInstance 
    xmlns:model="clr-namespace:WPForms.Common.Model;assembly=WPForms.Common"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    ServerUrl="http://localhost:51583/FormStore.svc"
    Name="SampleForm">
    <model:FormInstance.MainSection>
        <model:FormSection Name="Registration form">
            <model:FormSection.Children>
                <model:TextField Label="First name:" IsRequired="True"/>
                <model:TextField Label="Last name:" IsRequired="True"/>
                <model:DateTimeField Label="Date of birth:" IsRequired="False"/>
                <model:GeoLocation Label="Address:" IsRequired="True"/>
                <model:PictureAttachment Label="Portrait:" IsRequired="True"/>
                <model:FormSection Name="Shipping information">
                    <model:FormSection.Children>
                        <model:TextField Label="Bill to:"/>
                        <model:GeoLocation Label="Delivery address:"/>
                        <model:DateTimeField Label="Preferred day:"/>
                    </model:FormSection.Children>
                </model:FormSection>
            </model:FormSection.Children>
        </model:FormSection>
    </model:FormInstance.MainSection>
</model:FormInstance>   

3. Create Bootstrapper

3.1. Create a new Bootstrapper class in your Windows Phone application:
    /// <summary>
    /// Bootstraps the sample application.
    /// </summary>
    public class SampleBootstrapper : WPForms.Phone.Bootstrapper
    {
        /// <summary>
        /// Implementors have to provide form descriptions for all available forms in the application.
        /// </summary>
        /// <param name="descriptionCollection">The description collection.</param>        
        protected override void AddFormDescriptions(WPForms.Common.Model.FormDescriptionCollection descriptionCollection)
        {
            descriptionCollection.Add(new WPForms.Common.Model.FormDescription()
            {
                FormName = "Webshop Registration",
                Uri = new Uri("/PhoneSample;component/Resources/SampleForm.xaml", UriKind.Relative),
            });

        }
    }


3.2. Run the bootstrapper on startup
To start the framework your bootstrapper has to run when the application starts.
Edit the App.xaml.cs to include initialization:
        /// <summary>
        /// The sample application's bootstrapper.
        /// </summary>
        private SampleBootstrapper bootstrapper;

        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            this.InitializeFramework();
        }

        // Code to execute when the application is activated (brought to foreground)
        // This code will not execute when the application is first launched
        private void Application_Activated(object sender, ActivatedEventArgs e)
        {
            if (!e.IsApplicationInstancePreserved)
            {
                this.InitializeFramework();
            }
        }

        /// <summary>
        /// Initializes the wp forms framework.
        /// </summary>
        private void InitializeFramework()
        {
            if (this.bootstrapper == null)
            {
                this.bootstrapper = new SampleBootstrapper();
                this.bootstrapper.Run(this.RootFrame);
            }
        }

4. Configure your application

4.1. Resources
  • To display your application's name properly, you have to add a string resource to the application resources: <sys:String x:Key="AppName">WPForms Sample</sys:String>
  • To enable SkyDrive backup add your Live Client id to the resources: <sys:String x:Key="LiveClientId"></sys:String>
  • To enable reverse geocoding add your Bing Maps Key to the resources: <sys:String x:Key="BingMapsKey"></sys:String>

4.2. Startup page
To fill out your form navigate to the FormCollection page: WPForms.Phone;component/View/FormCollection.xaml

Or you can set it to be the start page in the WMAppManifest.xml: <DefaultTask Name ="_default" NavigationPage="WPForms.Phone;component/View/FormCollection.xaml"/>

Last edited Nov 2, 2012 at 9:55 AM by csabakiss, version 3

Comments

No comments yet.