Permalink
Browse files

Page2 using FabricDataService

  • Loading branch information...
saraford committed Dec 25, 2017
1 parent 073534a commit 6f46279fd00083f106a9175acb472b55de0c7f12
@@ -33,16 +33,17 @@ public static List<Fabric> GetAllFabrics()
await Application.Current.SavePropertiesAsync();
}
public static Fabric GetFabric(int id) {
return Application.Current.Properties[id.ToString()] as Fabric;
}
public static void UpdateFabric(Fabric fabric)
{
Xamarin.Forms.Application.Current.Properties.Remove(fabric.Id.ToString());
Xamarin.Forms.Application.Current.Properties.Add(fabric.Id.ToString(), fabric);
}
public static Fabric GetFabric(int id)
{
return Application.Current.Properties[id.ToString()] as Fabric;
}
}
}
@@ -1,4 +1,7 @@
using System;
using System.Windows.Input;
using ListViewInTabbedControl.Models;
using ListViewInTabbedControl.Services;
using MvvmHelpers;
using Xamarin.Forms;
@@ -8,10 +11,34 @@ public class PageTwoViewModel : BaseViewModel
{
private INavigation Navigation;
private Fabric currentFabric;
public Fabric CurrentFabric { get => currentFabric; set => SetProperty(ref currentFabric, value); }
public ICommand NextFabricCommand { get; private set; }
public PageTwoViewModel(INavigation navigation)
{
Title = "Page Two from VM";
this.Navigation = navigation;
CurrentFabric = new Fabric("add some fabrics first", 0);
NextFabricCommand = new Command(NextFabric);
}
internal void InitializeForFirstRun()
{
if (FabricsDataService.GetAllFabrics().Count > 0)
{
CurrentFabric = FabricsDataService.GetFabric(0);
}
}
public void NextFabric() {
CurrentFabric = FabricsDataService.GetFabric(1);
}
}
}
@@ -3,10 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ListViewInTabbedControl.Views.Page2">
<ContentPage.Content>
<StackLayout>
<Label Text="{Binding Title}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<StackLayout Padding="20" HorizontalOptions="Center">
<Label Text="{Binding CurrentFabric.Name}" FontSize="20" />
<Label Text="{Binding CurrentFabric.Seconds}" FontSize="20" />
<Button Text="Next" Command="{Binding NextFabricCommand}" HorizontalOptions="Center" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
@@ -7,12 +7,21 @@ namespace ListViewInTabbedControl.Views
{
public partial class Page2 : ContentPage
{
private PageTwoViewModel pageTwoViewModel;
public Page2()
{
InitializeComponent();
var pageTwoViewModel = new PageTwoViewModel(this.Navigation);
pageTwoViewModel = new PageTwoViewModel(this.Navigation);
this.BindingContext = pageTwoViewModel;
}
protected override void OnAppearing()
{
base.OnAppearing();
pageTwoViewModel.InitializeForFirstRun();
}
}
}

0 comments on commit 6f46279

Please sign in to comment.