Hi,
I am trying specify RadDiagram Canvas size and I have two questions below.
Question 1)
When I set Width and Height of RadDiagram to large numbers,
ViewportRect.location of RadDiagramThumbnail is different.
Is this correct behavior and why is this happening?
Question 2)
With With and Height set, I am able to restrict the movement(or scroll?) of canvas to (0,0) and (width,height).
Below is the code I wrote to restrict the pan movement.
Now, I want to the same thing when I click and move mouse on RadDiagramThumbnail's ViewportRect.
How can I do this?
Thanks in advance.
Jaeho
MainWindow.xaml
<Grid x:Name="LyoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<telerik:RadDiagram x:Name="xDiagram"
Width="5760"
Height="3240"
MouseMove="diagram_MouseMove"
PreviewMouseDown="diagram_MouseDown"
PreviewMouseUp="diagram_MouseUp"
PreviewPan="Diagram_OnPreviewPan"
>
<telerik:RadDiagramShape x:Name="Shape1"
Content="Shape1"
Geometry="{telerik:FlowChartShape ShapeType=Database1Shape}"
Position="100,80" />
<telerik:RadDiagramShape x:Name="Shape2"
Content="Shape2"
Position="200,180" />
<telerik:RadDiagramConnection Source="{Binding ElementName=Shape1}" Target="{Binding ElementName=Shape2}" />
</telerik:RadDiagram>
<telerik:RadDiagramThumbnail x:Name="xThumbnail"
Grid.Row="1"
Diagram="{Binding ElementName=xDiagram}">
<telerik:RadDiagramThumbnail.ViewportStyle>
<Style TargetType="Rectangle">
<Setter Property="Stroke" Value="Blue" />
</Style>
</telerik:RadDiagramThumbnail.ViewportStyle>
</telerik:RadDiagramThumbnail>
</Grid>''
MainWindow.xaml.cs
private bool isPanning = false;
private Point oldPosition;
private void Diagram_OnPreviewPan(object sender, PositionChangedRoutedEventArgs e)
{
e.Handled = true;
this.isPanning = true;
}
private void diagram_MouseDown(object sender, MouseButtonEventArgs e)
{
this.oldPosition = e.GetPosition(this);
}
private void diagram_MouseUp(object sender, MouseEventArgs e)
{
this.isPanning = false;
}
private void diagram_MouseMove(object sender, MouseEventArgs e)
{
if ((e.LeftButton == MouseButtonState.Pressed) || (e.RightButton == MouseButtonState.Pressed))
{
var position = e.GetPosition(this);
if (this.isPanning && (e.RightButton == MouseButtonState.Pressed || Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
{
RadDiagram diagram = sender as RadDiagram;
double xOffset = position.X - oldPosition.X;
double yOffset = position.Y - oldPosition.Y;
if (yOffset < 0)
{
int visibleHeight = (int)(diagram.DesiredSize.Height / diagram.Zoom);
double pos = diagram.Viewport.Top + visibleHeight;
if (pos - yOffset > diagram.ActualHeight)
{
yOffset += (int)((pos - yOffset) - diagram.ActualHeight);
}
}
else if (yOffset > 0)
{
if (diagram.Viewport.Top - yOffset < 0)
{
//e.Handled = true;
yOffset += (int)diagram.Viewport.Top - yOffset;
}
}
if (xOffset < 0)
{
int visibleWidth = (int)(diagram.DesiredSize.Width / diagram.Zoom);
double pos = diagram.Viewport.Left + visibleWidth;
if (pos - xOffset > diagram.ActualWidth)
{
//e.Handled = true;
xOffset += (int)((pos - xOffset) - diagram.ActualWidth);
}
}
else if (xOffset > 0)
{
if (diagram.Viewport.Left - xOffset < 0)
{
//e.Handled = true;
xOffset += (int)diagram.Viewport.Left - xOffset;
}
}
if (Math.Abs(xOffset) != 0 || Math.Abs(yOffset) != 0)
{
diagram.Position = new Point(diagram.Position.X + xOffset, diagram.Position.Y + yOffset);
}
oldPosition = new Point(oldPosition.X + xOffset, oldPosition.Y + yOffset);
}
}
}