/// <summary> /// 根据当前的指示值和颜色模板更改Indicator Bar背景色 /// </summary> void ChangeIndicatorBarBackground() { Color_Value previous_pattern = new Color_Value(); Color_Value next_pattern = new Color_Value(); /* 如果没有设置颜色模式列表,则用默认的Indicator Bar背景色绘制 */ if (this.IndicatorBarPattern.Count == 0) { this.IndicatorBar.Stroke = this.IndicatorBarBackground; return; } /* 利用颜色模式列表绘制Indicator Bar背景 */ for (int i = 0; i < this.IndicatorBarPattern.Count; i++) { if (this.IndicatorValue < this.IndicatorBarPattern[i].Value) { /* 根据指示值获取Indicator Bar将要在哪两个颜色之间变色 */ if (i == 0) { previous_pattern.Background = this.IndicatorBarBackground; previous_pattern.Value = this.Min; } else { previous_pattern = this.IndicatorBarPattern[i - 1]; } next_pattern = this.IndicatorBarPattern[i]; /* 根据指示值和颜色模式列表计算Indicator Bar的背景色RGB分量 */ byte color_r = (byte)( (this.IndicatorValue - previous_pattern.Value) / (next_pattern.Value - previous_pattern.Value) * (next_pattern.Background.Color.R - previous_pattern.Background.Color.R) + previous_pattern.Background.Color.R); byte color_g = (byte)( (this.IndicatorValue - previous_pattern.Value) / (next_pattern.Value - previous_pattern.Value) * (next_pattern.Background.Color.G - previous_pattern.Background.Color.G) + previous_pattern.Background.Color.G); byte color_b = (byte)( (this.IndicatorValue - previous_pattern.Value) / (next_pattern.Value - previous_pattern.Value) * (next_pattern.Background.Color.B - previous_pattern.Background.Color.B) + previous_pattern.Background.Color.B); this.IndicatorBar.Stroke = new SolidColorBrush(Color.FromRgb(color_r, color_g, color_b)); return; } } /* 如果遍历完颜色模式列表还没有发现匹配的范围,则说明指示值超过模式列表的最大值,则用模式列表的最后一项绘制Indicator Bar背景 */ this.IndicatorBar.Stroke = this.IndicatorBarPattern[this.IndicatorBarPattern.Count - 1].Background; }
/// <summary> /// 对List<IndicatorBarColorPattern>进行排序的函数 /// </summary> /// <param name="Arg1"></param> /// <param name="Arg2"></param> /// <returns></returns> private static int SortCompare(Color_Value Arg1, Color_Value Arg2) { if (Arg1.Value < Arg2.Value) { return(-1); } else if (Arg1.Value > Arg2.Value) { return(1); } else { return(0); } }
/// <summary> /// 根据当前的指示值和颜色模板更改Indicator Bar背景色 /// </summary> void ChangeIndicatorBarBackground() { Color_Value previous_pattern = new Color_Value(); Color_Value next_pattern = new Color_Value(); /* 如果没有设置颜色模式列表,则用默认的Indicator Bar背景色绘制 */ if(this.IndicatorBarPattern.Count == 0) { this.IndicatorBar.Stroke = this.IndicatorBarBackground; return; } /* 利用颜色模式列表绘制Indicator Bar背景 */ for (int i = 0; i < this.IndicatorBarPattern.Count; i++) { if (this.IndicatorValue < this.IndicatorBarPattern[i].Value) { /* 根据指示值获取Indicator Bar将要在哪两个颜色之间变色 */ if (i == 0) { previous_pattern.Background = this.IndicatorBarBackground; previous_pattern.Value = this.Min; } else { previous_pattern = this.IndicatorBarPattern[i - 1]; } next_pattern = this.IndicatorBarPattern[i]; /* 根据指示值和颜色模式列表计算Indicator Bar的背景色RGB分量 */ byte color_r =(byte)( (this.IndicatorValue - previous_pattern.Value) / (next_pattern.Value - previous_pattern.Value) * (next_pattern.Background.Color.R - previous_pattern.Background.Color.R) + previous_pattern.Background.Color.R); byte color_g = (byte)( (this.IndicatorValue - previous_pattern.Value) / (next_pattern.Value - previous_pattern.Value) * (next_pattern.Background.Color.G - previous_pattern.Background.Color.G) + previous_pattern.Background.Color.G); byte color_b = (byte)( (this.IndicatorValue - previous_pattern.Value) / (next_pattern.Value - previous_pattern.Value) * (next_pattern.Background.Color.B - previous_pattern.Background.Color.B) + previous_pattern.Background.Color.B); this.IndicatorBar.Stroke = new SolidColorBrush(Color.FromRgb(color_r, color_g, color_b)); return; } } /* 如果遍历完颜色模式列表还没有发现匹配的范围,则说明指示值超过模式列表的最大值,则用模式列表的最后一项绘制Indicator Bar背景 */ this.IndicatorBar.Stroke = this.IndicatorBarPattern[this.IndicatorBarPattern.Count - 1].Background; }
/// <summary> /// 对List<IndicatorBarColorPattern>进行排序的函数 /// </summary> /// <param name="Arg1"></param> /// <param name="Arg2"></param> /// <returns></returns> private static int SortCompare(Color_Value Arg1, Color_Value Arg2) { if (Arg1.Value < Arg2.Value) return -1; else if (Arg1.Value > Arg2.Value) return 1; else return 0; }