Skip to content

Instantly share code, notes, and snippets.

@BrianJVarley
Last active February 1, 2016 20:26
Show Gist options
  • Save BrianJVarley/4508dbadede93b64bbe3 to your computer and use it in GitHub Desktop.
Save BrianJVarley/4508dbadede93b64bbe3 to your computer and use it in GitHub Desktop.
using Parking_Tag_Picker_WRT.Interfaces;
using Parking_Tag_Picker_WRT.ViewModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
namespace Parking_Tag_Picker_WRT
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page, INavigationCallback
{
MainViewModel vm;
private INavigationCallback _navCallBack { get; set; }
public MainPage()
{
this.NavigationCacheMode = NavigationCacheMode.Required;
this.InitializeComponent();
vm = new MainViewModel(_navCallBack);
this.DataContext = vm;
vm.LoadCouncilNamesData();
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// this event is handled for you.
}
void INavigationCallback.NavigateTo(string ItemID)
{
Frame.Navigate(typeof(TagRequestPage), ItemID);
}
}
}
using Parking_Tag_Picker_WRT.Interfaces;
using Parking_Tag_Picker_WRT.Models;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace Parking_Tag_Picker_WRT.ViewModel
{
/// <summary>
/// This class contains properties that the main View can data bind to.
/// <para>
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
/// </para>
/// <para>
/// You can also use Blend to data bind with the tool's support.
/// </para>
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class MainViewModel : INotifyPropertyChanged
{
private INavigationCallback _navCallBack { get; set; }
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel(INavigationCallback navCallBack)
{
this._navCallBack = navCallBack;
this.CouncilNameItems = new ObservableCollection<CouncilNameModel>();
}
/// <summary>
/// Creates and adds council name data.
/// </summary>
public void LoadCouncilNamesData()
{
//Load Council Names
this.CouncilNameItems.Add(new CouncilNameModel() { ID = "0", CouncilAcronym = "DCC", CouncilFullName = "Dublin City Council" });
this.CouncilNameItems.Add(new CouncilNameModel() { ID = "1", CouncilAcronym = "DLR", CouncilFullName = "Dún Laoghaire-Rathdown County Council" });
this.CouncilNameItems.Add(new CouncilNameModel() { ID = "2", CouncilAcronym = "FCC", CouncilFullName = "Fingal County Council" });
this.CouncilNameItems.Add(new CouncilNameModel() { ID = "3", CouncilAcronym = "SDC", CouncilFullName = "South Dublin County Council" });
this.CouncilNameItems.Add(new CouncilNameModel() { ID = "4", CouncilAcronym = "ATC", CouncilFullName = "Arklow Town Council" });
this.CouncilNameItems.Add(new CouncilNameModel() { ID = "5", CouncilAcronym = "DLH", CouncilFullName = "Dún Laoghaire Harbour Company" });
this.CouncilNameItems.Add(new CouncilNameModel() { ID = "6", CouncilAcronym = "WTC", CouncilFullName = "Wicklow Town Council" });
this.CouncilNameItems.Add(new CouncilNameModel() { ID = "7", CouncilAcronym = "TS", CouncilFullName = "Tallaght Stadium" });
this.CouncilNameItems.Add(new CouncilNameModel() { ID = "8", CouncilAcronym = "GS", CouncilFullName = "Greystones" });
this.IsDataLoaded = true;
}
public ObservableCollection<CouncilNameModel> CouncilNameItems { get; set; }
public bool IsDataLoaded { get; private set; }
private CouncilNameModel _selectedCouncilName;
public CouncilNameModel SelectedCouncilName
{
get
{
return _selectedCouncilName;
}
set
{
if (_selectedCouncilName != value)
{
_selectedCouncilName = value;
RaisePropertyChanged("SelectedCouncilName");
_navCallBack.NavigateTo(_selectedCouncilName.ID);
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string prop)
{
if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(prop)); }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment