Example #1
0
        /// <summary>
        /// Incrementally resizes text until it fits within the mealplan
        /// </summary>
        private void SetMealPlanTextSize()
        {
            try
            {
                List <StackPanel> days        = new List <StackPanel>();
                double            totalHeight = 0;
                StackPanelMealPlan.UpdateLayout();
                foreach (var item in StackPanelMealPlan.Children)
                {
                    if (item.GetType() == typeof(StackPanel))
                    {
                        StackPanel sp = (StackPanel)item;
                        totalHeight += sp.ActualHeight;
                        days.Add(sp);
                        //Day
                        TextBlock tb = sp.Children[0] as TextBlock;
                        tb.FontSize          = TBlockAdminMessage.FontSize + 5;
                        tb.VerticalAlignment = VerticalAlignment.Center;
                        tb.UpdateLayout();
                        //Meal
                        tb                   = sp.Children[1] as TextBlock;
                        tb.FontSize          = TBlockAdminMessage.FontSize;
                        tb.VerticalAlignment = VerticalAlignment.Center;
                        tb.UpdateLayout();
                        //Width
                        while (tb.IsTextTrimmed && tb.FontSize > 10)
                        {
                            tb.FontSize--;
                            tb.UpdateLayout();
                        }
                    }
                }

                while (totalHeight > StackPanelMealPlan.MaxHeight)
                {
                    totalHeight = 0;
                    //Height
                    foreach (StackPanel item in days)
                    {
                        TextBlock tbDay  = (TextBlock)item.Children[0];
                        TextBlock tbMeal = (TextBlock)item.Children[1];
                        tbMeal.TextTrimming = TextTrimming.CharacterEllipsis;

                        if (tbMeal.FontSize > 10 && tbDay.FontSize > 10)
                        {
                            tbMeal.FontSize--;
                            tbDay.FontSize--;
                            tbMeal.UpdateLayout();
                            tbDay.UpdateLayout();
                            totalHeight += item.ActualHeight;
                        }
                    }
                }
            }
            catch (Exception error)
            {
                DataValidation.SaveError(error.ToString());
            }
        }
Example #2
0
        private void drawUMLActor(Node node)
        {
            Rectangle rectangle = new Rectangle();

            rectangle.Width      = node.Width;
            rectangle.Height     = node.Height;
            rectangle.Fill       = Brushes.White;
            rectangle.MouseDown += node.OnMouseDown;
            node.UICanvas.Children.Add(rectangle);


            normalDraw(node.Width, node.Height, node.Position, node.Background, node.OnMouseDown, node.UICanvas);


            TextBlock textBlock = new TextBlock();

            textBlock.Text = node.LabelTextBlock.Text;
            textBlock.InvalidateMeasure();
            textBlock.IsHitTestVisible = false;
            node.UICanvas.Children.Add(textBlock);

            textBlock.UpdateLayout();
            double xMargin = (node.Width - textBlock.ActualWidth) / 2;

            textBlock.Margin = new Thickness(xMargin, node.Height - 20, 0, 0);


            node.LabelTextBlock.Visibility = Visibility.Collapsed;
        }
Example #3
0
        private static bool CalculateIsTextTrimmed(TextBlock textBlock)
        {
            if (!textBlock.IsArrangeValid)
            {
                textBlock.UpdateLayout();
            }

            var typeface = new Typeface(
                textBlock.FontFamily,
                textBlock.FontStyle,
                textBlock.FontWeight,
                textBlock.FontStretch);

            // FormattedText is used to measure the whole width of the text held up by TextBlock container
            var formattedText = new FormattedText(
                textBlock.Text,
                System.Threading.Thread.CurrentThread.CurrentCulture,
                textBlock.FlowDirection,
                typeface,
                textBlock.FontSize,
                textBlock.Foreground);

            formattedText.MaxTextWidth = textBlock.ActualWidth;
            formattedText.Trimming     = TextTrimming.None;

            // When the maximum text width of the FormattedText instance is set to the actual
            // width of the textBlock, if the textBlock is being trimmed to fit then the formatted
            // text will report a larger height than the textBlock. Should work whether the
            // textBlock is single or multi-line.
            return(formattedText.Height > textBlock.ActualHeight);
        }
Example #4
0
 protected byte[] RenderText(string text)
 {
     if (!Application.Current.Dispatcher.HasShutdownStarted)
     {
         return(Application.Current.Dispatcher.Invoke(() =>
         {
             TextBlock textBlock = new TextBlock();
             textBlock.BeginInit();
             textBlock.Text = text;
             textBlock.Width = double.IsNaN(Width) ? Width : Width - 10;
             textBlock.TextAlignment = TextAlignment;
             textBlock.TextWrapping = AutoSize ? TextWrapping.NoWrap : TextWrapping.Wrap;
             textBlock.TextTrimming = TextTrimming.CharacterEllipsis;
             textBlock.FontFamily = Font.Family;
             textBlock.FontSize = Font.Size;
             textBlock.FontWeight = Font.Weight;
             textBlock.FontStyle = Font.Style;
             textBlock.FontStretch = Font.Stretch;
             textBlock.EndInit();
             textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
             textBlock.Arrange(new Rect(textBlock.DesiredSize));
             textBlock.UpdateLayout();
             RenderTargetBitmap bmp = new RenderTargetBitmap(Convert.ToInt32(Math.Ceiling(textBlock.ActualWidth)), Convert.ToInt32(Math.Ceiling(textBlock.ActualHeight)), 96, 96, PixelFormats.Pbgra32);
             bmp.Render(textBlock);
             var encoder = new PngBitmapEncoder();
             encoder.Frames.Add(BitmapFrame.Create(bmp));
             using (var stream = new MemoryStream())
             {
                 encoder.Save(stream);
                 return stream.ToArray();
             }
         }));
     }
     return(new byte[0]);
 }
Example #5
0
        public FormulaSlot(FilterFormulas builder, int k, int n, WrapPanel holder)
        {
            Builder = builder;
            Holder  = holder;
            K       = k;
            N       = n;

            Container = new Grid();
            Container.ColumnDefinitions.Add(ColumnAuto());
            Container.ColumnDefinitions.Add(ColumnAuto());
            Container.ColumnDefinitions.Add(ColumnAuto());
            Container.RowDefinitions.Add(RowAuto());
            Container.RowDefinitions.Add(RowAuto());
            holder.Children.Add(Container);

            Button removeButton = new Button()
            {
                Content  = "✕", VerticalContentAlignment = VerticalAlignment.Stretch,
                MinWidth = 20, Height = 20,
                Margin   = new Thickness(0, 0, 5, 0)
            };

            removeButton.Click += (a, b) => RemoveButton_Clicked();
            Container.Children.Add(removeButton);

            TextBlock name = new TextBlock()
            {
                Text = "ρ"
            };

            Grid.SetColumn(name, 1);
            Container.Children.Add(name);
            name.UpdateLayout();
            TextBlock nameIndex = new TextBlock()
            {
                Text = k.ToString() + "," + n.ToString()
            };

            nameIndex.FontSize = name.FontSize * 0.8;
            nameIndex.Margin   = new Thickness(name.ActualWidth, name.ActualHeight - nameIndex.FontSize * 0.8, 0, 0);
            name.Text          = "ρ   = ";
            Grid.SetColumn(nameIndex, 1);
            Container.Children.Add(nameIndex);

            Input = new TextBox()
            {
                Text   = "0", MinWidth = 30,
                Height = name.ActualHeight, VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(0, 0, 15, 0)
            };
            Result = new TextBlock()
            {
                Text = "0"
            };
            Grid.SetColumn(Input, 2);
            Grid.SetColumn(Result, 2);
            Grid.SetRow(Result, 1);
            Container.Children.Add(Input);
            Container.Children.Add(Result);
        }
Example #6
0
    public static bool IsTextTrimming(TextBlock ATextBlock)
    {
        ATextBlock.UpdateLayout();
        Typeface typeface = new Typeface(ATextBlock.FontFamily, ATextBlock.FontStyle, ATextBlock.FontWeight, ATextBlock.FontStretch);

        return(new FormattedText(ATextBlock.Text, Thread.CurrentThread.CurrentCulture, ATextBlock.FlowDirection, typeface, ATextBlock.FontSize, ATextBlock.Foreground)
        {
            Trimming = TextTrimming.None, MaxTextWidth = ATextBlock.ActualWidth
        }.Height > ATextBlock.ActualHeight);
    }
Example #7
0
 System.Drawing.SizeF StringSize(string text, int fontSize, NativeFontFamily fontFamily, bool bold)
 {
     _txtMeasure.Visibility = Visibility.Collapsed;
     _txtMeasure.FontFamily = fontFamily;
     _txtMeasure.FontSize   = fontSize;
     _txtMeasure.FontWeight = bold ? FontWeights.Bold : FontWeights.Normal;
     _txtMeasure.Text       = text;
     _txtMeasure.UpdateLayout();
     //txtMeasure.Measure (new Size (1, 1));
     return(new System.Drawing.SizeF((float)_txtMeasure.ActualWidth, (float)_txtMeasure.ActualHeight));
 }
