Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Silverlight reporting datacontext issue (Read 5954 times)
Vikas Kumar
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 1st, 2011
Silverlight reporting datacontext issue
Mar 1st, 2011 at 11:54am
Print Post  
Hi,
I am evaluating your silverlight reporting for our new project.

I have a usercontol for reporting which contains the mind funsion report viewer. I have supplied a view model class to the user control as its datacontext. The viewmodel class has a public property which contains a list<VehicleInfoList>. In the report.xaml under the ResourceDictionary I have provided :<r: DataRange Location="0,20" Size="100%,20" DataSource="{Binding Path=VehicleInfoList}" >. The code written in the main.cs is :
Code
Select All
 void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var report = Report.FromDictionary(new Uri("/ReportDemo;component/MyReport.xaml", UriKind.Relative), "myReport");

            ReportViewModel rvm = new ReportViewModel();
            reportControl.DataContext = rvm;.

            report.Run();
            reportControl.reportViewer.Document = report;
}

 



Will you please help me to find out why the reoprt is not generating.

If I provide : report.DataContext = rvm.VehicleInfoList it works fine.
But I need to give the datacontext to the reportcontrol which contains the reportviewer.

Code for report.xaml :

Code
Select All
<r:Report x:Key="myReport">
        <r:Page>
            <r:DataRange Location="0,20" Size="100%,20" DataSource="{Binding Path=VehicleInfoList}" >
                <r:DataRange.HeaderTemplate>
                    <DataTemplate>
                        <r:ItemContainer Size="100%,20">
                            <r:Label Text="Name" Location="0%,0" Size="20%,20" />
                            <r:Label Text="Rating" Location="20%,0" Size="20%,20" />
                            <r:Label Text="Cost" Location="40%,0" Size="20%,20" />
                            <r:Label Text="Weight" Location="60%,0" Size="20%,20" />
                            <!--<r:Label Text="UnitsInStock" Location="80%,0" Size="20%,20" />-->
                        </r:ItemContainer>
                    </DataTemplate>
                </r:DataRange.HeaderTemplate>

                    <r:DataRange.ItemTemplate>
                    <DataTemplate>
                        <r:ItemContainer>
                            <r:Label Text="[Name]" Location="0%,0" Size="20%,20" />
                            <r:Label Text="[Rating]" Location="20%,0" Size="20%,20" />
                            <r:Label Text="[Cost]" Location="40%,0" Size="20%,20" />
                            <r:Label Text="[Weight]" Location="60%,0" Size="20%,20" />
                            <!--<r:Label Text="[UnitsInStock]" Location="80%,0" Size="20%,20" />-->
                        </r:ItemContainer>
                    </DataTemplate>
                </r:DataRange.ItemTemplate>
            </r:DataRange>


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



ReportViewModel Code:

Code
Select All
public class ReportViewModel
    {

        public List<VehicleInfo> VehicleInfoList { get; set; }

        public ReportViewModel()
        {

            Init();
        }

        private void Init()
        {
            VehicleInfoList = new List<VehicleInfo>();

            VehicleInfoList.Add(new VehicleInfo { Name = "Vehicle1", Rating = 5.0, Uses = 3, Cost = 10, Weight = 5 });
            VehicleInfoList.Add(new VehicleInfo { Name = "Vehicle2", Rating = 4.0, Uses = 4, Cost = 12, Weight = 6 });
            VehicleInfoList.Add(new VehicleInfo { Name = "Vehicle3", Rating = 3.0, Uses = 5, Cost = 15, Weight = 4 });
            VehicleInfoList.Add(new VehicleInfo { Name = "Vehicle4", Rating = 6.0, Uses = 7, Cost = 14, Weight = 7 });
        }



    }
 



ReportControl.xaml :

Code
Select All
<UserControl x:Class="ReportDemo.ReportControl"
    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"
    mc:Ignorable="d"
    xmlns:report="http://mindfusion.eu/reporting/silverlight"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">

        <report:ReportViewer Name="reportViewer" />

    </Grid>
</UserControl>
 



Regards
Vikas
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Silverlight reporting datacontext issue
Reply #1 - Mar 2nd, 2011 at 8:47am
Print Post  
Hi,

The problem is caused by the fact that the Run method is invoked before the report is part of the object tree. And if the report is not part of the tree, it does not inherit the DataContext property you have set on the root. To fix this, try running the report after associating it with the viewer:

Code
Select All
reportControl.reportViewer.Document = report;
report.Run(); 


However, while we were inspecting your case, we came across an issue within the report, which has been subsequently fixed. Please, use the updated version below:

https://mindfusion.eu/_rep_trial/MindFusion.Reporting.Silverlight.trial.zip

Let me know if this works.

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


I love YaBB 1G - SP1!

Posts: 18
Joined: Mar 1st, 2011
Re: Silverlight reporting datacontext issue
Reply #2 - Mar 2nd, 2011 at 9:31am
Print Post  
Thanks for the quick reply. The new dll sent by you fixed the problem

In the sample codes
report.Run(); comes before reportViewer.Document = report;
sample code:
Code
Select All
var report = Report.FromDictionary(new Uri("/Tutorial1;component/MyReport.xaml", UriKind.Relative), "myReport");



report.DataContext = products;



report.Run();




reportViewer.Document = report;

 



So I did the same in my code. But even after reversing as suggested by you it didn't work.

It only worked after replacing the old dll with the new one provided by you.

anyways thanks for the assistance.

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