How to Export the Visible Area Within the ViewPort in WPF Diagram?
In the WPF Diagram, you can export only the visible area within the Viewport using the Clip property of the ExportSettings class. To achieve this, set the Clip property with the current viewport’s HorizontalOffset, VerticalOffset, ViewportWidth, and ViewportHeight values, calculated based on the viewport’s CurrentZoom level. We have provided the code example for how to achieve this.
private void Button_Click(object sender, RoutedEventArgs e)
{
String Extension;
var zoom = diagram.ScrollSettings.ScrollInfo.CurrentZoom;
var offsetX = diagram.ScrollSettings.ScrollInfo.HorizontalOffset;
var offsetY = diagram.ScrollSettings.ScrollInfo.VerticalOffset;
var width = diagram.ScrollSettings.ScrollInfo.ViewportWidth;
var height = diagram.ScrollSettings.ScrollInfo.ViewportHeight;
offsetX = offsetX / zoom;
offsetY = offsetY / zoom;
width = width / zoom;
height = height / zoom;
ExportSettings settings = new ExportSettings()
{
Clip = new Rect(offsetX, offsetY, width, height),
};
diagram.ExportSettings = settings;
settings.ExportType = Syncfusion.UI.Xaml.Diagram.Controls.ExportType.JPEG;
Extension = ("JPEG File(*.jpeg)|*.jpeg");
SaveFileDialog m_SaveFileDialog = new SaveFileDialog();
m_SaveFileDialog.Filter = Extension;
bool? istrue = m_SaveFileDialog.ShowDialog();
if (istrue == true)
{
string fileName = m_SaveFileDialog.FileName;
//Assigning export stream from the saved file
diagram.ExportSettings.FileName = fileName;
(diagram.Info as IGraphInfo).Export();
}
}
Conclusion
I hope you enjoyed learning about how to export the visible Area within the viewport in WPF Diagram.
You can refer to our WPF Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Diagram example to understand how to create and manipulate data
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!