Example #8
0
        public CoreSize UpdateLabel(string text, AxisCore axis)
        {
            TextBlock.Text = text;
            TextBlock.UpdateLayout();

            var alpha = axis.View.LabelsRotation;

            alpha *= Math.PI / 180;

            return(new CoreSize(Math.Cos(alpha) * TextBlock.ActualWidth,
                                Math.Sin(alpha) * TextBlock.ActualWidth +
                                Math.Sin((90 * (Math.PI / 180)) - alpha) * TextBlock.ActualHeight));
        }
Example #9
0
        /// <summary>
        /// Incrementally resizes text until it fits within the message area
        /// </summary>
        private void MessageTextFormatting()
        {
            try
            {
                UIElementCollection messagePanel = StackPanelMessage.Children;

                foreach (var item in messagePanel)
                {
                    if (item.GetType() == typeof(TextBlock))
                    {
                        bool      overflow = false;
                        TextBlock tb       = (TextBlock)item;
                        tb.TextWrapping = TextWrapping.WrapWholeWords;
                        tb.TextTrimming = TextTrimming.CharacterEllipsis;
                        tb.FontSize     = 40;
                        tb.UpdateLayout();
                        if (tb.ActualHeight > StackPanelMessage.MaxHeight * 0.9 - TBlockAdminMessageTitle.ActualHeight - TBlockAdminMessageAuthor.ActualHeight)
                        {
                            overflow = true;
                        }
                        while ((tb.IsTextTrimmed || overflow) && tb.FontSize > 10)
                        {
                            tb.FontSize -= 1;
                            tb.UpdateLayout();
                            if (tb.ActualHeight < StackPanelMessage.MaxHeight * 0.9 - TBlockAdminMessageTitle.ActualHeight - TBlockAdminMessageAuthor.ActualHeight)
                            {
                                overflow = false;
                            }
                        }
                    }
                    TBlockAdminMessage.MaxHeight = StackPanelMessage.MaxHeight - TBlockAdminMessageTitle.ActualHeight - TBlockAdminMessageAuthor.ActualHeight;
                }
            }
            catch (Exception error)
            {
                DataValidation.SaveError(error.ToString());
            }
        }
Example #10
0
        // Display current model we are scraping by highlighting as green color
        public void UpdateUI(string model)
        {
            if (CurrentModel is not null)
            {
                this.ModelDict[CurrentModel].Foreground = DefaultColor;
            }
            this.ModelDict[model].Foreground = CurrentColor;

            TextBlock tb = this.ModelDict[model];

            tb.InvalidateVisual();
            tb.UpdateLayout();
            this.CurrentModel = model;
        }
Example #11
0
        public LabelEvaluation UpdateLabel(string text, AxisCore axis, AxisOrientation source)
        {
            TextBlock.Text = text;
            TextBlock.UpdateLayout();

            var transform = new LabelEvaluation(axis.View.LabelsRotation,
                                                TextBlock.ActualWidth, TextBlock.ActualHeight, axis, source);

            TextBlock.RenderTransform = Math.Abs(transform.LabelAngle) > 1
                ? new RotateTransform(transform.LabelAngle)
                : null;

            LabelModel = transform;

            return(transform);
        }
        public TextBlock CalculateHeight(TextBlock currentTextBlock, double width)
        {
            var tb = new TextBlock {
                Text = currentTextBlock.Text, FontSize = currentTextBlock.FontSize
            };

            tb.MinWidth     = width;
            tb.MaxWidth     = width;
            tb.Width        = width;
            tb.MaxHeight    = Double.PositiveInfinity;
            tb.TextWrapping = TextWrapping.WrapWholeWords;
            //tb.Style = Style;

            tb.Measure(new Size(width, Double.PositiveInfinity));
            tb.Arrange(new Rect(0, 0, width, tb.DesiredSize.Height));
            tb.UpdateLayout();

            return(tb);
        }
        public static PathGeometry[] ConvertToPathGeometries(SceneElement element)
        {
            if (!PathConversionHelper.CanConvert(element))
            {
                return(new PathGeometry[0]);
            }
            object              platformSpecificObject = element.ViewObject.PlatformSpecificObject;
            ITypeId             type     = (ITypeId)element.ViewObject.GetIType((ITypeResolver)element.ProjectContext);
            List <PathGeometry> pathList = new List <PathGeometry>();

            if (PlatformTypes.Shape.IsAssignableFrom(type))
            {
                PathGeometry pathGeometry = PathConversionHelper.SimplifyGeometry(element.ViewModel.DefaultView.GetRenderedGeometryAsWpf(element), true, ProjectNeutralTypes.PrimitiveShape.IsAssignableFrom((ITypeId)element.Type));
                pathList.Add(pathGeometry);
            }
            else if (platformSpecificObject is TextBlock)
            {
                TextBlock textBlock = platformSpecificObject as TextBlock;
                if (!textBlock.IsArrangeValid)
                {
                    textBlock.UpdateLayout();
                }
                PathConversionHelper.ConvertTextRangeToGeometry(new TextRange(textBlock.ContentStart, textBlock.ContentEnd), textBlock.FlowDirection, pathList);
            }
            else if (platformSpecificObject is RichTextBox)
            {
                PathConversionHelper.ConvertRichTextBoxToGeometry(platformSpecificObject as RichTextBox, pathList);
            }
            else if (platformSpecificObject is TextBox)
            {
                PathConversionHelper.ConvertTextBoxToGeometry(platformSpecificObject as TextBox, pathList);
            }
            else
            {
                PathConversionHelper.ConvertToPathGeometriesViaProxy(element as BaseFrameworkElement, pathList);
            }
            return(pathList.ToArray());
        }
        private void Update()
        {
            if (!IsChartInitialized)
            {
                return;
            }

            Func <double, string> defFormatter = x => x.ToString(CultureInfo.InvariantCulture);

            var completed = (Value - From) / (To - From);

            var t = 0d;

            if (double.IsNaN(completed) || double.IsInfinity(completed))
            {
                completed = 0;
            }

            completed = completed > 1 ? 1 : (completed < 0 ? 0 : completed);

            var angle = Wedge > 360 ? 360 : (Wedge < 0 ? 0 : Wedge);

            var fromAlpha = (360 - Wedge) * .5;
            var toAlpha   = 360 - fromAlpha;

            LeftLabel.Visibility  = Visibility.Hidden;
            RightLabel.Visibility = Visibility.Hidden;

            double r, top;

            r   = ActualWidth > ActualHeight ? ActualHeight : ActualWidth;
            r   = r / 2 - 2 * t;
            top = ActualHeight / 2;

            if (r < 0)
            {
                r = 1;
            }

            PieBack.Radius        = r;
            PieBack.InnerRadius   = InnerRadius ?? r * .6;
            PieBack.RotationAngle = 270;
            PieBack.WedgeAngle    = angle;

            Pie.Radius        = PieBack.Radius;
            Pie.InnerRadius   = PieBack.InnerRadius;
            Pie.RotationAngle = PieBack.RotationAngle;

            Canvas.SetLeft(PieBack, ActualWidth / 2);
            Canvas.SetTop(PieBack, top);
            Canvas.SetLeft(Pie, ActualWidth / 2);
            Canvas.SetTop(Pie, top);

            Canvas.SetTop(LeftLabel, top);
            Canvas.SetTop(RightLabel, top);
            Canvas.SetRight(LeftLabel, ActualWidth / 2 + (r + PieBack.InnerRadius) / 2 - LeftLabel.ActualWidth / 2);
            Canvas.SetRight(RightLabel, ActualWidth / 2 - (r + PieBack.InnerRadius) / 2 - RightLabel.ActualWidth / 2);

            MeasureTextBlock.FontSize = HighFontSize ?? Pie.InnerRadius * .4;
            MeasureTextBlock.Text     = (Value / 100).ToString("P");
            MeasureTextBlock.SetCurrentValue(ForegroundProperty, GaugeActiveFill);
            MeasureTextBlock.UpdateLayout();
            Canvas.SetTop(MeasureTextBlock, top * 2 - MeasureTextBlock.ActualHeight * 1.3);
            Canvas.SetLeft(MeasureTextBlock, ActualWidth / 2 - MeasureTextBlock.ActualWidth / 2);

            var interpolatedColor = new Color
            {
                R = LinearInterpolation(FromColor.R, ToColor.R),
                G = LinearInterpolation(FromColor.G, ToColor.G),
                B = LinearInterpolation(FromColor.B, ToColor.B),
                A = LinearInterpolation(FromColor.A, ToColor.A)
            };

            if (IsNew)
            {
                Pie.Fill       = new SolidColorBrush(FromColor);
                Pie.WedgeAngle = 0;
            }

            if (DisableAnimations)
            {
                Pie.WedgeAngle = completed * angle;
            }
            else
            {
                Pie.BeginAnimation(PieSlice.WedgeAngleProperty, new DoubleAnimation(completed * angle, AnimationsSpeed));
            }

            var d = ActualWidth < ActualHeight ? ActualWidth : ActualHeight;

            Stick.Height = d * .5 * .8;
            Stick.Width  = Stick.Height * .2;

            Canvas.SetLeft(Stick, ActualWidth * .5 - Stick.Width * .5);
            Canvas.SetTop(Stick, ActualHeight * .5 - Stick.Height * .9);

            var ticksHi  = d * .35;
            var ticksHj  = d * .3;
            var labelsHj = d * .3;

            #region 画Tick刻度

            var ts = double.IsNaN(TicksStep) ? DecideInterval((To - From) / 5) : TicksStep;
            if (ts / (From - To) > 300)
            {
                throw new InvalidOperationException("TicksStep property is too small compared with the range in " +
                                                    "the gauge, to avoid performance issues, please increase it.");
            }

            for (var i = From; i <= To; i += ts)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, From, To, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth * .5 + ticksHi * Math.Cos(alpha * Math.PI / 180),
                    X2 = ActualWidth * .5 + ticksHj * Math.Cos(alpha * Math.PI / 180),
                    Y1 = ActualHeight * .5 + ticksHi * Math.Sin(alpha * Math.PI / 180),
                    Y2 = ActualHeight * .5 + ticksHj * Math.Sin(alpha * Math.PI / 180)
                };
                Canvas.Children.Add(tick);
                tick.SetBinding(Shape.StrokeProperty,
                                new Binding {
                    Path = new PropertyPath(TicksForegroundProperty), Source = this
                });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                                new Binding {
                    Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this
                });
            }

            #endregion

            #region 画Lable刻度
            var ls = double.IsNaN(LabelsStep) ? DecideInterval((To - From) / 5) : LabelsStep;
            if (ls / (From - To) > 300)
            {
                throw new InvalidOperationException("LabelsStep property is too small compared with the range in " +
                                                    "the gauge, to avoid performance issues, please increase it.");
            }

            for (var i = From; i <= To; i += ls)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, From, To, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth * .5 + ticksHi * Math.Cos(alpha * Math.PI / 180),
                    X2 = ActualWidth * .5 + labelsHj * Math.Cos(alpha * Math.PI / 180),
                    Y1 = ActualHeight * .5 + ticksHi * Math.Sin(alpha * Math.PI / 180),
                    Y2 = ActualHeight * .5 + labelsHj * Math.Sin(alpha * Math.PI / 180)
                };

                Canvas.Children.Add(tick);
                var label = new TextBlock
                {
                    Text = (LabelFormatter ?? defFormatter)(i)
                };

                Canvas.Children.Add(label);
                label.UpdateLayout();
                Canvas.SetLeft(label, alpha < 270
                    ? tick.X2
                    : (Math.Abs(alpha - 270) < 4
                        ? tick.X2 - label.ActualWidth * .5
                        : tick.X2 - label.ActualWidth));
                Canvas.SetTop(label, tick.Y2);
                tick.SetBinding(Shape.StrokeProperty,
                                new Binding {
                    Path = new PropertyPath(TicksForegroundProperty), Source = this
                });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                                new Binding {
                    Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this
                });
            }
            #endregion

            MoveStick();


            if (GaugeActiveFill == null)
            {
                ((SolidColorBrush)Pie.Fill).BeginAnimation(SolidColorBrush.ColorProperty,
                                                           new ColorAnimation(interpolatedColor, AnimationsSpeed));
            }
            else
            {
                Pie.Fill = GaugeActiveFill;
            }
            IsNew = false;
        }
Example #15
0
        internal override void DrawLineStudy(Types.RectEx rect, LineStatus lineStatus)
        {
            if (_txt == null && lineStatus != LineStatus.StartPaint)
            {
                DrawLineStudy(rect, LineStatus.StartPaint);
            }

            if (lineStatus == LineStatus.StartPaint)
            {
                FontFamily = new FontFamily(_fontName = _chartX.FontFace);
                Foreground = Stroke;

                _txt = new TextBlock
                {
                    Tag        = this,
                    Visibility = Visibility.Collapsed
                };
                C.Children.Add(_txt);
                _txt.SetBinding(TextBlock.TextProperty, this.CreateOneWayBinding("Text"));
                _txt.SetBinding(TextBlock.FontFamilyProperty, this.CreateOneWayBinding("FontFamily"));
                _txt.SetBinding(TextBlock.FontSizeProperty, this.CreateOneWayBinding("FontSize"));
                _txt.SetBinding(TextBlock.ForegroundProperty, this.CreateOneWayBinding("Foreground"));
                _txt.SetBinding(UIElement.OpacityProperty, this.CreateOneWayBinding("Opacity"));

                _txt.MouseLeftButtonDown += (sender, args) => MouseDown(sender, args);
                _txt.MouseEnter          += (sender, args) => MouseEnter(sender, args);
                _txt.MouseLeave          += (sender, args) => MouseLeave(sender, args);
                _txt.MouseMove           += (sender, args) => MouseMove(sender, args);
                _txt.MouseLeftButtonUp   += (sender, args) => MouseUp(sender, args);

                if (_contextLine == null)
                {
                    _contextLine = new ContextLine(this);

                    _chartX.InvokeLineStudyCreated(new StockChartX.LineStudyCreatedEventArgs(this));
                }

                _internalObjectCreated = true;
                _txt.SetBinding(Canvas.TopProperty, this.CreateOneWayBinding("CanvasTop"));
                _txt.SetBinding(Canvas.LeftProperty, this.CreateOneWayBinding("CanvasLeft"));
                _txt.SetBinding(Canvas.ZIndexProperty, this.CreateOneWayBinding("CanvasZIndex"));

                return;
            }

            if (_txt == null)
            {
                return;
            }

            if (_txt.Visibility == Visibility.Collapsed)
            {
                _txt.Visibility = Visibility.Visible;
                _txt.UpdateLayout();
            }

            //Canvas.SetLeft(_txt, rect.Right);
            //Canvas.SetTop(_txt, rect.Bottom);
            CanvasLeft   = rect.Right;
            CanvasTop    = rect.Bottom;
            CanvasZIndex = ZIndexConstants.LineStudies1;

            //Canvas.SetZIndex(_txt, ZIndexConstants.LineStudies1);
        }
Example #16
0
 private void SetContent(TextBlock textblock, string text)
 {
     textblock.Text = text;
     textblock.UpdateLayout();
 }
        /// <summary>
        /// Draws the or move.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="axis">The axis.</param>
        public void DrawOrMove(AxisOrientation source, int axis)
        {
            _rectangle.Fill            = Fill;
            _rectangle.Stroke          = Stroke;
            _rectangle.StrokeDashArray = StrokeDashArray;
            _rectangle.StrokeThickness = StrokeThickness;
            Panel.SetZIndex(_rectangle, Panel.GetZIndex(this));
            BindingOperations.SetBinding(_rectangle, VisibilityProperty,
                                         new Binding {
                Path = new PropertyPath(VisibilityProperty), Source = this
            });

            var ax = source == AxisOrientation.X ? Model.Chart.AxisX[axis] : Model.Chart.AxisY[axis];
            var uw = ax.EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(source, Model.Chart, axis) / 2 : 0;

            if (Parent == null)
            {
                _label         = ((Axis)ax.View).BindATextBlock();
                _label.Padding = new Thickness(5, 2, 5, 2);
                Model.Chart.View.AddToView(this);
                Model.Chart.View.AddToDrawMargin(_rectangle);
                Model.Chart.View.AddToView(_label);
                _rectangle.Height = 0;
                _rectangle.Width  = 0;
                Canvas.SetLeft(_rectangle, 0d);
                Canvas.SetTop(_rectangle, Model.Chart.DrawMargin.Height);
                #region Obsolete
                Canvas.SetTop(_label, Model.Chart.DrawMargin.Height);
                Canvas.SetLeft(_label, 0d);
                #endregion
            }

            #pragma warning disable 618
            var from = ChartFunctions.ToDrawMargin(double.IsNaN(FromValue) ? Value + SectionOffset : FromValue, source, Model.Chart, axis) + uw;
#pragma warning restore 618
#pragma warning disable 618
            var to = ChartFunctions.ToDrawMargin(double.IsNaN(ToValue) ? Value + SectionOffset + SectionWidth : ToValue, source, Model.Chart, axis) + uw;
#pragma warning restore 618

            if (from > to)
            {
                var temp = to;
                to   = from;
                from = temp;
            }

            var anSpeed = Model.Chart.View.AnimationsSpeed;

            if (DataLabel)
            {
                if (DataLabelForeground != null)
                {
                    _label.Foreground = DataLabelForeground;
                }
                _label.UpdateLayout();
                _label.Background = Stroke ?? Fill;
                PlaceLabel(ax.GetFormatter()(Value), ax, source);
            }

            if (source == AxisOrientation.X)
            {
                var w = to - from;
                w = StrokeThickness > w ? StrokeThickness : w;

                Canvas.SetTop(_rectangle, 0);
                _rectangle.Height = Model.Chart.DrawMargin.Height;

                if (Model.Chart.View.DisableAnimations || DisableAnimations)
                {
                    _rectangle.Width = w > 0 ? w : 0;
                    Canvas.SetLeft(_rectangle, from - StrokeThickness / 2);
                }
                else
                {
                    _rectangle.BeginAnimation(WidthProperty, new DoubleAnimation(w > 0 ? w : 0, anSpeed));
                    _rectangle.BeginAnimation(Canvas.LeftProperty,
                                              new DoubleAnimation(from - StrokeThickness / 2, anSpeed));
                }
                return;
            }

            var h = to - from;
            h = StrokeThickness > h ? StrokeThickness : h;

            Canvas.SetLeft(_rectangle, 0d);
            _rectangle.Width = Model.Chart.DrawMargin.Width;

            if (Model.Chart.View.DisableAnimations || DisableAnimations)
            {
                Canvas.SetTop(_rectangle, from - StrokeThickness / 2);
                _rectangle.Height = h > 0 ? h : 0;
            }
            else
            {
                _rectangle.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(from, anSpeed));
                _rectangle.BeginAnimation(HeightProperty, new DoubleAnimation(h, anSpeed));
            }
        }
        /// <summary>
        /// Clears existing content then calculates new UI elements of the <see cref="Graph"/>
        /// for the current <see cref="BarometerTestUIModel.Graph"/>.
        /// </summary>
        private void DrawGraph()
        {
            // Initialize
            Graph.Children.Clear();

            // Calculate range and average
            var count = Model.Graph.Count;

            if (count == 0)
            {
                // Nothing to draw
                return;
            }
            var pressureMin      = (double?)null;
            var pressureMax      = (double?)null;
            var temperatureMin   = (double?)null;
            var temperatureMax   = (double?)null;
            var pressureTotal    = (double?)null;
            var temperatureTotal = (double?)null;

            foreach (var point in Model.Graph)
            {
                var pressure = point.Pressure;
                if (!pressureMax.HasValue || pressure > pressureMax)
                {
                    pressureMax = pressure;
                }
                if (!pressureMin.HasValue || pressure < pressureMin)
                {
                    pressureMin = pressure;
                }
                pressureTotal = (pressureTotal ?? 0) + pressure;

                var temperature = point.Temperature;
                if (!temperatureMax.HasValue || temperature > temperatureMax)
                {
                    temperatureMax = temperature;
                }
                if (!temperatureMin.HasValue || temperature < temperatureMin)
                {
                    temperatureMin = temperature;
                }
                temperatureTotal = (temperatureTotal ?? 0) + temperature;
            }
            var pressureRange      = (pressureMax ?? 0) - (pressureMin ?? 0);
            var pressureAverage    = pressureTotal / count;
            var temperatureRange   = (temperatureMax ?? 0) - (temperatureMin ?? 0);
            var temperatureAverage = temperatureTotal / count;

            // Calculate metrics
            Graph.UpdateLayout();
            var height     = Graph.ActualHeight;
            var drawHeight = height - (GraphPadding * 2);
            var width      = Graph.ActualWidth;
            var drawWidth  = width - (GraphPadding * 2);
            var graphYMax  = GraphPadding + drawHeight;
            Func <double, double, double, double> calculateGraphY = (double value, double minimum, double range) =>
            {
                if (range > 0)
                {
                    // Relative within range
                    return(graphYMax - (drawHeight * ((value - minimum) / range)));
                }
                else
                {
                    // Middle when flat line
                    return(graphYMax - (drawHeight / 2));
                }
            };

            // Get resources
            var pressureBrush    = (SolidColorBrush)Resources["GraphPressureBrush"];
            var temperatureBrush = (SolidColorBrush)Resources["GraphTemperatureBrush"];

            // Draw pressure average lines
            var pressureAverageY = calculateGraphY(pressureAverage.Value, pressureMin.Value, pressureRange);

            Graph.Children.Add(new Line
            {
                Stroke          = pressureBrush,
                StrokeThickness = 1,
                X1 = GraphPadding,
                Y1 = pressureAverageY,
                X2 = GraphPadding + drawWidth,
                Y2 = pressureAverageY
            });

            // Draw temperature average line
            var temperatureAverageY = calculateGraphY(temperatureAverage.Value, temperatureMin.Value, temperatureRange);

            Graph.Children.Add(new Line
            {
                Stroke          = temperatureBrush,
                StrokeThickness = 1,
                X1 = GraphPadding,
                Y1 = temperatureAverageY,
                X2 = GraphPadding + drawWidth,
                Y2 = temperatureAverageY
            });

            // Plot graph points
            var graphX       = GraphPadding;
            var pressureLine = new Polyline
            {
                Stroke          = pressureBrush,
                StrokeThickness = 1
            };
            var temperatureLine = new Polyline
            {
                Stroke          = temperatureBrush,
                StrokeThickness = 1
            };

            for (var index = Model.Graph.Count - 1; index >= 0; index--)
            {
                // Iterate backwards so we start with latest measurement
                var point = Model.Graph[index];

                // Calculate relative pressure point
                var pressureY     = calculateGraphY(point.Pressure, pressureMin.Value, pressureRange);
                var pressurePoint = new Point(graphX, pressureY);
                pressureLine.Points.Add(pressurePoint);

                // Calculate relative temperature point
                var temperatureY     = calculateGraphY(point.Temperature, temperatureMin.Value, temperatureRange);
                var temperaturePoint = new Point(graphX, temperatureY);
                temperatureLine.Points.Add(temperaturePoint);

                // Move X for next point...
                graphX += GraphZoom;
                if (graphX > width)
                {
                    // Stop when outside view
                    break;
                }
            }
            Graph.Children.Add(pressureLine);
            Graph.Children.Add(temperatureLine);

            // Draw average text
            var pressureAverageString = string.Format(CultureInfo.CurrentCulture,
                                                      "Pressure: {0}mbar", pressureAverage.Value);
            var pressureAverageText = new TextBlock
            {
                Foreground = pressureBrush,
                Text       = pressureAverageString
            };

            Graph.Children.Add(pressureAverageText);
            var temperatureAverageString = string.Format(CultureInfo.CurrentCulture,
                                                         "Temperature: {0}°c", temperatureAverage.Value);
            var temperatureAverageText = new TextBlock
            {
                Foreground = temperatureBrush,
                Text       = temperatureAverageString
            };

            Graph.Children.Add(temperatureAverageText);

            // Position average text so that it does not overlap
            pressureAverageText.UpdateLayout();
            temperatureAverageText.UpdateLayout();
            Canvas.SetTop(pressureAverageText, pressureAverageY
                          - pressureAverageText.ActualHeight);
            Canvas.SetLeft(pressureAverageText, width
                           - pressureAverageText.ActualWidth - GraphPadding
                           - temperatureAverageText.ActualWidth - GraphPadding);
            Canvas.SetTop(temperatureAverageText, temperatureAverageY
                          - temperatureAverageText.ActualHeight);
            Canvas.SetLeft(temperatureAverageText, width
                           - temperatureAverageText.ActualWidth - GraphPadding);
        }
Example #19
0
        public void DrawOrMove(AxisOrientation source, int axis)
        {
            if (Parent == null)
            {
                Model.Chart.View.AddToView(this);
                Model.Chart.View.AddToDrawMargin(_rectangle);
                Model.Chart.View.AddToDrawMargin(_label);
                _rectangle.Height = 0;
                _rectangle.Width  = 0;
                Canvas.SetLeft(_rectangle, 0d);
                Canvas.SetTop(_rectangle, Model.Chart.DrawMargin.Height);
                Canvas.SetTop(_label, Model.Chart.DrawMargin.Height);
                Canvas.SetLeft(_label, 0d);
            }

            var from = ChartFunctions.ToDrawMargin(FromValue, source, Model.Chart, axis);
            var to   = ChartFunctions.ToDrawMargin(ToValue, source, Model.Chart, axis);

            if (from > to)
            {
                var temp = to;
                to   = from;
                from = temp;
            }

            var anSpeed = Model.Chart.View.AnimationsSpeed;

            _label.UpdateLayout();

            if (source == AxisOrientation.X)
            {
                var w = to - from;
                w = StrokeThickness > w ? StrokeThickness : w;

                Canvas.SetTop(_rectangle, 0);
                _rectangle.Height = Model.Chart.DrawMargin.Height;

                if (Model.Chart.View.DisableAnimations)
                {
                    _rectangle.Width = w > 0 ? w : 0;
                    Canvas.SetLeft(_rectangle, from);
                    Canvas.SetLeft(_label, (from + to) / 2 - _label.ActualWidth / 2);
                }
                else
                {
                    _rectangle.BeginAnimation(WidthProperty, new DoubleAnimation(w > 0 ? w : 0, anSpeed));
                    _rectangle.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(from, anSpeed));
                    _label.BeginAnimation(Canvas.LeftProperty,
                                          new DoubleAnimation((from + to) / 2 - _label.ActualWidth / 2, anSpeed));
                }
                return;
            }

            var h = to - from;

            h = StrokeThickness > h ? StrokeThickness : h;

            Canvas.SetLeft(_rectangle, 0d);
            _rectangle.Width = Model.Chart.DrawMargin.Width;

            if (Model.Chart.View.DisableAnimations)
            {
                Canvas.SetTop(_rectangle, from);
                _rectangle.Height = h > 0 ? h : 0;
                Canvas.SetTop(_label, (from + to) / 2 - _label.ActualHeight / 2);
            }
            else
            {
                _rectangle.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(from, anSpeed));
                _rectangle.BeginAnimation(HeightProperty, new DoubleAnimation(h, anSpeed));
                _label.BeginAnimation(Canvas.TopProperty,
                                      new DoubleAnimation((from + to) / 2 - _label.ActualHeight / 2, anSpeed));
            }
        }
Example #20
0
        internal void Draw()
        {
            if (!IsControlLaoded) return;

            //No cache for you gauge :( kill and redraw please
            foreach (var child in Canvas.Children.Cast<UIElement>()
                .Where(x => !Equals(x, Stick) && !(x is AngularSection) && !(x is PieSlice)).ToArray())
                Canvas.Children.Remove(child);

            Wedge = Wedge > 360 ? 360 : (Wedge < 0 ? 0 : Wedge);

            var fromAlpha = (360-Wedge)*.5;
            var toAlpha = 360 - fromAlpha;

            var d = ActualWidth < ActualHeight ? ActualWidth : ActualHeight;

            Stick.Height = d*.5*.8;
            Stick.Width = Stick.Height*.2;

            Canvas.SetLeft(Stick, ActualWidth*.5 - Stick.Width*.5);
            Canvas.SetTop(Stick, ActualHeight*.5 - Stick.Height*.9);

            var ticksHi = d*.5;
            var ticksHj = d*.47;
            var labelsHj = d*.44;

            foreach (var section in Sections)
            {
                PieSlice slice;

                section.Owner = this;

                if (!Slices.TryGetValue(section, out slice))
                {
                    slice = new PieSlice();
                    Slices[section] = slice;
                }

                var p = (Canvas)section.Parent;
                if (p != null) p.Children.Remove(section);
                Canvas.Children.Add(section);
                var ps = (Canvas)slice.Parent;
                if (ps != null) ps.Children.Remove(slice);
                Canvas.Children.Add(slice);
            }

            UpdateSections();

            var ts = double.IsNaN(TicksStep) ? DecideInterval((ToValue - FromValue)/5) : TicksStep;
            if (ts / (FromValue - ToValue) > 300)
                throw new LiveChartsException("TicksStep property is too small compared with the range in " +
                                              "the gauge, to avoid performance issues, please increase it.");

            for (var i = FromValue; i <= ToValue; i += ts)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth*.5 + ticksHi*Math.Cos(alpha*Math.PI/180),
                    X2 = ActualWidth*.5 + ticksHj*Math.Cos(alpha*Math.PI/180),
                    Y1 = ActualHeight*.5 + ticksHi*Math.Sin(alpha*Math.PI/180),
                    Y2 = ActualHeight*.5 + ticksHj*Math.Sin(alpha*Math.PI/180)
                };
                Canvas.Children.Add(tick);
                tick.SetBinding(Shape.StrokeProperty,
                    new Binding {Path = new PropertyPath(TicksForegroundProperty), Source = this});
                tick.SetBinding(Shape.StrokeThicknessProperty,
                    new Binding { Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this });
            }

            var ls = double.IsNaN(LabelsStep) ? DecideInterval((ToValue - FromValue) / 5) : LabelsStep;
            if (ls / (FromValue - ToValue) > 300)
                throw new LiveChartsException("LabelsStep property is too small compared with the range in " +
                                              "the gauge, to avoid performance issues, please increase it.");

            for (var i = FromValue; i <= ToValue; i += ls)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth*.5 + ticksHi*Math.Cos(alpha*Math.PI/180),
                    X2 = ActualWidth*.5 + labelsHj*Math.Cos(alpha*Math.PI/180),
                    Y1 = ActualHeight*.5 + ticksHi*Math.Sin(alpha*Math.PI/180),
                    Y2 = ActualHeight*.5 + labelsHj*Math.Sin(alpha*Math.PI/180)
                };

                Canvas.Children.Add(tick);
                var label = new TextBlock
                {
                    Text = LabelFormatter(i)
                };

                label.SetBinding(EffectProperty,
                    new Binding {Path = new PropertyPath(LabelsEffectProperty), Source = this});

                Canvas.Children.Add(label);
                label.UpdateLayout();
                Canvas.SetLeft(label, alpha < 270
                    ? tick.X2
                    : (Math.Abs(alpha - 270) < 4
                        ? tick.X2 - label.ActualWidth*.5
                        : tick.X2 - label.ActualWidth));
                Canvas.SetTop(label, tick.Y2);
                tick.SetBinding(Shape.StrokeProperty,
                    new Binding { Path = new PropertyPath(TicksForegroundProperty), Source = this });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                    new Binding { Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this });
            }
            MoveStick();
        }
Example #21
0
        /// <summary>
        /// Draws the or move.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="axis">The axis.</param>
        public void DrawOrMove(AxisOrientation source, int axis)
        {
            _rectangle.Fill            = Fill;
            _rectangle.Stroke          = Stroke;
            _rectangle.StrokeDashArray = StrokeDashArray;
            _rectangle.StrokeThickness = StrokeThickness;
            Canvas.SetZIndex(_rectangle, Canvas.GetZIndex(this));
            BindingOperations.SetBinding(_rectangle, VisibilityProperty,
                                         new Binding {
                Path = new PropertyPath(nameof(Visibility)), Source = this
            });

            if (Parent == null)
            {
                Model.Chart.View.AddToView(this);
                Model.Chart.View.AddToDrawMargin(_rectangle);
                Model.Chart.View.AddToDrawMargin(_label);
                _rectangle.Height = 0;
                _rectangle.Width  = 0;
                Canvas.SetLeft(_rectangle, 0d);
                Canvas.SetTop(_rectangle, Model.Chart.DrawMargin.Height);
                Canvas.SetTop(_label, Model.Chart.DrawMargin.Height);
                Canvas.SetLeft(_label, 0d);
            }

            var ax = source == AxisOrientation.X ? Model.Chart.AxisX[axis] : Model.Chart.AxisY[axis];
            var uw = ax.EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(source, Model.Chart, axis) / 2 : 0;

            var from = ChartFunctions.ToDrawMargin(Value, source, Model.Chart, axis) + uw;
            var to   = ChartFunctions.ToDrawMargin(Value + SectionWidth, source, Model.Chart, axis) + uw;

            if (from > to)
            {
                var temp = to;
                to   = from;
                from = temp;
            }

            var anSpeed = Model.Chart.View.AnimationsSpeed;

            _label.UpdateLayout();

            if (source == AxisOrientation.X)
            {
                var w = to - from;
                w = StrokeThickness > w ? StrokeThickness : w;

                Canvas.SetTop(_rectangle, 0);
                _rectangle.Height = Model.Chart.DrawMargin.Height;

                if (Model.Chart.View.DisableAnimations)
                {
                    _rectangle.Width = w > 0 ? w : 0;
                    Canvas.SetLeft(_rectangle, from - StrokeThickness / 2);
                    Canvas.SetLeft(_label, (from + to) / 2 - _label.ActualWidth / 2);
                }
                else
                {
                    _rectangle.BeginDoubleAnimation(nameof(Width), w > 0 ? w : 0, anSpeed);
                    _rectangle.BeginDoubleAnimation("(Canvas.Left)", from - StrokeThickness / 2, anSpeed);
                    _label.BeginDoubleAnimation("(Canvas.Left)", (from + to) / 2 - _label.ActualWidth / 2, anSpeed);
                }
                return;
            }

            var h = to - from;

            h = StrokeThickness > h ? StrokeThickness : h;

            Canvas.SetLeft(_rectangle, 0d);
            _rectangle.Width = Model.Chart.DrawMargin.Width;

            if (Model.Chart.View.DisableAnimations)
            {
                Canvas.SetTop(_rectangle, from);
                _rectangle.Height = h > 0 ? h : 0;
                Canvas.SetTop(_label, (from + to) / 2 - _label.ActualHeight / 2);
            }
            else
            {
                _rectangle.BeginDoubleAnimation("(Canvas.Top)", from - StrokeThickness / 2, anSpeed);
                _rectangle.BeginDoubleAnimation(nameof(Height), h > 0 ? h : 0, anSpeed);
                _label.BeginDoubleAnimation("(Canvas.Top)", (from + to) / 2 - _label.ActualHeight / 2, anSpeed);
            }
        }
 private void SetContent(TextBlock textblock, string text)
 {
     textblock.Text = text;
     textblock.UpdateLayout();
 }
