private void SetLabel(RadarObj obj, Point location, double duration) { //计算偏移量 bool x = true; bool y = true; if (location.X < 0) { x = false; } if (location.Y < 0) { y = false; } //obj.Name + " " + TextBlock txb = new TextBlock() { Text = " " + obj.Name + " " + Getbfb(Count.ToString(), obj.DataValue.ToString(), 2) + " ", Foreground = this.Foreground, FontSize = this.FontSize }; Size s = ControlSizeUtils.GetTextAreaSize(txb.Text, this.FontSize); CanvasPanel.Children.Add(txb); AnimationUtils.CtrlDoubleAnimation(txb, 1000, duration); if (location.X > -5 && location.X < 5) { Canvas.SetLeft(txb, location.X - (s.Width / 2)); } else { Canvas.SetLeft(txb, location.X + (x ? 0 : -(s.Width))); } if (location.Y > -5 && location.Y < 5) { Canvas.SetTop(txb, location.Y - (s.Height / 2)); } else { Canvas.SetTop(txb, location.Y + (y ? 0 : -(s.Height))); } }
/// <summary> /// 设置标注 /// </summary> /// <param name="obj"></param> /// <param name="location"></param> /// <param name="isGroupLabel"></param> private void SetLabel(RadarObj obj, Point location, bool isGroupLabel) { //计算偏移量 bool x = true; bool y = true; if (location.X < 0) { x = false; } if (location.Y < 0) { y = false; } TextBlock txb = new TextBlock() { Text = isGroupLabel ? obj.Name : obj.DataValue.ToString(), Foreground = this.Foreground, FontSize = this.FontSize }; Size s = ControlSizeUtils.GetTextAreaSize(txb.Text, this.FontSize); CanvasPanel.Children.Add(txb); if (location.X > -5 && location.X < 5) { Canvas.SetLeft(txb, location.X - (s.Width / 2)); } else { Canvas.SetLeft(txb, location.X + (x ? 0 : -(s.Width))); } if (location.Y > -5 && location.Y < 5) { Canvas.SetTop(txb, location.Y - (s.Height / 2)); } else { Canvas.SetTop(txb, location.Y + (y ? 0 : -(s.Height))); } }