private static void OrientationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { BidirectionalIndicator bidirectionalProgressbar = (BidirectionalIndicator)d; Orientation orientation = (Orientation)e.NewValue; // Don't do anything if the orientation is the same as before. if (orientation == (Orientation)e.OldValue) { return; } switch (orientation) { case Orientation.Horizontal: // convert the layout grid from 1x2 to 2x1 bidirectionalProgressbar.layoutRoot.RowDefinitions.RemoveAt(1); bidirectionalProgressbar.layoutRoot.ColumnDefinitions.Add(new ColumnDefinition()); // reposition the progressbars to their appropriate cells Grid.SetColumn(bidirectionalProgressbar.positiveProgressBar, 1); Grid.SetRow(bidirectionalProgressbar.negativeProgressBar, 0); // switch the progressbars' orientations bidirectionalProgressbar.negativeProgressBar.Orientation = Orientation.Horizontal; bidirectionalProgressbar.positiveProgressBar.Orientation = Orientation.Horizontal; // transform the negativeProgressBar by adding a rotation of 180 degrees // scoping brackets used to avoid transformGroup name conflict { TransformGroup transformGroup = (TransformGroup)bidirectionalProgressbar.negativeProgressBar.RenderTransform; transformGroup.Children.Add(new RotateTransform(180)); } break; case Orientation.Vertical: // convert the layout grid from 2x1 to 1x2 bidirectionalProgressbar.layoutRoot.ColumnDefinitions.RemoveAt(1); bidirectionalProgressbar.layoutRoot.RowDefinitions.Add(new RowDefinition()); // reposition progressbars to their appropriate cells Grid.SetRow(bidirectionalProgressbar.negativeProgressBar, 1); Grid.SetColumn(bidirectionalProgressbar.positiveProgressBar, 0); // switch the progressbars' orientations bidirectionalProgressbar.negativeProgressBar.Orientation = Orientation.Vertical; bidirectionalProgressbar.positiveProgressBar.Orientation = Orientation.Vertical; // transform the negativeprogressbar by removing the 180 degree rotation // scoping brackets used to avoid transformGroup name conflict { TransformGroup transformGroup = (TransformGroup)bidirectionalProgressbar.negativeProgressBar.RenderTransform; transformGroup.Children.RemoveAt(1); } break; default: throw new NotImplementedException("Orientation not implemented."); } }
private static void ValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { BidirectionalIndicator bidirectionalIndicator = (BidirectionalIndicator)d; double value = (double)e.NewValue; if (value > 0) { bidirectionalIndicator.negativeProgressBar.Value = 0.0; bidirectionalIndicator.positiveProgressBar.Value = value; } else if (value < 0) { bidirectionalIndicator.negativeProgressBar.Value = -value; bidirectionalIndicator.positiveProgressBar.Value = 0.0; } else { bidirectionalIndicator.negativeProgressBar.Value = 0.0; bidirectionalIndicator.positiveProgressBar.Value = 0.0; } }