将RDLC窗口更改为UserControl

本文关键字:UserControl RDLC 窗口 | 更新日期: 2023-09-27 18:27:25

你好,当我单击"业务列表"按钮时,它将显示我的报告窗口,其中包含适当的信息。我试图让它显示在我的ShellView中,而不是"弹出窗口"。

旧代码

预览表单.xaml

<Window .......
    <Grid> 
         <WindowsFormsHost Name="MyHost" Margin="0,0,0,0" Visibility="Visible">
             <rv:ReportViewer x:Name="_reportViewer" ForeColor="AliceBlue" Visible="True" Dock="Fill"/>
        </WindowsFormsHost>
    </Grid>
</Window>

预览表单.xaml.cs

public string reportSource { get; set; }
public Microsoft.Reporting.WinForms.ReportDataSource reportDataSource { get; set; }
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    try
    {
        this._reportViewer.Reset();
        this._reportViewer.LocalReport.ReportEmbeddedResource = this.reportSource;
        this._reportViewer.LocalReport.DataSources.Clear();
        this._reportViewer.LocalReport.DataSources.Add(this.reportDataSource);
        this._reportViewer.LocalReport.Refresh();
        this._reportViewer.RefreshReport();
    }
    catch (Exception Ex)
    {
        Ex.ToString();
    }
}

ReportViewModel

public void BusinessListing()
{
    try
    {
        BindableCollection<BusinessDTO> Firms;
        using (var ctx = DB.Get())
        {
            Firms = new BindableCollection<BusinessDTO>(BusinessDTO.ReportBusiness(ctx));
        }
        Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new            Microsoft.Reporting.WinForms.ReportDataSource();
        reportDataSource1.Name            = "BusinessDTO";
        reportDataSource1.Value           = Firms;
        Reports.ReportPreviewForm preview = new Reports.ReportPreviewForm();
        preview.reportDataSource          = reportDataSource1;
        preview.reportSource              = "Reports.ListingReports.BusinessListingReport.rdlc";
        preview.Show();
    }
    catch (Exception Ex)
    {
        MessageBox.Show(Ex.Message);
    }
}

ReportGridView

<shell:GridScreenControl.Grid>
    <Grid >
        <panes:ReportPreviewForm/>
    <Grid >
</shell:GridScreenControl.Grid>

添加。

我将PreviewForm转换为UserControl。

更改的Window_Loaded=>

public void Update()

在我的ReportViewModel中,而不是preview.Show()中,我有preview.Update()它目前只显示一个空白的白色屏幕。

将RDLC窗口更改为UserControl

我认为您需要告诉您的窗格填充网格吗?在原始代码中,您使用Dock="Fill"来告诉报告填充窗口。你为什么不试试这个,或者在网格、窗格和窗口中添加一些固定的高度和宽度,看看这是否是问题所在。

您还可以设置窗口的背景色(如蓝色)和网格(如绿色),以查看它们是否确实被窗格覆盖。

这不是最科学的方法,但它为您提供了一些视觉工具。还有一些像WPF Snoop这样的工具可以提供帮助。

也许您需要在更新方法中添加一个调度器,因为您的调用现在源自视图模型:

private Dispatcher _dispatcher; // In class
_dispatcher = Dispatcher.CurrentDispatcher; // In constructor
public void Update()
{
    try
    {
        _dispatcher.BeginInvoke(new Action(() =>
        {
            this._reportViewer.Reset();
            this._reportViewer.LocalReport.ReportEmbeddedResource = this.reportSource;
            this._reportViewer.LocalReport.DataSources.Clear();
            this._reportViewer.LocalReport.DataSources.Add(this.reportDataSource);
            this._reportViewer.LocalReport.Refresh();
            this._reportViewer.RefreshReport();
        }));
    }
    catch (Exception Ex)
    {
        Ex.ToString();
    }
}