Hosting Telerik WPF Reports. In Widows Forms App

1 Answer 22 Views
.NET Framework Report Viewer - WPF
Mark
Top achievements
Rank 1
Mark asked on 17 May 2021, 05:58 AM

We have a Winforms App that has an embedded WPF Telerik Reporting User Control

It works fabulously until search. The Search Button on the Telerik Report Launches a Modeless Window with the ComboBox for Searching. The Rub comes between The ElementHost and the WPF Control. When A WPF Control Hosted by Winforms uses Modeless operations the WPF Control must call a Static method to Enable Modeless opetion from a static Method

ElementHost.EnableModelessKeyboardInterop(Window wpfHostedWindow)

My Question is will my embedded control (item 1)  be sufficient for the wpfHostedWindow?

Or will i need to pass the actual Find Window (item 2)?

Or the ComboBox Source (item 3)

 

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 19 May 2021, 03:05 PM

Hello Mark,

This is a custom scenario that we haven't tested. For that reason, I cannot advise on the requirement.

I can share the solution of another user with the same scenario. He found the correct window on the LostKeyboardFocus event of the WPF Report Viewer. Although it worked, it was more like a makeshift solution to the current problem.

Here is the relevant code he shared with us:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        
    }
    private object WinFormCallback(String SourceField, Object[] Parameters)
    {
        ElementHost.EnableModelessKeyboardInterop(Parameters[0] as System.Windows.Window);
        return null;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        WpfLibrary.Report report = new WpfLibrary.Report();
        wpfElementHost.Child = report;
        report.WinFormCallbackDelegate = WinFormCallback;
    }
}


namespace WpfLibrary
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    /// 

    public interface IElementHostSupport
    {
        void OnWindowAdded(System.Windows.Window window);
    }
    public partial class Report : IElementHostSupport
    {
        public delegate Object WinFormCallback(String Source, Object[] Params);
        public Report()
        {
            InitializeComponent();
            LoadReport();
        }

        public void OnWindowAdded(System.Windows.Window window)
        {
            if (window != null && WinFormCallbackDelegate != null)
                WinFormCallbackDelegate("Report", new object[] { window });
        }
        public WinFormCallback WinFormCallbackDelegate
        {
            get;
            set;
        }
        private void LoadReport()
        {
            Telerik.Reporting.UriReportSource urisource = new Telerik.Reporting.UriReportSource();
            urisource.Uri = @"C:\Users\abhilashc\source\repos\TelerikSearchBug\WpfLibrary\TestReport.trdp";
            var instanceReportSource = new Telerik.Reporting.InstanceReportSource();
            instanceReportSource.ReportDocument = UnpackageReport(urisource);
            tReportViewer.ReportSource = instanceReportSource;
            tReportViewer.LostKeyboardFocus += (s1, e1) =>
            {

                tReportViewer.Dispatcher.BeginInvoke((Action)(() =>
                {
                    IList<WindowBase> windows = RadWindowManager.Current.GetWindows();
                    if (windows.Count > 0)
                    {
                        OnWindowAdded(windows[0].GetVisualParent<System.Windows.Window>());
                    }
                }), System.Windows.Threading.DispatcherPriority.ContextIdle);
            };
        }
        Telerik.Reporting.Report UnpackageReport(UriReportSource uriReportSource)
        {
            var reportPackager = new ReportPackager();
            using (var sourceStream = System.IO.File.OpenRead(uriReportSource.Uri))
            {
                var report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                return report;
            }
        }
    }
}
Regards,
Todor
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
.NET Framework Report Viewer - WPF
Asked by
Mark
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or