public wndGroupSetting(Config config, MainWindow mainwnd) { InitializeComponent(); this.mainwnd = mainwnd; this.conf = config; //this.bindingDatas = bindingDatas; this.lstGroup.ItemsSource = config.Groups; }
private void Window_Loaded(object sender, RoutedEventArgs e) { coor_mgr.SetDeviceRTC("*", DateTime.Now); coor_mgr.SetDeviceScheduleEnable("*", true); if (App.Current.Properties.Contains("LightCollection")) { this.dictStreetLightBindingInfos = App.Current.Properties["LightCollection"] as Dictionary<string, StreetLightBindingData>; this.dictStreetLightBindingInfosOriginal = App.Current.Properties["LightCollectionOriginal"] as Dictionary<string, StreetLightBindingData>; } // System.Collections.Generic.Dictionary<string, StreetLightBindingData> List = new Dictionary<string, StreetLightBindingData>(); System.Collections.Generic.Dictionary<string, StreetLightBindingData> list = new Dictionary<string, StreetLightBindingData>(); if (!System.IO.File.Exists("config.xml")) { Config config = new Config(); foreach (UIElement element in this.grdDeviceLayer.Children) { if (element is CheckBox) { CheckBox btn = element as CheckBox; list.Add(btn.Content.ToString(), new StreetLightBindingData() { DevID = btn.Content.ToString(), OriginalDevID = btn.Content.ToString() }); // btn.Tag = btn.Content ; } } config.StreetLightBindingDatas = list.Values.ToArray(); config.Scenariors = new List<Scenarior>(); config.Groups = new List<Group>(); //System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(Config)); //sr.Serialize(System.IO.File.OpenWrite("config.xml"), config); SaveConfig(config); LedConfig = config; // this.listScene.ItemsSource = LedConfig.Scenariors; } else { //System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(Config)); //Config config = sr.Deserialize(System.IO.File.OpenRead("config.xml")) as Config; LedConfig = LoadConfig(); foreach (StreetLightBindingData data in LedConfig.StreetLightBindingDatas) list.Add(data.OriginalDevID, data); // this.listScene.ItemsSource = LedConfig.Scenariors; } foreach (UIElement element in this.grdDeviceLayer.Children) { if (element is CheckBox) { CheckBox btn = element as CheckBox; StreetLightBindingData temp; string devid = ""; btn.Tag = list[btn.Content.ToString()].OriginalDevID; devid = list[btn.Content.ToString()].DevID; if (!dictStreetLightBindingInfos.ContainsKey(devid)) { temp = new StreetLightBindingData() { DevID = devid, OriginalDevID = btn.Tag.ToString(), DimLevel = 0, IsEnable = false, LightNo = list[btn.Content.ToString()].LightNo, IsFake = list[btn.Content.ToString()].IsFake}; dictStreetLightBindingInfos.Add(temp.DevID, temp); dictStreetLightBindingInfosOriginal.Add(temp.OriginalDevID, temp); } else temp = dictStreetLightBindingInfos[devid] as StreetLightBindingData; btn.FontSize = 8; // temp.IsEnable = true; Binding binding = new Binding() { Path = new PropertyPath("IsEnable"), Converter = converter }; btn.SetBinding(Button.ForegroundProperty, binding); // btn.SetBinding(ForegroundProperty, binding); // btn.Content = null; // btn.SetBinding(CheckBox.ContentProperty, new Binding("DevID")); btn.SetBinding(CheckBox.ContentProperty, new Binding("LightNo")); #if !DEBUG btn.SetBinding(CheckBox.IsEnabledProperty, new Binding("IsEnable")); #endif btn.SetBinding(CheckBox.IsCheckedProperty, new Binding("IsChecked") { Mode = BindingMode.TwoWay }); // btn.Foreground = btn.Foreground; btn.DataContext = temp; // btn.Content = temp.LightNo; // btn.Text = btn.Text; btn.IsChecked = temp.IsChecked; // btn.IsChecked = false; } //if (element is Button) //{ // try // { // Button btn = (Button)element; // btn.Name = "btn" + btn.Content; // // btn.Width = btn.Height = 84; // btn.Click += btn_Click; // StreetLightBindingData temp = new StreetLightBindingData() { DevID = btn.Content.ToString(), DimLevel = 20, IsEnable = false }; // dictStreetLightBindingInfos.Add(btn.Content.ToString(), temp); // // temp.IsEnable = true; // btn.DataContext = temp; // Binding binding = new Binding() { Path = new PropertyPath("IsEnable"), Converter = converter }; // btn.SetBinding(Button.ForegroundProperty, binding); // // btn.SetBinding(ForegroundProperty, binding); // btn.Content = null; // btn.SetBinding(Button.ContentProperty, new Binding("DevID")); // btn.SetBinding(Button.IsEnabledProperty, new Binding("IsEnable")); // // btn.GetBindingExpression(ForegroundProperty).UpdateSource(); // } // catch (Exception ex) // { // System.Diagnostics.Debug.Print(ex.Message); // } //} } // foeach App.Current.Properties["LightCollection"] = dictStreetLightBindingInfos; App.Current.Properties["LightCollectionOriginal"] = dictStreetLightBindingInfosOriginal; Initial(); scrollViewer1_SizeChanged(null, null); }
public void SaveConfig(Config config) { System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(Config)); try { System.IO.File.Delete("config.xml"); } catch { ;} sr.Serialize(System.IO.File.OpenWrite("config.xml"), config); }
//private void scrollViewer1_SizeChanged(object sender, SizeChangedEventArgs e) //{ // if (rdNone.IsChecked == true) // { // vbImage.Stretch = Stretch.None; // vbImage.Width = imgPic.Width; // vbImage.Height = imgPic.Height; // vbImage.Margin = new Thickness(0); // vbImage.UpdateLayout(); // } // else //全覽 // { // vbImage.Width = scrollViewer1.ViewportWidth; // vbImage.Height = scrollViewer1.ViewportHeight; // vbImage.Margin = new Thickness(0); // vbImage.Stretch = Stretch.Uniform; // } //} //private void bdrOverView_MouseDown(object sender, MouseButtonEventArgs e) //{ // Point p = e.GetPosition(sender as IInputElement); // double horoffset, veroffset; // horoffset = p.X / bdrOverView.ActualWidth * imgPic.ActualWidth; // veroffset = p.Y / bdrOverView.ActualHeight * imgPic.ActualHeight; // scrollViewer1.ScrollToHorizontalOffset(horoffset); // scrollViewer1.ScrollToVerticalOffset(veroffset); //} private void Window_Loaded(object sender, RoutedEventArgs e) { #if !DEBUG coor_mgr.SetDeviceRTC("*", DateTime.Now); coor_mgr.SetDeviceScheduleEnable("*", true); #endif if (App.Current.Properties.Contains("LightCollection")) { this.dictStreetLightBindingInfos = App.Current.Properties["LightCollection"] as Dictionary<string, StreetLightBindingData>; this.dictStreetLightBindingInfosOriginal = App.Current.Properties["LightCollectionOriginal"] as Dictionary<string, StreetLightBindingData>; } System.Collections.Generic.Dictionary<string, StreetLightBindingData> List = new Dictionary<string, StreetLightBindingData>(); System.Collections.Generic.Dictionary<string, StreetLightBindingData> list = new Dictionary<string, StreetLightBindingData>(); if (!System.IO.File.Exists("config.xml")) { Config config = new Config(); #region open here later foreach (UIElement element in (this.map.Layers["grdDeviceLayer"] as ElementLayer).Children) { if (element is CheckBox) { CheckBox btn = element as CheckBox; list.Add(btn.Content.ToString(), new StreetLightBindingData() { DevID = btn.Content.ToString(), OriginalDevID = btn.Content.ToString() }); btn.Tag = btn.Content ; } } #endregion config.StreetLightBindingDatas = list.Values.ToArray(); config.Scenariors = new List<Scenarior>(); //System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(Config)); //sr.Serialize(System.IO.File.OpenWrite("config.xml"), config); SaveConfig(config); LedConfig = config; // this.listScene.ItemsSource = LedConfig.Scenariors; } else { //System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(Config)); //Config config = sr.Deserialize(System.IO.File.OpenRead("config.xml")) as Config; LedConfig = LoadConfig(); foreach (StreetLightBindingData data in LedConfig.StreetLightBindingDatas) list.Add(data.OriginalDevID, data); // this.listScene.ItemsSource = LedConfig.Scenariors; } #region open here later foreach (UIElement element in (this.map.Layers["grdDeviceLayer"] as ElementLayer).Children) { if (element is CheckBox) { CheckBox btn = element as CheckBox; StreetLightBindingData temp; string devid = ""; btn.Tag = list[btn.Content.ToString()].OriginalDevID; devid = list[btn.Content.ToString()].DevID; if (!dictStreetLightBindingInfos.ContainsKey(devid)) { temp = new StreetLightBindingData() { DevID = devid, OriginalDevID = btn.Tag.ToString(), DimLevel = 0, IsEnable = false, LightNo = list[btn.Content.ToString()].LightNo, IsFake = list[btn.Content.ToString()].IsFake}; dictStreetLightBindingInfos.Add(temp.DevID, temp); dictStreetLightBindingInfosOriginal.Add(temp.OriginalDevID, temp); } else temp = dictStreetLightBindingInfos[devid] as StreetLightBindingData; Binding binding = new Binding() { Path = new PropertyPath("IsEnable"), Converter = fontconverter }; btn.SetBinding(Button.ForegroundProperty, binding); btn.SetBinding(CheckBox.ContentProperty, new Binding("DevID")); btn.SetBinding(CheckBox.IsEnabledProperty, new Binding("IsEnable")); btn.SetBinding(CheckBox.IsCheckedProperty, new Binding("IsChecked") { Mode = BindingMode.TwoWay }); btn.DataContext = temp; btn.IsChecked = temp.IsChecked; } } // foeach #endregion App.Current.Properties["LightCollection"] = dictStreetLightBindingInfos; App.Current.Properties["LightCollectionOriginal"] = dictStreetLightBindingInfosOriginal; Initial(); Button_Click_1(null, null); //歸位 }