Permalink
Browse files

added listview

  • Loading branch information...
saraford committed Dec 22, 2017
1 parent d394bf2 commit f8b75014ea778b1add1c77cde9ab99893243f751
@@ -51,6 +51,7 @@
</Compile>
<Compile Include="ViewModels\PageOneViewModel.cs" />
<Compile Include="ViewModels\PageTwoViewModel.cs" />
<Compile Include="Models\Fabric.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Xamarin.Forms.Core">
@@ -72,6 +73,7 @@
<ItemGroup>
<Folder Include="Views\" />
<Folder Include="ViewModels\" />
<Folder Include="Models\" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="..\packages\Xamarin.Forms.2.5.0.121934\build\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.5.0.121934\build\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.targets')" />
@@ -0,0 +1,34 @@
using System;
using System.ComponentModel;
using MvvmHelpers;
namespace ListViewInTabbedControl.Models
{
public class Fabric : ObservableObject
{
private string name;
private int seconds;
private int id;
public Fabric(string Name, int Seconds)
{
this.Name = Name;
this.Seconds = Seconds;
this.Id = id;
}
// for the INotifyPropertyChange that the ObservableObject handles for us
// this is needed when the user edits a fabric item in the ListView
public string Name { get => name; set => SetProperty(ref name, value); }
public int Seconds { get => seconds; set => SetProperty(ref seconds, value); }
public int Id { get => id; set => SetProperty(ref id, value); }
// For tool tips in debugging
public override string ToString()
{
return this.Name + " " + this.Seconds + " " + this.Id;
}
}
}
@@ -1,15 +1,29 @@
using System;
using System.Collections.ObjectModel;
using MvvmHelpers;
using Xamarin.Forms;
using ListViewInTabbedControl.Models;
using System.Collections.Generic;
namespace ListViewInTabbedControl.ViewModels
{
public class PageOneViewModel : BaseViewModel
{
// this ObservableCollection is *only* for the View
// do *not* use this as the "source of truth" for fabrics
public ObservableCollection<Fabric> OCFabrics { get; set; }
private INavigation Navigation;
public PageOneViewModel(INavigation Navigation)
{
OCFabrics = new ObservableCollection<Fabric>();
OCFabrics.Add(new Fabric("fabric1", 5));
OCFabrics.Add(new Fabric("fabric2", 5));
OCFabrics.Add(new Fabric("fabric3", 5));
Title = "Page One from VM";
this.Navigation = Navigation;
}
@@ -1,12 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ListViewInTabbedControl.Views.Page1">
x:Class="ListViewInTabbedControl.Views.Page1"
Title="{Binding Title}">
<ContentPage.Content>
<StackLayout>
<Label Text="{Binding Title}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"/>
<ListView ItemsSource="{Binding OCFabrics}"
SelectedItem="{Binding SelectedItem, Mode=OneWay}"
HasUnevenRows="True"
Margin="10,10,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Height="60">
<StackLayout Orientation="Horizontal">
<BoxView BackgroundColor="Blue" WidthRequest="10" Margin="0,0,0,10" />
<StackLayout BackgroundColor="White" Orientation="Vertical" Margin="5,5,10,5">
<Label Text="{Binding Name}" FontAttributes="Bold" />
<Label Text="{Binding Seconds, StringFormat='Seconds: {0}'}" TextColor="Gray" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>

0 comments on commit f8b7501

Please sign in to comment.