Rotation can be added to ZoomPanel and ViewboxEx with the following code change (this can be only done if you have purchased
ZoomPanel with source code).
First you need to add Rotate DependencyProperty to ViewboxEx.
Add the following before the constructor:
Code:
public static readonly DependencyProperty RotateProperty = DependencyProperty.Register("Rotate", typeof(double), typeof(ViewboxEx), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure));
public double Rotate
{
get
{
return (double)base.GetValue(RotateProperty);
}
set
{
base.SetValue(RotateProperty, value);
}
}
Now you have to change the GetViewboxTransform method (as you have correctly found out). After "transformGroup = new TransformGroup();" add the following:
Code:
if (this.Rotate != 0)
transformGroup.Children.Add(new RotateTransform(this.Rotate, objectCenter.X / scaleXFactor, objectCenter.Y / scaleYFactor));
Note that this line rotates the content of the ViewboxEx around the center of the ViewboxEx control. It can be rotated by simply changing the Rotate property.
Now we need to add the Rotate property to ZoomPanel as well:
Add the following before ZoomPanel constructor:
Code:
public static readonly DependencyProperty RotateProperty = DependencyProperty.Register("Rotate", typeof(double), typeof(ZoomPanel), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure));
public double Rotate
{
get
{
return (double)base.GetValue(RotateProperty);
}
set
{
base.SetValue(RotateProperty, value);
}
}
You also need to change the template for the ZoomPanel - change the Generic.xaml in Themes folder. The line 12 should look like:
Code:
<local:ViewboxEx Name="PART_ZoomViewboxEx" Stretch="Uniform" Rotate="{TemplateBinding Rotate}">
The Rotate property of ViewboxEx was binded to the ZoomPanel Rotate property.
That is it :cool:
Now also ZoomPanel has a Rotate property that can rotate its content.
You can simply test this by adding a Slider to the ZoomPanelSample.xaml:
Add the following into the top right StackPanel:
Code:
<Slider Name="RotateSlider" Minimum="0" Maximum="360" Value="0" Width="160"/>
Now you can bind the slider to the ZoomPanel with adding the following attribute to the ZoomPanel:
Rotate="{Binding ElementName=RotateSlider, Path=Value}"