将RDLC窗口更改为用户控件

4

你好,目前当我点击“商业列表”按钮时,它会显示出适当信息的报告窗口。我想让它在我的ShellView中显示,而不是弹出一个“窗口”。

旧代码

PreviewForm.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>

PreviewForm.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();
    }
}

报告视图模型

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);
    }
}

报告网格视图

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

新增内容。

我将 PreviewForm 转换为 UserControl。

更改 Window_Loaded =>

public void Update()

在我的 ReportViewModel 中,我使用 preview.Update() 而不是 preview.Show()。但目前只显示一个空白的白屏。


是使用 Prism 还是仅通过 DataTemplate 更改视图? - StepUp
你的问题非常高级,你需要通过调试将其分解,否则大家会一直猜测问题在哪里。 - Kylo Ren
2个回答

0
也许你需要在更新方法中添加一个调度程序,因为现在你的调用是来自于视图模型的:
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();
    }
}

0

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

你也可以设置窗口(比如蓝色)和网格(比如绿色)的背景颜色,看看它们是否被窗格覆盖了。

这并不是最科学的方法,但是给你一些可视化工具来处理。还有像 WPF Snoop 这样的工具可以帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接