/// <summary> /// 当led形状参数发生变化时调用的方法 /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DigitalControl led = d as DigitalControl; //获取根布局 Grid rootGrid = led.GetTemplateChild("gdRoot") as Grid; if (rootGrid == null) { return; } //清除原图形 if (led.rootGrid != null) { led.rootGrid.Children.Clear(); } //画新数字图形 //初始化Segments的点集digitalSegmentDict led.SetSegmentsData(); //画数字 led.dd = led.DrawSegments(led.digitalSegmentDict, led.LEDColor); //将线段添加到容器 led.AddSegmentsToPanel(led.dd); led.dd.DisplayDigital(led.Value); }
/// <summary> /// 当前值发生变化时候调用的方法 /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DigitalControl led = d as DigitalControl; if (led.dd != null) { led.dd.DisplayDigital(led.Value); } }
/// <summary> /// 添加Led Digitals /// </summary> /// <param name="ledCount"></param> private void DrawDigitals(int ledCount) { digitalsList.Clear(); double ledControlWidth = Width / ledCount; double ledControlHeight = Height; for (int i = 0; i < ledCount; i++) { DigitalControl led = new DigitalControl(); led.Width = ledControlWidth; led.Height = ledControlHeight; led.LEDColor = DigitalColor; led.SegmentInterval = SegmentInterval; led.LEDThickness = DigitalThickness; led.BevelWidth = BevelWidth; digitalsList.Add(led); } }
/// <summary> /// LED颜色发生变化时调用的方法 /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnLEDColorPropertyChange(DependencyObject d, DependencyPropertyChangedEventArgs e) { DigitalControl led = d as DigitalControl; led.SetAllSegmentsColor(led.dd, led.LEDColor); }