Skip to content

Instantly share code, notes, and snippets.

@BrianJVarley
Last active April 28, 2016 19:01
Show Gist options
  • Save BrianJVarley/d421008b21d1e1f7c7826429a99c0043 to your computer and use it in GitHub Desktop.
Save BrianJVarley/d421008b21d1e1f7c7826429a99c0043 to your computer and use it in GitHub Desktop.
<Page x:Class="Parking_Tag_Picker_WRT.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Parking_Tag_Picker_WRT"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="#FF236A93">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel"
Grid.Row="0"
Margin="12,17,0,28">
<TextBlock Style="{StaticResource SubheaderTextBlockStyle}" Text="Parking Tag Picker" />
<TextBlock Margin="9,-7,0,0"
Style="{StaticResource HeaderTextBlockStyle}"
Text="Council Zones" />
</StackPanel>
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0">
<ListView x:Name="ZonesListView"
Margin="0,0,-12,0"
ItemsSource="{Binding CouncilNameItems}"
SelectedItem="{Binding SelectedCouncilName,
Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17">
<TextBlock Style="{ThemeResource ListViewItemTextBlockStyle}"
Text="{Binding CouncilAcronym}"
TextWrapping="Wrap" />
<TextBlock Margin="12,-6,12,0"
Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"
Text="{Binding CouncilFullName}"
TextWrapping="Wrap" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
<!--
Uncomment to see an alignment grid to help ensure your controls are
aligned on common boundaries. The image has a top margin of -32px to
account for the System Tray. Set this to 0 (or remove the margin altogether)
if the System Tray is hidden.
Before shipping remove this XAML and the image itself.
-->
<!--<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top" Height="800" Width="480" Margin="0,-32,0,0" Grid.Row="0" Grid.RowSpan="2" IsHitTestVisible="False" />-->
</Grid>
</Page>
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;
public MainPage()
{
//init data context
this.NavigationCacheMode = NavigationCacheMode.Required;
this.InitializeComponent();
vm = new MainViewModel(this);
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(RequestTagPage), 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<CouncilName>();
}
/// <summary>
/// Creates and adds council name data.
/// </summary>
public void LoadCouncilNamesData()
{
//Load Council Names
this.CouncilNameItems.Add(new CouncilName() { ID = "0", CouncilAcronym = "DCC", CouncilFullName = "Dublin City Council" });
this.CouncilNameItems.Add(new CouncilName() { ID = "1", CouncilAcronym = "DLR", CouncilFullName = "Dún Laoghaire-Rathdown County Council" });
this.CouncilNameItems.Add(new CouncilName() { ID = "2", CouncilAcronym = "FCC", CouncilFullName = "Fingal County Council" });
this.CouncilNameItems.Add(new CouncilName() { ID = "3", CouncilAcronym = "SDC", CouncilFullName = "South Dublin County Council" });
this.CouncilNameItems.Add(new CouncilName() { ID = "4", CouncilAcronym = "ATC", CouncilFullName = "Arklow Town Council" });
this.CouncilNameItems.Add(new CouncilName() { ID = "5", CouncilAcronym = "DLH", CouncilFullName = "Dún Laoghaire Harbour Company" });
this.CouncilNameItems.Add(new CouncilName() { ID = "6", CouncilAcronym = "WTC", CouncilFullName = "Wicklow Town Council" });
this.CouncilNameItems.Add(new CouncilName() { ID = "7", CouncilAcronym = "TS", CouncilFullName = "Tallaght Stadium" });
this.CouncilNameItems.Add(new CouncilName() { ID = "8", CouncilAcronym = "GS", CouncilFullName = "Greystones" });
this.IsDataLoaded = true;
}
public ObservableCollection<CouncilName> CouncilNameItems { get; set; }
public bool IsDataLoaded { get; private set; }
private CouncilName _selectedCouncilName;
public CouncilName 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)); }
}
}
}
using Parking_Tag_Picker_WRT.Common;
using Parking_Tag_Picker_WRT.Helpers;
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.Graphics.Display;
using Windows.UI.ViewManagement;
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 Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556
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 RequestTagPage : Page
{
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
private TagRequestViewModel _vm;
private DatabaseHelper _dbHelper;
private bool _isNewPageInstance = false;
public RequestTagPage()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
//init data context
this.NavigationCacheMode = NavigationCacheMode.Required;
_dbHelper = new DatabaseHelper();
_vm = new TagRequestViewModel(_dbHelper);
this.DataContext = _vm;
_isNewPageInstance = true;
}
/// <summary>
/// Gets the <see cref="NavigationHelper"/> associated with this <see cref="Page"/>.
/// </summary>
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
/// <summary>
/// Gets the view model for this <see cref="Page"/>.
/// This can be changed to a strongly typed view model.
/// </summary>
public ObservableDictionary DefaultViewModel
{
get { return this.defaultViewModel; }
}
/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="sender">
/// The source of the event; typically <see cref="NavigationHelper"/>
/// </param>
/// <param name="e">Event data that provides both the navigation parameter passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
/// a dictionary of state preserved by this page during an earlier
/// session. The state will be null the first time a page is visited.</param>
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
// If _isNewPageInstance is true, the page constuctor has been called, so
// state may need to be restored.
if (_isNewPageInstance)
{
if (_vm == null)
{
if (e.PageState.Count > 0)
{
_vm = (TagRequestViewModel)e.PageState["ViewModel"];
}
else
{
_vm = new TagRequestViewModel(_dbHelper);
}
}
DataContext = _vm;
}
// Set _isNewPageInstance to false. If the user navigates back to this page
// and it has remained in memory, this value will continue to be false.
_isNewPageInstance = false;
}
/// <summary>
/// Preserves state associated with this page in case the application is suspended or the
/// page is discarded from the navigation cache. Values must conform to the serialization
/// requirements of <see cref="SuspensionManager.SessionState"/>.
/// </summary>
/// <param name="sender">The source of the event; typically <see cref="NavigationHelper"/></param>
/// <param name="e">Event data that provides an empty dictionary to be populated with
/// serializable state.</param>
private void NavigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
// Save the ViewModel variable in the page's State dictionary.
e.PageState["ViewModel"] = _vm;
}
#region NavigationHelper registration
/// <summary>
/// The methods provided in this section are simply used to allow
/// NavigationHelper to respond to the page's navigation methods.
/// <para>
/// Page specific logic should be placed in event handlers for the
/// <see cref="NavigationHelper.LoadState"/>
/// and <see cref="NavigationHelper.SaveState"/>.
/// The navigation parameter is available in the LoadState method
/// in addition to page state preserved during an earlier session.
/// </para>
/// </summary>
/// <param name="e">Provides data for navigation methods and event
/// handlers that cannot cancel the navigation request.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.navigationHelper.OnNavigatedTo(e);
((TagRequestViewModel)this.DataContext).SelectedCouncilId = (string)e.Parameter;
_vm.InitZoneInfoAsync();
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
this.navigationHelper.OnNavigatedFrom(e);
}
#endregion
private void ZoneInfoAppBarBtn_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(ZoneInfoPage), _vm.SelectedZone);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment