Esempio n. 1
0
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            TranslateTransform tt    = new TranslateTransform();
            RadialScale        scale = Owner as RadialScale;

            if (scale != null)
            {
                // Calculate the geometry again. The first time this was done the owner had a size of (0,0)
                // and so did the indicator. Once the owner has the correct size (MeasureOverride has been called)
                // we should re-calculate the shape of the indicator
                SetIndicatorGeometry(scale, Value);
                Point center = scale.GetIndicatorOffset();
                tt.X            = center.X;
                tt.Y            = center.Y;
                RenderTransform = tt;
            }
            return(base.ArrangeOverride(arrangeBounds));
        }
Esempio n. 2
0
        private void PositionMarker()
        {
            if (Owner == null)
            {
                return;
            }
            if (Owner is RadialScale)
            {
                RadialScale rs = (RadialScale)Owner;
                // Get the angle based on the value
                double angle = rs.GetAngleFromValue(Value);
                if (rs.SweepDirection == SweepDirection.Counterclockwise)
                {
                    angle = -angle;
                }
                // Rotate the marker by angle
                TransformGroup tg = RenderTransform as TransformGroup;
                if (tg != null)
                {
                    RotateTransform rt = tg.Children[0] as RotateTransform;
                    if (rt != null)
                    {
                        rt.Angle = angle;
                    }
                }
                // Position the marker based on the radius
                Point  offset = rs.GetIndicatorOffset();
                double rad    = rs.GetIndicatorRadius();

                //position the marker
                double px = offset.X + (rad - DesiredSize.Height / 2) * Math.Sin(angle * Math.PI / 180);
                double py = offset.Y - (rad - DesiredSize.Height / 2) * Math.Cos(angle * Math.PI / 180);

                // Cache the intended position of the Indicator before it's centered
                this.Center = new Point(px, py);

                // Subtract the width of the Indicator's size so that it looks centered
                px -= DesiredSize.Width / 2;
                py -= DesiredSize.Height / 2;
                if (tg != null)
                {
                    TranslateTransform tt = tg.Children[1] as TranslateTransform;
                    if (tt != null)
                    {
                        tt.X = px;
                        tt.Y = py;
                    }
                }
            }
            //else
            //{
            //    LinearScale ls = Owner as LinearScale;
            //    Point offset = ls.GetIndicatorOffset(this);
            //    //the getIndicatorOffset returns only one correct dimension
            //    //for marker indicators the other dimension will have to be calculated again
            //    if (ls.Orientation == Orientation.Horizontal)
            //    {
            //        offset.X = ls.ActualWidth * (Value - ls.Minimum) / (ls.Maximum - ls.Minimum) - DesiredSize.Width / 2;
            //    }
            //    else
            //    {
            //        offset.Y = ls.ActualHeight - ls.ActualHeight * (Value - ls.Minimum) / (ls.Maximum - ls.Minimum) - DesiredSize.Height / 2;
            //    }
            //    TransformGroup tg = RenderTransform as TransformGroup;
            //    if (tg != null)
            //    {
            //        TranslateTransform tt = tg.Children[1] as TranslateTransform;
            //        if (tt != null)
            //        {
            //            tt.X = offset.X;
            //            tt.Y = offset.Y;
            //        }
            //    }
            //}
        }