Example #23
0
        private void Draw()
        {
            if (!IsControlLaoded)
            {
                return;
            }

            //No cache for you gauge :( kill and redraw please
            foreach (var child in Canvas.Children.Cast <UIElement>()
                     .Where(x => !Equals(x, Stick)).ToArray())
            {
                Canvas.Children.Remove(child);
            }

            Wedge = Wedge > 360 ? 360 : (Wedge < 0 ? 0 : Wedge);

            var fromAlpha = (360 - Wedge) * .5;
            var toAlpha   = 360 - fromAlpha;

            var d = ActualWidth < ActualHeight ? ActualWidth : ActualHeight;

            Stick.Height = d * .5 * .8;
            Stick.Width  = Stick.Height * .2;

            Canvas.SetLeft(Stick, ActualWidth * .5 - Stick.Width * .5);
            Canvas.SetTop(Stick, ActualHeight * .5 - Stick.Height * .9);

            var ticksHi  = d * .5;
            var ticksHj  = d * .47;
            var labelsHj = d * .44;

            if (Sections.Any())
            {
                SectionsInnerRadius = SectionsInnerRadius > 1
                    ? 1
                    : (SectionsInnerRadius < 0
                        ? 0
                        : SectionsInnerRadius);

                foreach (var section in Sections)
                {
                    var start = LinearInterpolation(fromAlpha, toAlpha,
                                                    FromValue, ToValue, section.FromValue) + 180;
                    var end = LinearInterpolation(fromAlpha, toAlpha,
                                                  FromValue, ToValue, section.ToValue) + 180;

                    var slice = new PieSlice
                    {
                        RotationAngle = start,
                        WedgeAngle    = end - start,
                        Radius        = d * .5,
                        InnerRadius   = d * .5 * SectionsInnerRadius,
                        Fill          = section.Fill
                    };
                    Canvas.Children.Add(slice);
                    Canvas.SetTop(slice, ActualHeight * .5);
                    Canvas.SetLeft(slice, ActualWidth * .5);
                }
            }

            for (var i = FromValue; i <= ToValue; i += TicksStep)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth * .5 + ticksHi * Math.Cos(alpha * Math.PI / 180),
                    X2 = ActualWidth * .5 + ticksHj * Math.Cos(alpha * Math.PI / 180),
                    Y1 = ActualHeight * .5 + ticksHi * Math.Sin(alpha * Math.PI / 180),
                    Y2 = ActualHeight * .5 + ticksHj * Math.Sin(alpha * Math.PI / 180)
                };
                Canvas.Children.Add(tick);
                tick.SetBinding(Shape.StrokeProperty,
                                new Binding {
                    Path = new PropertyPath(TicksForegroundProperty), Source = this
                });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                                new Binding {
                    Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this
                });
            }

            for (var i = FromValue; i <= ToValue; i += LabelsStep)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth * .5 + ticksHi * Math.Cos(alpha * Math.PI / 180),
                    X2 = ActualWidth * .5 + labelsHj * Math.Cos(alpha * Math.PI / 180),
                    Y1 = ActualHeight * .5 + ticksHi * Math.Sin(alpha * Math.PI / 180),
                    Y2 = ActualHeight * .5 + labelsHj * Math.Sin(alpha * Math.PI / 180)
                };

                Canvas.Children.Add(tick);
                var label = new TextBlock
                {
                    Text = LabelFormatter(i)
                };

                label.SetBinding(EffectProperty,
                                 new Binding {
                    Path = new PropertyPath(LabelsEffectProperty), Source = this
                });

                Canvas.Children.Add(label);
                label.UpdateLayout();
                Canvas.SetLeft(label, alpha < 270
                    ? tick.X2
                    : (Math.Abs(alpha - 270) < 4
                        ? tick.X2 - label.ActualWidth * .5
                        : tick.X2 - label.ActualWidth));
                Canvas.SetTop(label, tick.Y2);
                tick.SetBinding(Shape.StrokeProperty,
                                new Binding {
                    Path = new PropertyPath(TicksForegroundProperty), Source = this
                });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                                new Binding {
                    Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this
                });
            }
            MoveStick();
        }
Example #24
0
 public CoreSize UpdateLabel(string text)
 {
     TextBlock.Text = text;
     TextBlock.UpdateLayout();
     return(new CoreSize(TextBlock.ActualWidth, TextBlock.ActualHeight));
 }
Example #25
0
        /// <summary>
        /// 绘制长标签与lable
        /// </summary>
        /// <param name="fromAlpha"></param>
        /// <param name="toAlpha"></param>
        /// <param name="ticksHi"></param>
        /// <param name="labelsHj"></param>
        /// <param name="i"></param>
        void DrawTick(double fromAlpha, double toAlpha, double ticksHi, double labelsHj, double i)
        {
            var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) - 90;

            var tick = new Line
            {
                X1 = ActualWidth * .5 + ticksHi * Math.Cos(alpha * Math.PI / 180),
                X2 = ActualWidth * .5 + labelsHj * Math.Cos(alpha * Math.PI / 180),
                Y1 = ActualHeight * .5 + ticksHi * Math.Sin(alpha * Math.PI / 180),
                Y2 = ActualHeight * .5 + labelsHj * Math.Sin(alpha * Math.PI / 180)
            };

            Canvas.Children.Add(tick);

            tick.SetBinding(Shape.StrokeProperty,
                new Binding { Path = new PropertyPath(TicksForegroundProperty), Source = this });
            tick.SetBinding(Shape.StrokeThicknessProperty,
                new Binding { Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this });
            string text = i.ToString();
            if (i % 90 == 0)
            {
                switch (i.ToString())
                {
                    case "0":
                        text = "北";
                        break;
                    case "90":
                        text = "东";
                        break;
                    case "180":
                        text = "南";
                        break;
                    case "270":
                        text = "西";
                        break;
                    default:
                        break;
                }
            }
            if (IsMil)
            {
                if (i == 0)
                    text = "0-00";
                else
                {
                    text =Math.Round((i * 16.667), MidpointRounding.AwayFromZero).ToString();
                    if (text.Length == 2) text = "0-" + text;
                    else
                    {
                        char[] strArr;
                        strArr = text.Length > 4 ? text.Take(4).ToArray() : text.ToArray();
                        var num = strArr.Length;
                        string s = new string(strArr,0,num-2);
                        string e = new string(strArr, num - 2, 2);
                        text = s + "-" + e;
                    }
                }
                
            }
            var label = new TextBlock
            {
                Text = text
            };

            label.SetBinding(EffectProperty,
                new Binding { Path = new PropertyPath(LabelsEffectProperty), Source = this });

            Canvas.Children.Add(label);
            label.UpdateLayout();
            if (alpha >= -90 && alpha < 0)
            {
                Canvas.SetLeft(label, tick.X2 - label.ActualWidth * .7);
                Canvas.SetTop(label, tick.Y2);
            }
            else if (alpha > 0 && alpha < 90)
            {
                Canvas.SetLeft(label, tick.X2 - label.ActualWidth);
                Canvas.SetTop(label, tick.Y2 - label.ActualHeight * .7);
            }
            else if (alpha >= 90 && alpha <= 180)
            {
                Canvas.SetLeft(label, tick.X2-label.ActualWidth*.5);
                Canvas.SetTop(label, tick.Y2 - label.ActualHeight * .7);
            }
            else
            {
                Canvas.SetLeft(label, tick.X2);
                Canvas.SetTop(label, tick.Y2);
            }
            if (label.Text == "东")
            {
                Canvas.SetLeft(label, tick.X2 - label.ActualWidth * 1.1);
                Canvas.SetTop(label, tick.Y2 - label.ActualHeight * .5);
            }
            if (label.Text == "南")
            {
                Canvas.SetLeft(label, tick.X2 - label.ActualWidth * .5);
                Canvas.SetTop(label, tick.Y2 - label.ActualHeight *1.05);
            }
            if (label.Text == "西")
            {
                Canvas.SetLeft(label, tick.X2);
                Canvas.SetTop(label, tick.Y2 - label.ActualHeight * 0.5);
            }
            if (label.Text == "北")
            {
                Canvas.SetLeft(label, tick.X2 - label.ActualWidth * .5);
                Canvas.SetTop(label, tick.Y2);
            }

        }
