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 :
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 :
<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:
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 :
<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