Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将RDLC窗口更改为UserControl_C#_Wpf - Fatal编程技术网

C# 将RDLC窗口更改为UserControl

C# 将RDLC窗口更改为UserControl,c#,wpf,C#,Wpf,您好,当我点击我的“业务列表”按钮时,它将显示我的报告窗口,其中包含相应的信息。我试图让它显示在我的ShellView中,而不是“窗口弹出” 旧代码 PreviewForm.xaml <Window ....... <Grid> <WindowsFormsHost Name="MyHost" Margin="0,0,0,0" Visibility="Visible"> <rv:ReportViewer x:

您好,当我点击我的“业务列表”按钮时,它将显示我的报告窗口,其中包含相应的信息。我试图让它显示在我的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>
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);
    }
}
在我的ReportViewModel中,我使用了
preview.Update()

它目前只显示一个空白的白色屏幕

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

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


这不是最科学的方法,但可以为您提供一些可视化工具。也有类似的工具可以提供帮助

也许您需要向更新方法添加一个调度程序,因为您的调用现在来自viewmodel:

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

Prism
还是您只是使用
DataTemplate的
更改视图?您的问题非常严重,您需要通过调试将其分解,否则每个人都会不断猜测问题出在哪里?
<shell:GridScreenControl.Grid>
    <Grid >
        <panes:ReportPreviewForm/>
    <Grid >
</shell:GridScreenControl.Grid>
public void Update()
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();
    }
}