Added layout
This commit is contained in:
+33
-32
@@ -2,41 +2,49 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace BindingToCommandsUWP
|
||||
namespace HueUWP
|
||||
{
|
||||
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 int ID { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string Type { get; private set; }
|
||||
|
||||
public bool On { get; private set; }
|
||||
public int Brightness{ get; private set; }
|
||||
public int Hue { get; private set; }
|
||||
public int Saturation { get; private set; }
|
||||
|
||||
public Light()
|
||||
{
|
||||
|
||||
Debug.WriteLine("Get lamp data on creation or something");
|
||||
//temp
|
||||
ID = 1;
|
||||
Name = "Lamp 1";
|
||||
Type = "Extended color light";
|
||||
On = true;
|
||||
Brightness = 10;
|
||||
Hue = 14215;
|
||||
Saturation = 425;
|
||||
}
|
||||
|
||||
public void CheckInCar()
|
||||
public void UpdateState(bool on)
|
||||
{
|
||||
this.CheckedInDateTime = String.Format("{0:t}", DateTime.Now);
|
||||
NotifyPropertyChanged(nameof(UpdateState));
|
||||
Debug.WriteLine(on);
|
||||
|
||||
}
|
||||
|
||||
public void UpdateColor(int r, int g, int b)
|
||||
{
|
||||
NotifyPropertyChanged(nameof(UpdateColor));
|
||||
Debug.WriteLine(r + "-" + g + "-" + b);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,24 +59,17 @@ namespace BindingToCommandsUWP
|
||||
|
||||
public class LightDataSource
|
||||
{
|
||||
private static ObservableCollection<Light> _cars
|
||||
private static ObservableCollection<Light> _lights
|
||||
= new ObservableCollection<Light>();
|
||||
|
||||
public static ObservableCollection<Light> GetCars()
|
||||
public static ObservableCollection<Light> GetLights()
|
||||
{
|
||||
if (_cars.Count == 0)
|
||||
if (_lights.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" });
|
||||
_lights.Add(new Light());
|
||||
}
|
||||
return _cars;
|
||||
return _lights;
|
||||
}
|
||||
|
||||
//public static void CheckInCar(Car car)
|
||||
//{
|
||||
// _cars.FirstOrDefault(p => p.ID == car.ID).CheckedInDateTime = String.Format("{0:t}", DateTime.Now);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+10
-12
@@ -5,7 +5,8 @@
|
||||
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}}"
|
||||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||
DataContext="{Binding LightsViewModel, RelativeSource={RelativeSource Self}}"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid>
|
||||
@@ -14,21 +15,18 @@
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:Name="dataTemplate">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Rectangle Width="20" Height="20" Fill="Red" Margin="20, 0,0,0" />
|
||||
|
||||
<StackPanel Orientation="Vertical" Width="110" Margin="0,0,0,20">
|
||||
<TextBlock Text="{Binding Make}" FontSize="24" />
|
||||
<TextBlock Text="{Binding Model}" FontSize="24" />
|
||||
<TextBlock Text="{Binding Name}" FontSize="24" />
|
||||
<TextBlock Text="{Binding Type}" FontSize="14" />
|
||||
</StackPanel>
|
||||
|
||||
<Button Content="Check In"
|
||||
Width="100"
|
||||
Height="50"
|
||||
Margin="0,0,20,0"
|
||||
Click="CheckInButton_Click"
|
||||
<ToggleSwitch Tapped="ToggleSwitch_Tapped">
|
||||
<ToggleSwitch.OffContent>Off</ToggleSwitch.OffContent>
|
||||
<ToggleSwitch.OnContent>On</ToggleSwitch.OnContent>
|
||||
</ToggleSwitch>
|
||||
|
||||
/>
|
||||
|
||||
<TextBlock Text="{Binding CheckedInDateTime}"
|
||||
FontSize="24" />
|
||||
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
|
||||
+12
-5
@@ -28,11 +28,11 @@ namespace BindingToCommandsUWP
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
private ObservableCollection<Light> _carsViewModel = LightDataSource.GetCars();
|
||||
private ObservableCollection<Light> _lightsViewModel = LightDataSource.GetLights();
|
||||
|
||||
public ObservableCollection<Light> CarsViewModel
|
||||
public ObservableCollection<Light> LightsViewModel
|
||||
{
|
||||
get { return this._carsViewModel; }
|
||||
get { return this._lightsViewModel; }
|
||||
}
|
||||
|
||||
public MainPage()
|
||||
@@ -42,13 +42,20 @@ namespace BindingToCommandsUWP
|
||||
Debug.WriteLine(new NetworkHandler().Test());
|
||||
}
|
||||
|
||||
private void CheckInButton_Click(object sender, RoutedEventArgs e)
|
||||
private void ColorChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Button button = ((Button)sender);
|
||||
Light light = (Light)button.DataContext;
|
||||
|
||||
light.CheckInCar();
|
||||
light.UpdateColor(10, 10, 10);
|
||||
}
|
||||
|
||||
private void ToggleSwitch_Tapped(object sender, TappedRoutedEventArgs e)
|
||||
{
|
||||
ToggleSwitch button = ((ToggleSwitch)sender);
|
||||
Light light = (Light)button.DataContext;
|
||||
|
||||
light.UpdateState(button.IsOn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user