1

I am a beginner in WPF (and C# in XAML in general) and currently trying to save a Grid filled with WindowsFormsHosts (modified as given here for compatibility with ScrollViewer) in turn containing charts from DataVisualization.Charting to an image.

I've tried both of the answers to this question - using the Grid as the 'content' for the first answer - with no avail (saves a black image of the correct dimensions)

The snippet below is my current layout. Any XY problem challenges - such as a way to render DataVisualization.Charting charts without using WindowsFormsHost - are welcome, as I am very much a greenhorn. However the ScrollViewers are needed due to the size of the full Grid, and the entire Grid (including the area that needs to be scrolled to) must be saved in its entirety.

 <TabControl x:Name="tabcontrol" Margin="5,0">
        <TabItem Header="1" Width="30" Visibility="Hidden" Name="tabitem0">
            <ScrollViewer Margin="5" CanContentScroll="False" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" Name="Scroll">

                <Grid x:Name="ChartGrid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>


                    <wpfrichtextbox:ScrollViewerWindowsFormsHost x:Name="Chart1" Visibility="Visible"  Grid.Row="0" Grid.Column="1" Margin="0" 
                        HorizontalAlignment="Center" VerticalAlignment="Center"/> //A DataVisualization.Charting chart contained in each WindowsFormsHost, repeated throughout Grid
                </Grid>
            </ScrollViewer>
        </TabItem>
    </TabControl>
mantra
  • 69
  • 2
  • 1
    Why not wpf controls?https://www.nuget.org/packages/DotNetProjects.WpfToolkit.DataVisualization/ – Andy Jun 21 '21 at 09:01
  • I don't see a clean way with those WindowsFormsHosts in place. Basically, a HWND and a rectangle gets passed, and the contained control then draws to that window and region however and whenever it likes. I strongly agree with @Andy to switch the DataVisualization.Charting to a native WPF control. – Alexander Gräf Jun 24 '21 at 17:37

0 Answers0