private void PiePieceMouseUp(object sender, MouseButtonEventArgs e) { PiePiece piece = sender as PiePiece; bool newValue = !piece.IsSelected; foreach (PiePiece piePiece in _piePieceList) { piePiece.IsSelected = false; } piece.IsSelected = newValue; }
private void ConstructPiePieces() { if (_piePiecePanel == null) { return; } double pieRadius = Radius; if (pieRadius <= 0) { return; } double total = 0; foreach (DataPoint dataPoint in DataPoints) { total += dataPoint.Value; } _piePiecePanel.Children.Clear(); _piePieceList.Clear(); double accumulativeAngle = 0; for (int i = 0; i < DataPoints.Count; i++) { double percentage = DataPoints[i].Value / total; double wedgeAngle = percentage * 360; double radius = pieRadius; if (IsStepwisePiePiece) { radius = (pieRadius - InnerRadius) / DataPoints.Count / 2 * (i + 1) + (InnerRadius + pieRadius) / 2; } if (DataPoints[i].DataPointForeground == null && BrushSet != null && BrushSet.Count > 0) { DataPoints[i].DataPointForeground = BrushSet[i % BrushSet.Count]; } PiePiece piece = new PiePiece() { Radius = radius, Percentage = percentage, InnerRadius = InnerRadius, CenterX = pieRadius + 10, CenterY = pieRadius + 10, ExtractLength = 0, Value = DataPoints[i].Value, RotateAngle = accumulativeAngle, Fill = DataPoints[i].DataPointForeground, Tag = DataPoints[i], }; Binding valueBinding = new Binding() { Source = DataPoints[i], Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(piece, PiePiece.ValueProperty, valueBinding); Binding binding = new Binding() { Source = DataPoints[i], Path = new PropertyPath("IsSelected"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(piece, PiePiece.IsSelectedProperty, binding); ToolTip toolTip = new ToolTip(); toolTip.Content = string.Format("{0} - {1} - {2}%", DataPoints[i].Label.ToString(), DataPoints[i].Value, Math.Round(percentage * 100, 2)); piece.ToolTip = toolTip; piece.OnValueChangedAction = new Action(ConstructPiePieces); piece.ToolTipOpening += new ToolTipEventHandler(PiePieceToolTipOpening); piece.MouseUp += new MouseButtonEventHandler(PiePieceMouseUp); _piePieceList.Add(piece); _piePiecePanel.Children.Insert(0, piece); accumulativeAngle += wedgeAngle; } }