Inheritance: System.Windows.Controls.UserControl
Exemplo n.º 1
0
        private void RefreshUI()
        {
            foreach (PieSlice sliceControl in xSlices.Children.OfType <PieSlice>())
            {
                sliceControl.MouseMove -= OnSliceMouseMove;
            }

            xSlices.Children.Clear();

            double numFractions = _sliceWeights.Length;
            double acc          = 0.0;

            for (int i = 0; i < _sliceWeights.Length; ++i)
            {
                double sliceWeight = _sliceWeights[i];
                Color  sliceColor  = _colorSpace[i];

                PieSlice sliceControl = new PieSlice();
                sliceControl.StartDegree = acc;
                sliceControl.EndDegree   = Math.Min(acc + sliceWeight * 360.0, 359.9);
                sliceControl.Color       = sliceColor;
                sliceControl.MouseMove  += OnSliceMouseMove;
                sliceControl.MouseDown  += OnSliceMouseDown;
                sliceControl.MouseLeave += OnSliceMouseLeave;
                sliceControl.MouseUp    += OnSliceMouseUp;

                xSlices.Children.Add(sliceControl);

                acc = sliceControl.EndDegree;
            }


            foreach (PieSlice slice in this.xSlices.Children)
            {
                if (_enableArrows && slice.ChildContent == null)
                {
                    Arrow arrow = new Arrow();
                    arrow.Width                 = 5;
                    arrow.Height                = 5;
                    arrow.RenderTransform       = new RotateTransform(180);
                    arrow.RenderTransformOrigin = new Point(0.5, 0.5);
                    arrow.HorizontalAlignment   = HorizontalAlignment.Center;
                    arrow.VerticalAlignment     = VerticalAlignment.Center;
                    arrow.Margin                = new Thickness(0, -2, 0, 0);
                    arrow.IsHitTestVisible      = false;
                    slice.ChildContent          = arrow;
                }
                else if (!_enableArrows && slice.ChildContent != null)
                {
                    slice.ChildContent = null;
                }
            }
        }
Exemplo n.º 2
0
        private void OnSliceMouseMove(object sender, MouseEventArgs e)
        {
            if (!_mouseDownInside)
            {
                return;
            }
            if (!AllowDrag)
            {
                return;
            }

            PieSlice sliceControl = (PieSlice)e.Source;
            int      sliceIndex   = xSlices.Children.IndexOf(sliceControl);

            BeginDrag(sliceIndex);
        }
Exemplo n.º 3
0
        private void RefreshUI()
        {
            foreach (PieSlice sliceControl in xSlices.Children.OfType<PieSlice>())
            {
                sliceControl.MouseMove -= OnSliceMouseMove;
            }

            xSlices.Children.Clear();

            double numFractions = _sliceWeights.Length;
            double acc = 0.0;

            for (int i = 0; i < _sliceWeights.Length; ++i)
            {
                double sliceWeight = _sliceWeights[i];
                Color sliceColor = _colorSpace[i];

                PieSlice sliceControl = new PieSlice();
                sliceControl.StartDegree = acc;
                sliceControl.EndDegree = Math.Min(acc + sliceWeight * 360.0, 359.9);
                sliceControl.Color = sliceColor;
                sliceControl.MouseMove += OnSliceMouseMove;
                sliceControl.MouseDown += OnSliceMouseDown;
                sliceControl.MouseLeave += OnSliceMouseLeave;
                sliceControl.MouseUp += OnSliceMouseUp;

                xSlices.Children.Add(sliceControl);

                acc = sliceControl.EndDegree;
            }

            foreach (PieSlice slice in this.xSlices.Children)
            {
                if (_enableArrows && slice.ChildContent == null)
                {
                    Arrow arrow = new Arrow();
                    arrow.Width = 5;
                    arrow.Height = 5;
                    arrow.RenderTransform = new RotateTransform(180);
                    arrow.RenderTransformOrigin = new Point(0.5, 0.5);
                    arrow.HorizontalAlignment = HorizontalAlignment.Center;
                    arrow.VerticalAlignment = VerticalAlignment.Center;
                    arrow.Margin = new Thickness(0, -2, 0, 0);
                    arrow.IsHitTestVisible = false;
                    slice.ChildContent = arrow;
                }
                else if (!_enableArrows && slice.ChildContent != null)
                {
                    slice.ChildContent = null;
                }
            }
        }