diff --git a/WpfDemo/App.xaml.cs b/WpfDemo/App.xaml.cs index 44f8391..014c05b 100644 --- a/WpfDemo/App.xaml.cs +++ b/WpfDemo/App.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; @@ -16,12 +16,14 @@ namespace WpfDemo /// /// Interaction logic for App.xaml /// - public partial class App : Application + public partial class App : Application, INotifyPropertyChanged { public SensorsPage mainWindow { get; private set; } public AddSensorPage discoverSensorsWindow { get; private set; } + public bool ConfigModified { get => configStore.Modified; } + public ObservableCollection Sensors { get { return bleSensors; } @@ -35,6 +37,8 @@ public ObservableCollection Sensors private System.Windows.Forms.NotifyIcon notifyIcon; private HomeWindow homeWindow; + public event PropertyChangedEventHandler PropertyChanged; + public App() { ShutdownMode = ShutdownMode.OnExplicitShutdown; @@ -44,6 +48,7 @@ protected override void OnStartup(StartupEventArgs e) base.OnStartup(e); configStore = new SFConfigStore(); + configStore.PropertyChanged += ConfigStorePropertyChanged; // init sensors bleSensorsDict = new Dictionary(); @@ -56,6 +61,8 @@ protected override void OnStartup(StartupEventArgs e) Normal = sensorConfig.Normal, MACAddress = sensorConfig.MACAddress, }; + sensor.AutoConnect = sensorConfig.AutoConnect; + sensor.Binding.MonitorDeviceName = sensorConfig.BindedMonitor; sensor.PropertyChanged += (object s, PropertyChangedEventArgs ev) => { SyncSensorProperty(sensor, sensorConfig, ev.PropertyName); @@ -131,14 +138,23 @@ private void sensorCollectionChanged(object sender, NotifyCollectionChangedEvent { throw new NotImplementedException(); } - //System.Diagnostics.Debugger.Break(); + configStore.Modified = true; } private void SensorPropertyChangedEventHandler(object sender, PropertyChangedEventArgs e) { + + } + private void ConfigStorePropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == "Modified") + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ConfigModified")); + } } private void SyncSensorProperty(IBLEAccelerationSensor sensor, BLEGravitySensorConfig sensorConfig, string propertyName) { + bool isConfigProperty = true; switch (propertyName) { case "DeviceName": @@ -156,6 +172,26 @@ private void SyncSensorProperty(IBLEAccelerationSensor sensor, BLEGravitySensorC sensorConfig.Normal = sensor.Normal; break; } + case "AutoConnect": + { + sensorConfig.AutoConnect = sensor.AutoConnect; + break; + } + case "BindMonitor": + { + sensorConfig.BindedMonitor = sensor.Binding.MonitorDeviceName; + break; + } + default: + { + isConfigProperty = false; + break; + } + + } + if (isConfigProperty) + { + configStore.Modified = true; } } public void SaveSettings() diff --git a/WpfDemo/HomeWindow.xaml b/WpfDemo/HomeWindow.xaml index bd2706b..40e0149 100644 --- a/WpfDemo/HomeWindow.xaml +++ b/WpfDemo/HomeWindow.xaml @@ -21,15 +21,10 @@ - -