More Windows 7, More Persistence




CS185c

Chris Pollett

Sep. 27, 2010

Outline

Introduction

Setting up our XAML file

Setting Events to be Handled

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace WindowsPhoneApplication1
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            SupportedOrientations = SupportedPageOrientation.Portrait |
            SupportedPageOrientation.Landscape;
            this.OrientationChanged +=
                new EventHandler<OrientationChangedEventArgs>(OnOrientationChanged);
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            slider1.Value = 50; 
        }

        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (sliderNum != null && slider1 != null)
            {
                sliderNum.Text = "" + Math.Floor(slider1.Value + 0.5);
            }
        }

        void OnOrientationChanged(object sender, OrientationChangedEventArgs e)
        {

            if ((e.Orientation & PageOrientation.Landscape) != 0)
            {

                sliderNum.FontSize = 30;

            }

            else // Portrait
            {

                sliderNum.FontSize = 16;
            }

        }
    }
}

Comments on the C# code

  • Notice C# has a notion of partial class which one doesn't have in Java.
  • One common use for this is to split, a class definition across several files.
  • You can also use it to get something like Aspect Oriented Programming.
  • Notice also our constructor calls initialize components. It is here that the magic glue between C# and XAML is done. i.e., Name's in the XAML will be objects with that field name in our instance of the C# class.
  • Notice in the constructor we declare which orientations we support.
  • We also use += to add an event handler new EventHandler(OnOrientationChanged) to handle orientation changes.
  • ScreenShots of our App

    Portrait Screenshot of Phone 7 app Landscape Screenshot of Phone 7 app

    Quiz

    Which of the following is true?

    1. You don't need a certificate to get an app on an android device.
    2. willAnimateSecondHalfOfRotationToInterfaceOrientation: could be overriden to move buttons around the screen when the iPhone is rotated.
    3. If an Android app is in the run state, its state won't change if the screen is rotated.

    Logging

    Logging Example

    Storing and Retrieving Data

    Using Preferences

    More on Using Preferences

    Remembering the iPhone Filesystem

    iPhone Filesystem Test