Example #26
0
        /// <summary>
        /// Construct page with header and footer.
        /// </summary>
        /// <param name="pageNumber">The current page to transform.</param>
        /// <returns>The document page.</returns>
        private DocumentPage ConstructPageWithHeaderAndFooter(int pageNumber)
        {
            DocumentPage page0 = flowDocPaginator.GetPage(pageNumber);

            // Coming from WPFNotepad, the source document should always be a FlowDocument
            FlowDocument originalDocument = (FlowDocument)flowDocPaginator.Source;
            TextBlock    headerBlock      = null;
            TextBlock    footerBlock      = null;
            DocumentPage newPage          = null;

            if (originalPageSize == Size.Empty)
            {
                originalPageSize = ((IDocumentPaginatorSource)originalDocument).DocumentPaginator.PageSize;
            }

            Size newPageSize = originalPageSize;

            // Decrease the top and/or bottom margins to account for headers/footers
            if ((headerText != null) && (headerText.Length > 0))
            {
                string expandedHeaderText = GetExpandedText(headerText, originalDocument, pageNumber + 1);
                headerBlock                     = new TextBlock();
                headerBlock.Text                = expandedHeaderText;
                headerBlock.FontFamily          = SystemFonts.MenuFontFamily;
                headerBlock.FontSize            = 10;
                headerBlock.HorizontalAlignment = HorizontalAlignment.Center;

                headerBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                headerBlock.Arrange(new Rect(headerBlock.DesiredSize));
                headerBlock.UpdateLayout();
                if (headerBlock.DesiredSize.Width > 0 && headerBlock.DesiredSize.Height > 0)
                {
                    newPageSize.Height -= headerBlock.DesiredSize.Height;
                }
            }

            if ((footerText != null) && (footerText.Length > 0))
            {
                string expandedFooterText = GetExpandedText(footerText, originalDocument, pageNumber + 1);
                footerBlock                     = new TextBlock();
                footerBlock.Text                = expandedFooterText;
                footerBlock.FontFamily          = SystemFonts.MenuFontFamily;
                footerBlock.FontSize            = 10;
                footerBlock.HorizontalAlignment = HorizontalAlignment.Center;

                footerBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                footerBlock.Arrange(new Rect(footerBlock.DesiredSize));
                footerBlock.UpdateLayout();
                if (footerBlock.DesiredSize.Width > 0 && footerBlock.DesiredSize.Height > 0)
                {
                    newPageSize.Height -= footerBlock.DesiredSize.Height;
                }
            }

            // Get the original page with its reduced size
            flowDocPaginator.PageSize = newPageSize;
            DocumentPage page = flowDocPaginator.GetPage(pageNumber);

            if (page != DocumentPage.Missing)
            {
                // Create a Grid that will hold the header, the original page, and the footer
                Grid          grid   = new Grid();
                RowDefinition rowDef = new RowDefinition();
                rowDef.Height = new GridLength(0, GridUnitType.Auto);
                grid.RowDefinitions.Add(rowDef);

                rowDef        = new RowDefinition();
                rowDef.Height = new GridLength(0, GridUnitType.Star);
                grid.RowDefinitions.Add(rowDef);

                rowDef        = new RowDefinition();
                rowDef.Height = new GridLength(0, GridUnitType.Auto);
                grid.RowDefinitions.Add(rowDef);

                ColumnDefinition columnDef = new ColumnDefinition();
                grid.ColumnDefinitions.Add(columnDef);

                // The header and footer TextBlocks can be added to the grid
                // directly.  The Visual from the original DocumentPage needs
                // to be hosted in a container that derives from UIElement.
                if (headerBlock != null)
                {
                    headerBlock.Margin = new Thickness(0, originalDocument.PagePadding.Top, 0, 0);
                    Grid.SetRow(headerBlock, 0);
                    grid.Children.Add(headerBlock);
                }

                VisualContainer container = new VisualContainer();
                container.PageVisual = page.Visual;
                container.PageSize   = newPageSize;

                Grid.SetRow(container, 1);
                grid.Children.Add(container);

                if (footerBlock != null)
                {
                    footerBlock.Margin = new Thickness(0, 0, 0, originalDocument.PagePadding.Bottom);
                    Grid.SetRow(footerBlock, 2);
                    grid.Children.Add(footerBlock);
                }

                // Recalculate the children inside the Grid
                grid.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                grid.Arrange(new Rect(grid.DesiredSize));
                grid.UpdateLayout();


                // Return the new DocumentPage constructed from the Grid's Visual
                newPage = new DocumentPage(grid);
            }

            // Return the page.
            return(newPage);
        }
        internal void Draw()
        {
            if (!IsControlLaoded)
            {
                return;
            }

            //No cache for you gauge :( kill and redraw please
            foreach (var child in Canvas.Children
                     .Where(x => !Equals(x, Stick) && !(x is AngularSection) && !(x is PieSlice)).ToArray())
            {
                Canvas.Children.Remove(child);
            }

            Wedge = Wedge > 360 ? 360 : (Wedge < 0 ? 0 : Wedge);

            var fromAlpha = (360 - Wedge) * .5;
            var toAlpha   = 360 - fromAlpha;

            var d = ActualWidth < ActualHeight ? ActualWidth : ActualHeight;

            Stick.Height = d * .5 * .8;
            Stick.Width  = Stick.Height * .2;

            Canvas.SetLeft(Stick, ActualWidth * .5 - Stick.Width * .5);
            Canvas.SetTop(Stick, ActualHeight * .5 - Stick.Height * .9);

            var ticksHi  = d * .5;
            var ticksHj  = d * .47;
            var labelsHj = d * .44;

            foreach (var section in Sections)
            {
                PieSlice slice;
                section.Owner = this;

                if (!Slices.TryGetValue(section, out slice))
                {
                    slice           = new PieSlice();
                    Slices[section] = slice;
                }

                var p = (Canvas)section.Parent;
                p?.Children.Remove(section);
                Canvas.Children.Add(section);
                var ps = (Canvas)slice.Parent;
                ps?.Children.Remove(slice);
                Canvas.Children.Add(slice);
            }

            UpdateSections();

            for (var i = FromValue; i <= ToValue; i += TicksStep)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth * .5 + ticksHi * Math.Cos(alpha * Math.PI / 180),
                    X2 = ActualWidth * .5 + ticksHj * Math.Cos(alpha * Math.PI / 180),
                    Y1 = ActualHeight * .5 + ticksHi * Math.Sin(alpha * Math.PI / 180),
                    Y2 = ActualHeight * .5 + ticksHj * Math.Sin(alpha * Math.PI / 180)
                };
                Canvas.Children.Add(tick);
                tick.SetBinding(Shape.StrokeProperty,
                                new Binding {
                    Path = new PropertyPath("TicksForeground"), Source = this
                });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                                new Binding {
                    Path = new PropertyPath("TicksStrokeThickness"), Source = this
                });
            }

            for (var i = FromValue; i <= ToValue; i += LabelsStep)
            {
                var alpha = LinearInterpolation(fromAlpha, toAlpha, FromValue, ToValue, i) + 90;

                var tick = new Line
                {
                    X1 = ActualWidth * .5 + ticksHi * Math.Cos(alpha * Math.PI / 180),
                    X2 = ActualWidth * .5 + labelsHj * Math.Cos(alpha * Math.PI / 180),
                    Y1 = ActualHeight * .5 + ticksHi * Math.Sin(alpha * Math.PI / 180),
                    Y2 = ActualHeight * .5 + labelsHj * Math.Sin(alpha * Math.PI / 180)
                };

                Canvas.Children.Add(tick);
                var label = new TextBlock
                {
                    Text = LabelFormatter(i)
                };

                //label.SetBinding(EffectProperty,
                //new Binding {Path = new PropertyPath("LabelsEffect"), Source = this});

                Canvas.Children.Add(label);
                label.UpdateLayout();
                Canvas.SetLeft(label, alpha < 270
                    ? tick.X2
                    : (Math.Abs(alpha - 270) < 4
                        ? tick.X2 - label.ActualWidth * .5
                        : tick.X2 - label.ActualWidth));
                Canvas.SetTop(label, tick.Y2);
                tick.SetBinding(Shape.StrokeProperty,
                                new Binding {
                    Path = new PropertyPath("TicksForeground"), Source = this
                });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                                new Binding {
                    Path = new PropertyPath("TicksStrokeThickness"), Source = this
                });
            }
            MoveStick();
        }
Example #28
0
        protected void UpdateUserInterface()
        {
            var size = Math.Min(this.ActualWidth, this.ActualHeight);

            this.Root.Width = this.Root.Height = size;
            this.Root.Children.Clear();
            for (var i = 0; i < this.RingCount; ++i)
            {
                this.Root.Children.Add(new Ellipse()
                {
                    Margin          = new Thickness(size / this.RingCount / 2 * i),
                    StrokeThickness = 2,
                    Stroke          = Brushes.Black,
                    Fill            = Brushes.Transparent,
                });
            }

            if (this.SegmentCount >= 2)
            {
                for (var i = 0; i <= this.SegmentCount; ++i)
                {
                    this.Root.Children.Add(new Line()
                    {
                        X1 = size / 2,
                        Y1 = size / 2,
                        X2 = (Math.Sin(Math.PI * 2 / this.SegmentCount * i) * (size / 2)) + (size / 2),
                        Y2 = (Math.Cos(Math.PI * 2 / this.SegmentCount * i) * (size / 2)) + (size / 2),
                        StrokeThickness = 2,
                        Stroke          = Brushes.Black,
                    });
                }
            }

            this.Labels = new String[this.SegmentCount, this.RingCount];
            for (var s = 0; s < this.SegmentCount; ++s)
            {
                for (var r = 0; r < this.RingCount; ++r)
                {
                    this.Labels[s, r] = new RadialMenuField(r, s).ToString();
                }
            }

            for (var s = 0; s < this.SegmentCount; ++s)
            {
                for (var r = 0; r < this.RingCount; ++r)
                {
                    var tb = new TextBlock()
                    {
                        Text = this.Labels[s, r],
                        HorizontalAlignment = HorizontalAlignment.Left,
                        VerticalAlignment   = VerticalAlignment.Top
                    };
                    this.Root.Children.Add(tb);
                    tb.UpdateLayout();
                    tb.Margin = new Thickness(
                        (Math.Sin(Math.PI * 2 / this.SegmentCount * (s + 0.5)) * (size / 2) / this.RingCount * (r + 0.5)) + (size / 2) - (tb.ActualWidth / 2),
                        (Math.Cos(Math.PI * 2 / this.SegmentCount * (s + 0.5)) * (size / 2) / this.RingCount * (r + 0.5)) + (size / 2) - (tb.ActualHeight / 2),
                        0,
                        0);
                }
            }
        }
Example #29
0
        /// <summary>
        ///Función que modifica el estilo del texto
        /// </summary>
        public void ChangeTextStyle()
        {
            if (TextBlockName == null)
            {
                return;
            }
            TextBlockName.Text       = FieldAssociated.Name;
            TextBlockName.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(FontColor));
            if (DataType == DataType.Image)
            {
                TextBlockName.UpdateLayout();
                return;
            }

            switch (FontName)
            {
            case FontName.Arial:
                TextBlockName.FontFamily = new FontFamily("Arial");
                break;

            case FontName.Currier:
                TextBlockName.FontFamily = new FontFamily("Courier New");
                break;

            case FontName.Times:
                TextBlockName.FontFamily = new FontFamily("Times New Roman");
                break;
            }

            switch (FontSize)
            {
            case FontSize.Small:
                TextBlockName.FontSize = 9;
                break;

            case FontSize.Medium:
                TextBlockName.FontSize = 13;
                break;

            case FontSize.Large:
                TextBlockName.FontSize = 17;
                break;
            }

            if (Italic)
            {
                TextBlockName.FontStyle = FontStyles.Italic;
            }
            else
            {
                TextBlockName.FontStyle = FontStyles.Normal;
            }

            if (Bold)
            {
                TextBlockName.FontWeight = FontWeights.UltraBold;
            }
            else
            {
                TextBlockName.FontWeight = FontWeights.Normal;
            }

            if (Underline)
            {
                TextDecoration myUnderline = new TextDecoration();

                myUnderline.Pen = new Pen(TextBlockName.Foreground, 1);
                myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;

                // Set the underline decoration to a TextDecorationCollection and add it to the text block.
                TextDecorationCollection myCollection = new TextDecorationCollection();
                myCollection.Add(myUnderline);
                TextBlockName.TextDecorations = myCollection;
            }
            else
            {
                TextBlockName.TextDecorations.Clear();
            }

            TextBlockName.UpdateLayout();
        }
Example #30
0
        public void DrawOrMove(AxisOrientation source, int axis)
        {
            _rectangle.Fill            = Fill;
            _rectangle.Stroke          = Stroke;
            _rectangle.StrokeDashArray = StrokeDashArray;
            _rectangle.StrokeThickness = StrokeThickness;
            Panel.SetZIndex(_rectangle, Panel.GetZIndex(this));

            if (Parent == null)
            {
                Model.Chart.View.AddToView(this);
                Model.Chart.View.AddToDrawMargin(_rectangle);
                Model.Chart.View.AddToDrawMargin(_label);
                _rectangle.Height = 0;
                _rectangle.Width  = 0;
                Canvas.SetLeft(_rectangle, 0d);
                Canvas.SetTop(_rectangle, Model.Chart.DrawMargin.Height);
                Canvas.SetTop(_label, Model.Chart.DrawMargin.Height);
                Canvas.SetLeft(_label, 0d);
            }

            var ax = source == AxisOrientation.X ? Model.Chart.AxisX[axis] : Model.Chart.AxisY[axis];
            var uw = ax.EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(source, Model.Chart, axis) / 2 : 0;

            var from = ChartFunctions.ToDrawMargin(FromValue, source, Model.Chart, axis) + uw;
            var to   = ChartFunctions.ToDrawMargin(ToValue, source, Model.Chart, axis) + uw;

            if (from > to)
            {
                var temp = to;
                to   = from;
                from = temp;
            }

            var anSpeed = Model.Chart.View.AnimationsSpeed;

            _label.UpdateLayout();

            if (source == AxisOrientation.X)
            {
                var w = to - from;
                w = StrokeThickness > w ? StrokeThickness : w;

                Canvas.SetTop(_rectangle, 0);
                _rectangle.Height = Model.Chart.DrawMargin.Height;

                if (Model.Chart.View.DisableAnimations)
                {
                    _rectangle.Width = w > 0 ? w : 0;
                    Canvas.SetLeft(_rectangle, from - StrokeThickness / 2);
                    Canvas.SetLeft(_label, (from + to) / 2 - _label.ActualWidth / 2);
                }
                else
                {
                    _rectangle.BeginAnimation(WidthProperty, new DoubleAnimation(w > 0 ? w : 0, anSpeed));
                    _rectangle.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(from - StrokeThickness / 2, anSpeed));
                    _label.BeginAnimation(Canvas.LeftProperty,
                                          new DoubleAnimation((from + to) / 2 - _label.ActualWidth / 2, anSpeed));
                }
                return;
            }

            var h = to - from;

            h = StrokeThickness > h ? StrokeThickness : h;

            Canvas.SetLeft(_rectangle, 0d);
            _rectangle.Width = Model.Chart.DrawMargin.Width;

            if (Model.Chart.View.DisableAnimations)
            {
                Canvas.SetTop(_rectangle, from - StrokeThickness / 2);
                _rectangle.Height = h > 0 ? h : 0;
                Canvas.SetTop(_label, (from + to) / 2 - _label.ActualHeight / 2);
            }
            else
            {
                _rectangle.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(from, anSpeed));
                _rectangle.BeginAnimation(HeightProperty, new DoubleAnimation(h, anSpeed));
                _label.BeginAnimation(Canvas.TopProperty,
                                      new DoubleAnimation((from + to) / 2 - _label.ActualHeight / 2, anSpeed));
            }
        }
Example #31
0
        internal override void Draw()
        {
            if (!IsControlLaoded)
            {
                return;
            }
            foreach (var child in Canvas.Children.Cast <UIElement>()
                     .Where(x => !Equals(x, Stick) && !(x is LinearSection) && !(x is PieSlice)).ToArray())
            {
                Canvas.Children.Remove(child);
            }

            foreach (var section in Sections)
            {
                Rectangle slice;

                section.Owner = this;

                if (!Slices.TryGetValue(section, out slice))
                {
                    slice           = new Rectangle();
                    Slices[section] = slice;
                }

                var p = (Canvas)section.Parent;
                if (p != null)
                {
                    p.Children.Remove(section);
                }
                Canvas.Children.Add(section);
                var ps = (Canvas)slice.Parent;
                if (ps != null)
                {
                    ps.Children.Remove(slice);
                }
                Canvas.Children.Add(slice);
            }

            //画区域
            UpdateSections();

            var ts = double.IsNaN(TicksStep) ? DecideInterval((ToValue - FromValue) / 5) : TicksStep;

            var unit = (GetActualHeight() / (ToValue - FromValue));

            //画短刻度
            for (var i = FromValue; i <= ToValue; i += ts)
            {
                var bottom = (i - FromValue) * unit;

                var tick = new Line
                {
                    X1 = ActualWidth * .5,
                    X2 = ActualWidth * .5 + 5,
                    Y1 = ActualHeight - bottom,
                    Y2 = ActualHeight - bottom
                };
                Canvas.Children.Add(tick);
                tick.SetBinding(Shape.StrokeProperty,
                                new Binding {
                    Path = new PropertyPath(TicksForegroundProperty), Source = this
                });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                                new Binding {
                    Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this
                });
            }

            var ls = double.IsNaN(LabelsStep) ? DecideInterval((ToValue - FromValue) / 5) : LabelsStep;

            if (ls / (FromValue - ToValue) > 300)
            {
                throw new LiveChartsException("LabelsStep property is too small compared with the range in " +
                                              "the gauge, to avoid performance issues, please increase it.");
            }


            //画长刻度与数字
            for (var i = FromValue; i <= ToValue; i += ls)
            {
                var bottom = (i - FromValue) * unit;


                var tick = new Line
                {
                    X1 = ActualWidth * .5,
                    X2 = ActualWidth * .5 + 10,
                    Y1 = ActualHeight - bottom,
                    Y2 = ActualHeight - bottom,
                };
                Canvas.Children.Add(tick);
                var label = new TextBlock
                {
                    Text = LabelFormatter(i)
                };

                label.SetBinding(EffectProperty,
                                 new Binding {
                    Path = new PropertyPath(LabelsEffectProperty), Source = this
                });

                Canvas.Children.Add(label);
                label.UpdateLayout();

                Canvas.SetLeft(label, ActualWidth * .5 - label.ActualWidth * .5 - 10);
                Canvas.SetBottom(label, bottom - (label.ActualHeight / 2));
                tick.SetBinding(Shape.StrokeProperty,
                                new Binding {
                    Path = new PropertyPath(TicksForegroundProperty), Source = this
                });
                tick.SetBinding(Shape.StrokeThicknessProperty,
                                new Binding {
                    Path = new PropertyPath(TicksStrokeThicknessProperty), Source = this
                });
            }

            ValueRec.Width = BackWidth / 4;
            Canvas.Children.Add(ValueRec);

            Canvas.SetLeft(ValueRec, ActualWidth * 0.5 + ValueRec.Width * 1.5);
            Canvas.SetBottom(ValueRec, 0);

            MoveStick();
        }