How to cancel a document rendering

Attachments

In order to cancel a report rendering you can use the StopRendering() method of the ReportViewer object. The report rendering will be canceled, and the view model will return to the previous state (if the report was displayed before the rendering, then it will be displayed again).

Example:

MainPage.xaml.cs

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
 
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            reportViewer.ReportName = 
            "/AdventureWorks 2008 Sample Reports/Report List 2008";
 
            if (HtmlPage.IsEnabled == false)
            {
                reportViewer.ServiceUrl = 
                "http://localhost:51286/ReportService.svc";
                reportViewer.DebugMode = DebugModeEnum.Full;
            }
            else
            {
                SilverlightInitParamsHelper initParamsHelper =
                new SilverlightInitParamsHelper
                (HtmlPage.Plugin.GetProperty("initParams").ToString());
                reportViewer.ServiceUrl = initParamsHelper.ServiceUrl;
                reportViewer.DebugMode = initParamsHelper.DebugMode;
            }
 
            reportViewer.ApplyTemplate();
            reportViewer.RenderDocument();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            reportViewer.StopRendering();
        }
    }

MainPage.xaml

<UserControl x:Class="SilverlightApplication58.MainPage"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 xmlns:ReportViewer=
       "clr-namespace:PerpetuumSoft.ReportingServices.Viewer.Client;
       assembly=PerpetuumSoft.ReportingServices.Viewer.Client"
 mc:Ignorable="d"
 d:DesignHeight="300" d:DesignWidth="400">
 
 <Grid x:Name="LayoutRoot" Background="White">
  <Grid.RowDefinitions>
   <RowDefinition Height="35"/>
   <RowDefinition/>
  </Grid.RowDefinitions>
 
 <Grid Grid.Row="0">
  <Grid.ColumnDefinitions>
   <ColumnDefinition />
    <ColumnDefinition />
    <ColumnDefinition />
   </Grid.ColumnDefinitions>
  <Button Margin="4" Content="Stop Render" Click="Button_Click"/>
 </Grid>
  <ReportViewer:ReportViewer x:Name="reportViewer" Grid.Row="1"/>
 </Grid>
</UserControl>

Add Feedback