Skip to content

Instantly share code, notes, and snippets.

@aybarsyalcin
Last active December 12, 2017 21:13
Show Gist options
  • Save aybarsyalcin/9a8b74c801a600671cc2e4cd17d9f697 to your computer and use it in GitHub Desktop.
Save aybarsyalcin/9a8b74c801a600671cc2e4cd17d9f697 to your computer and use it in GitHub Desktop.
Listview with SwitchCell & Itemsource of Listview is set to "ItemsSource="{x:Static local:HomeViewModel.lights}"
using System;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace twoWayBinding
{
public static class HomeViewModel
{
public static ObservableCollection<light> lights { get; set; }
static HomeViewModel ()
{
HomeViewModel.lights = DataSource.getLights ();
}
}
}
?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="twoWayBinding.SwitchPage"
Title="Switch Panel"
xmlns:local="clr-namespace:twoWayBinding;assembly=twoWayBinding">
<ContentPage.Content>
<ListView x:Name="listView" SeparatorVisibility="None" ItemsSource="{x:Static local:HomeViewModel.lights}">
<ListView.ItemTemplate>
<DataTemplate>
<SwitchCell Text="{Binding name}" On="{Binding isOn}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment