From 56885c4001dc4acce773ed7098474cbef2d2aa6b Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 27 Nov 2015 12:27:08 +0100 Subject: [PATCH] Added databinding example --- HueUWP/App.xaml | 4 +- HueUWP/App.xaml.cs | 4 +- HueUWP/HueUWP.csproj | 1 + HueUWP/HueUWP.sln | 40 +++++++++++++++++ HueUWP/Light.cs | 77 +++++++++++++++++++++++++++++++++ HueUWP/MainPage.xaml | 34 +++++++++++++-- HueUWP/MainPage.xaml.cs | 86 +++++++++++++++++++++++-------------- HueUWP/Package.appxmanifest | 16 +++---- 8 files changed, 214 insertions(+), 48 deletions(-) create mode 100644 HueUWP/HueUWP.sln create mode 100644 HueUWP/Light.cs diff --git a/HueUWP/App.xaml b/HueUWP/App.xaml index da19261..74c682e 100644 --- a/HueUWP/App.xaml +++ b/HueUWP/App.xaml @@ -1,8 +1,8 @@  diff --git a/HueUWP/App.xaml.cs b/HueUWP/App.xaml.cs index f465a11..68bc255 100644 --- a/HueUWP/App.xaml.cs +++ b/HueUWP/App.xaml.cs @@ -15,7 +15,7 @@ using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; -namespace HueUWP +namespace BindingToCommandsUWP { /// /// 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 diff --git a/HueUWP/HueUWP.csproj b/HueUWP/HueUWP.csproj index d7e0ef6..4ce3100 100644 --- a/HueUWP/HueUWP.csproj +++ b/HueUWP/HueUWP.csproj @@ -96,6 +96,7 @@ App.xaml + MainPage.xaml diff --git a/HueUWP/HueUWP.sln b/HueUWP/HueUWP.sln new file mode 100644 index 0000000..6e5e026 --- /dev/null +++ b/HueUWP/HueUWP.sln @@ -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 diff --git a/HueUWP/Light.cs b/HueUWP/Light.cs new file mode 100644 index 0000000..69436ff --- /dev/null +++ b/HueUWP/Light.cs @@ -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 _cars + = new ObservableCollection(); + + public static ObservableCollection 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); + //} + } + + + + +} diff --git a/HueUWP/MainPage.xaml b/HueUWP/MainPage.xaml index 538d50b..4d9e4d8 100644 --- a/HueUWP/MainPage.xaml +++ b/HueUWP/MainPage.xaml @@ -1,13 +1,41 @@  - + + + + + + + + + + + +