简体   繁体   中英

Active Reports winforms viewer control hosted in WPF Window

There is currently not an available WPF viewer for Active Reports 6 . I was attempting to use a host control to display the viewer in a interop host but I'm not having much luck. Has anyone else attempted this successfully? I can't even get the wrapper Viewer control to add to the project toolbox as a custom control at this point. I'm hoping to avoid recreating the wheel.

The existing ActiveReports Viewer works fine in WPF. You can use the below XAML to host it in WPF:

<Window x:Class="ARViewerHostedInWpf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:arv="clr-namespace:DataDynamics.ActiveReports.Viewer;assembly=ActiveReports.Viewer6"  
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Grid>
        <WindowsFormsHost Name="windowsFormsHost1">
            <arv:Viewer x:Name="ARViewer" Dock="Fill" />
        </WindowsFormsHost>
    </Grid>
</Window>

The following code in the code-behind of the XAML file will connect a report to the viewer in the XAML above and run it:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        NewActiveReport1 rpt = new NewActiveReport1();
        this.ARViewer.Document = rpt.Document;
        rpt.Run();
    }
}

I'm using the currently available version of ActiveReports 6 to test this.

Hope this helps!

Scott Willeke
GrapeCity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM