Click here to Skip to main content
15,895,667 members
Articles / Mobile Apps / Windows Phone 7

Bike In City with Windows Phone 7

Rate me:
Please Sign up or sign in to vote.
4.97/5 (62 votes)
5 Jan 2011CPOL33 min read 111.3K   3.1K   101  
Learn how to build a small mobile application to visualize data from the city bike sharing system. Get the nearest stations, find the number of free bikes, and compute directions to other stations.
using System;
using System.ComponentModel;
using System.Windows.Media;
using System.Device.Location;
using BikeInCity.Utils;
using System.Collections.ObjectModel;
using System.Windows.Data;
using System.Xml.Serialization;
using Microsoft.Phone.Controls.Maps.Platform;


namespace BikeInCity.Model
{
  public class BikeStation : INotifyPropertyChanged
  {
    #region Private fields
        
    private  GeoCoordinate _location;
    private int _free;
    private int _freePlaces;
    private bool _isSelected;
    private int _walkDistance;    
    private int _id;
    private string _address;
    private int _total;
    private ObservableCollection<BikeRoute> _routes;

    #endregion

    public ObservableCollection<BikeRoute> Routes
    {
      get
      {
        if (_routes == null)
        {
          _routes = new ObservableCollection<BikeRoute>();
        }
        return _routes;
      }
      set {
        OnPropertyChanged("Routes");
        _routes = value;
      }
    }

    public bool IsSelected
    {
      get { return _isSelected; }
      set { 
        _isSelected = value;
        OnPropertyChanged("IsSelected");
      }
    }

    public GeoCoordinate Location
    {
      get
      {
        return _location;
      }
      set
      {
        _location = value;
        OnPropertyChanged("Location");
      }
    }

    public String Address
    {
      get { return _address; }
      set {
        if (value != null)
        {
          string toTrim = " -";


          string val = value;
          if (value.Contains(toTrim))
          {
            val = value.TrimEnd(toTrim.ToCharArray());
          }
          val = val.ToLower();
          if (_address != val)
          {
            OnPropertyChanged("Address");
          }
          _address = val;
        }
      }
    }

    public int Id
    {
      get { return _id; }
      set { _id = value; }
    }

    public int Free
    {
      get { return _free; }
      set { _free = value;
        OnPropertyChanged("Free");
        //OnPropertyChanged("PointColor");
        OnPropertyChanged("FreePlaces");
      }
    }

    public int Total
    {
      get { return _total; }
      set { 
        _total = value;
        OnPropertyChanged("FreePlaces");
      }
    }

    public int WalkDistance
    {
      get { return _walkDistance; }
      set {
        _walkDistance = value;
      }
    }

    public int FreePlaces
    {
      get { return _freePlaces; }
      set { 
        _freePlaces = value;
        OnPropertyChanged("FreePlaces");
      }
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    public virtual void OnPropertyChanged(string propertyName)
    {
      PropertyChangedEventHandler handler = this.PropertyChanged;
      if (handler != null)
      {
        var e = new PropertyChangedEventArgs(propertyName);
        handler(this, e);
      }
    }

    #endregion
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Junior) OCTO Technology
Czech Republic Czech Republic
Writing software at ITG RFQ-hub.
LinkedIn
Blog
GitHub
Articles at OCTO blog

Comments and Discussions