This is a migrated thread and some comments may be shown as answers.

WPF Diagram ExportToImage (to png) has shape connectors visible on selected shapes.

1 Answer 113 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 25 Jan 2013, 04:15 PM
When using ExportToImage (with the WPF Q3 2012 SP1 version) on a diagram with some shapes selected, the resultant image has the selected shape connectors rendered. See attached screen capture as an example. 

I have tried to DeselectAll(), setting IsConnectorsManipulationEnabled false and setting  IsManipulationAdornerVisible false just before exporting but none had any effect.

So is there a way of exporting the shapes without rendering the connectors of selected shapes ?

Many Thanks,








 

1 Answer, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 30 Jan 2013, 09:21 AM
Hi Terry,
You're seeing the connectors because they are part of the RadDiagramShape and we can't export the shape without them. As a workaround you could indeed deselect the items but you'll have to do it a little bit earlier than the export so that the diagram will have time to update its layout:
private void RadButton_Click(object sender, RoutedEventArgs e)
{
    var selectedItems = this.diagram.SelectedItems.ToList();
    this.diagram.DeselectAll();
 
    var dialog = new SaveFileDialog();
    dialog.DefaultExt = "png";
    dialog.Filter = string.Format("{1} File (*.{0}) | *.{0}", "png", "png");
 
    if (!(bool)dialog.ShowDialog())
    {
        this.SelectItems(selectedItems);
        return;
    }
 
    using (var fileStream = dialog.OpenFile())
    {
        this.diagram.ExportToImage(fileStream, backgroundBrush: diagram.Background, margin: new Thickness(20));
    }
    this.SelectItems(selectedItems);
}
 
private void SelectItems(List<object> selectedItems)
{
    foreach (var item in selectedItems)
    {
        var container = this.diagram.ContainerGenerator.ContainerFromItem(item);
        if (container != null)
            container.IsSelected = true;
    }
}
Or if you want you could use a dispatcher:
private void RadButton_Click(object sender, RoutedEventArgs e)
{
    var dialog = new SaveFileDialog();
    dialog.DefaultExt = "png";
    dialog.Filter = string.Format("{1} File (*.{0}) | *.{0}", "png", "png");
 
    if (!(bool)dialog.ShowDialog())
        return;
 
    var selectedItems = this.diagram.SelectedItems.ToList();
    this.diagram.DeselectAll();
    this.Dispatcher.BeginInvoke(new Action(() =>
    {
        using (var fileStream = dialog.OpenFile())
        {
            this.diagram.ExportToImage(fileStream, backgroundBrush: diagram.Background, margin: new Thickness(20));
        }
        this.SelectItems(selectedItems);
    }), System.Windows.Threading.DispatcherPriority.SystemIdle);
}
I hope I was able to help you and if you have further questions please feel free to ask.

Kind regards,
Zarko
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Diagram
Asked by
Terry
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Share this question
or