Added databinding example

This commit is contained in:
2015-11-27 12:27:08 +01:00
parent 5a1dc5e980
commit 56885c4001
8 changed files with 214 additions and 48 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
<Application
x:Class="HueUWP.App"
x:Class="BindingToCommandsUWP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HueUWP"
xmlns:local="using:BindingToCommandsUWP"
RequestedTheme="Light">
</Application>
+2 -2
View File
@@ -15,7 +15,7 @@ using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace HueUWP
namespace BindingToCommandsUWP
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
@@ -43,7 +43,7 @@ namespace HueUWP
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
this.DebugSettings.EnableFrameRateCounter = false;
}
#endif
+1
View File
@@ -96,6 +96,7 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Light.cs" />
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
+40
View File
@@ -0,0 +1,40 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HueUWP", "HueUWP.csproj", "{88414ECD-0462-41DE-ABA9-462D2F154595}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM = Release|ARM
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|ARM.ActiveCfg = Debug|ARM
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|ARM.Build.0 = Debug|ARM
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|ARM.Deploy.0 = Debug|ARM
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x64.ActiveCfg = Debug|x64
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x64.Build.0 = Debug|x64
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x64.Deploy.0 = Debug|x64
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x86.ActiveCfg = Debug|x86
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x86.Build.0 = Debug|x86
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x86.Deploy.0 = Debug|x86
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|ARM.ActiveCfg = Release|ARM
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|ARM.Build.0 = Release|ARM
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|ARM.Deploy.0 = Release|ARM
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x64.ActiveCfg = Release|x64
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x64.Build.0 = Release|x64
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x64.Deploy.0 = Release|x64
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x86.ActiveCfg = Release|x86
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x86.Build.0 = Release|x86
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
+77
View File
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace BindingToCommandsUWP
{
public class Light : INotifyPropertyChanged
{
public int ID { get; set; }
public string Make { get; set; }
public string Model { get; set; }
private string checkedInDateTime;
public string CheckedInDateTime
{
get { return checkedInDateTime; }
set
{
checkedInDateTime = value;
NotifyPropertyChanged(nameof(CheckedInDateTime));
}
}
public Light()
{
}
public void CheckInCar()
{
this.CheckedInDateTime = String.Format("{0:t}", DateTime.Now);
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public class LightDataSource
{
private static ObservableCollection<Light> _cars
= new ObservableCollection<Light>();
public static ObservableCollection<Light> GetCars()
{
if (_cars.Count == 0)
{
_cars.Add(new Light() { ID = 1, Make = "Tesla", Model = "Model S" });
_cars.Add(new Light() { ID = 2, Make = "Tesla", Model = "Model 3" });
_cars.Add(new Light() { ID = 3, Make = "Tesla", Model = "Model X" });
}
return _cars;
}
//public static void CheckInCar(Car car)
//{
// _cars.FirstOrDefault(p => p.ID == car.ID).CheckedInDateTime = String.Format("{0:t}", DateTime.Now);
//}
}
}
+31 -3
View File
@@ -1,13 +1,41 @@
<Page
x:Class="HueUWP.MainPage"
x:Class="BindingToCommandsUWP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HueUWP"
xmlns:local="using:BindingToCommandsUWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
DataContext="{Binding CarsViewModel, RelativeSource={RelativeSource Self}}"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<StackPanel Margin="20,40,20,40">
<ListView x:Name="myListView" ItemsSource="{Binding}" >
<ListView.ItemTemplate>
<DataTemplate x:Name="dataTemplate">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical" Width="110" Margin="0,0,0,20">
<TextBlock Text="{Binding Make}" FontSize="24" />
<TextBlock Text="{Binding Model}" FontSize="24" />
</StackPanel>
<Button Content="Check In"
Width="100"
Height="50"
Margin="0,0,20,0"
Click="CheckInButton_Click"
/>
<TextBlock Text="{Binding CheckedInDateTime}"
FontSize="24" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</Grid>
</Page>
+53 -33
View File
@@ -1,34 +1,54 @@
using System;
using System.Collections.Generic;
using HueUWP;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
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=402352&clcid=0x409
namespace HueUWP
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
Debug.WriteLine(new NetworkHandler().RegisterName("Kaas", "Henk"));
Debug.WriteLine(new NetworkHandler().Test());
}
}
}
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=402352&clcid=0x409
namespace BindingToCommandsUWP
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private ObservableCollection<Light> _carsViewModel = LightDataSource.GetCars();
public ObservableCollection<Light> CarsViewModel
{
get { return this._carsViewModel; }
}
public MainPage()
{
this.InitializeComponent();
Debug.WriteLine(new NetworkHandler().RegisterName("Kaas", "Henk"));
Debug.WriteLine(new NetworkHandler().Test());
}
private void CheckInButton_Click(object sender, RoutedEventArgs e)
{
Button button = ((Button)sender);
Light light = (Light)button.DataContext;
light.CheckInCar();
}
}
}
+8 -8
View File
@@ -7,15 +7,15 @@
IgnorableNamespaces="uap mp">
<Identity
Name="f92196db-26a4-4fab-8aa6-ed6892357fd3"
Publisher="CN=kenny"
Name="ce9a0222-308a-470c-a219-f3b5a133de19"
Publisher="CN=Paul de Mast"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="f92196db-26a4-4fab-8aa6-ed6892357fd3" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<mp:PhoneIdentity PhoneProductId="ce9a0222-308a-470c-a219-f3b5a133de19" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>HueUWP</DisplayName>
<PublisherDisplayName>kenny</PublisherDisplayName>
<DisplayName>CarCheckInUWP</DisplayName>
<PublisherDisplayName>Paul de Mast</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
@@ -30,12 +30,12 @@
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="HueUWP.App">
EntryPoint="CarCheckInUWP.App">
<uap:VisualElements
DisplayName="HueUWP"
DisplayName="CarCheckInUWP"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
Description="HueUWP"
Description="CarCheckInUWP"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
<uap:SplashScreen Image="Assets\SplashScreen.png" />