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

2 posts, 0 answers
  1. Terry
    Terry avatar
    2 posts
    Member since:
    Nov 2012

    Posted 25 Jan 2013 Link to this post

    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,








     
  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 30 Jan 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top