Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Adding silverlight control to report at run time (Read 6662 times)
Vikas Kumar
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 1st, 2011
Adding silverlight control to report at run time
Mar 3rd, 2011 at 12:15pm
Print Post  

Hi Meppy

Need your help again.
In my report I need to add a silverlight control at run time while printing.
Code
Select All
<r:Report x:Key="myReport" >
        <r:Page >
 <r:CustomReportItem  Location="0,50" Size="50%,200" x:Name="custReportItem" >
                <r:CustomReportItem.Template >
                    <DataTemplate x:Name="dm">
                        <StackPanel  x:Name="stkData" >

                        </StackPanel>
                    </DataTemplate>
                </r:CustomReportItem.Template>
           </r:CustomReportItem>

<r:Page.FooterTemplate>
                <DataTemplate>
                    <r:ItemContainer Size="100%,25">
                        <r:Label Text="This is the page footer" Size="100%,45" Background="Orange"
                                        HorizontalAlignment="Center" VerticalAlignment="Bottom" />
                    </r:ItemContainer>
                </DataTemplate>
            </r:Page.FooterTemplate>





        </r:Page>
    </r:Report>

 



At runtime while printing the report I want to add a usercontrol in the stackPanel named "stkData" in the code.
Code
Select All
private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            Stack Panel stk= report.FindName("stkData") as StackPanel

           stk.Children.Add(new DataControl());

            ReportPrinter reportPrinter = new ReportPrinter(report);

           reportPrinter.Print();

        }

 



It is not working. can you please assist me in this.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Adding silverlight control to report at run ti
Reply #1 - Mar 3rd, 2011 at 2:40pm
Print Post  
The most natural option would be to define the content of the stack panel in the report itself:

Code
Select All
<r:CustomReportItem  Location="0,50" Size="50%,200">
      <r:CustomReportItem.Template>
            <DataTemplate>
                  <StackPanel>
                        <local:DataControl />
                  </StackPanel>
            </DataTemplate>
      </r:CustomReportItem.Template>
</r:CustomReportItem> 


Then the DataControl will be loaded automatically when the report is rendered or printed.

However, if you want to modify the contents of the stack panel dynamically, you have two options. Both of them require to handle the Report.Prerender event. The easier of the two approaches simply uses the custom report item as a placeholder. Then, in the Prerender event handler this placeholder is replaced with a stack panel and the content of the stack panel can be modified dynamically. Define an empty 'placeholder' item:

Code
Select All
<r:CustomReportItem  Location="0,50" Size="50%,200" x:Name="custReportItem" /> 


Then replace this item before rendering within the Prerender event handler:

Code
Select All
if (e.Item.Name == "custReportItem")
{
      StackPanel panel = new StackPanel();
      panel.Children.Add(new DataControl());

      e.RootVisual = panel;
} 


The second approach is to dig up the stack panel from the RootVisual passed as argument to the Prerender event. The RootVisual of a CustomReportItem is a ContentControl. However, at the time the Prerender event is called the template of this control is not yet loaded so the stack panel is not created. Therefre you have to additionally listen to the ContentControl's Loaded event before you are able to find the stack panel in the visual tree.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Vikas Kumar
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 1st, 2011
Re: Adding silverlight control to report at run ti
Reply #2 - Mar 4th, 2011 at 8:17am
Print Post  
Thanks for the assistance again.
I needed to add some control to the report for printing purpose only not to show in the report viewer document.

The pre render event handling Suggested by you works fine for my requirement.

Regards
Vikas
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint