We are making an application that needs to bind to a data object that we defined in a similar fashion to what is described in the documentation on page 43.
However, we are running into an issue within the report designer when we try to add this as a data source. It is not selectable. The problem seems to be that our object type has a constructor that requires several parameters; this is the reason why it does not seem to be selectable. When we add a default constructor back into the code, it works. You can try it with the code supplied in the documentation. Within the project class, add a constructor that takes in one or more arguments and it will then cease to be able to be bind-able.
Is this a bug? An oversight? Or just a requirement that must be lived with? It just seems odd that we should have to define a default constructor for this just to be able to bind to this object.
On a related note, is it possible to make the object type an interface? So far it doesn't seem to be supported unless the object type is a concrete class. Is this by design or is this something that might change in later builds?
One last question... is the design team aware of random crashes that happen periodically while within the report designer? I wish I had more information about these crashes at the moment, but I can't seem to replicate this now that I need it to happen.
Overall, I think you guys are doing a great job with this tool and it seems to be coming along very nicely.
Hi,
If I understand correctly you have something like this:
public class ObjectSource
{
public ObjectSource(int a) { }
public IEnumerable<Product> GetProducts()
List<Product> products = new List<Product>();
for (int i = 0; i < 10; i++)
products.Add(new Product() { Code = i, Price = i * 1.5, });
}
return products;
This is not supported right now. Instead of adding the default constructor you can define GetProducts() as static receiving the parameters you need, as follows:
public static IEnumerable<Product> GetProducts(int a)
Do this works for you?
In the CTP there was a limitation that doesn’t allow creating ODS from an interface. We will review this for V1.
We are not aware of those crashes. Is this happening often? Do you remember what you were doing when it crash? Can you give me more information about your system configuration?
Thanks a lot for your feedback!
Leo
// populate list
public class Product
public Product (int a)
This is more so what I was talking about. This code only works if Product also has a constructor that takes zero arguments.
Pertaining to the crash, I wish I had more detailed information to give you, but it simply crashes frequently and without error messages when I am working with controls directly in the designer. I noticed that when I fill in the content of labels and tables through the fields in the property grid, I do not seem to crash at all. The crashes only occur when I am working with the GUI itself.
My version of Visual Studio is 10.0.40219.1 SP1Rel.
My system is a Dell Latitude M60
Operating System: Windows XP Pro SP 3
CPU: Intel Pentium M @ 1.8 Ghz
2.00 GB RAM.
I tried with that code and I could create the object data source. Can you send me the exact code you are using?
Thanks,
I wasn't thinking straight. Your first example was correct. You gave a couple workarounds, but do you know if they will still be necessary for the V1 release?
I found a couple more issues as well during my usage of this software.
1) When the datasource object is being connected to the report designer using the methodology that has been discussed here, properties & data from any potential base classes do not get pulled.
For instance...
public class BaseDatasource { public string BaseProperty { get; set; } public BaseDatasource(string base_property) { BaseProperty = base_property; } } public class Datasource1 : BaseDatasource { public int Number { get; set; } public string Word { get; set; } public string Label { get; set; } public Datasource1(int num, string word, string label, string property) : base(property) { Number = num; Word = word; Label = label; } } public class ObjectSource { List<Datasource1> list = new List<Datasource1>(); public IEnumerable<Datasource1> getData() { return list; } }
public class BaseDatasource { public string BaseProperty { get; set; } public BaseDatasource(string base_property) { BaseProperty = base_property; } }
public class Datasource1 : BaseDatasource { public int Number { get; set; } public string Word { get; set; } public string Label { get; set; } public Datasource1(int num, string word, string label, string property) : base(property) { Number = num; Word = word; Label = label; } }
public class ObjectSource { List<Datasource1> list = new List<Datasource1>(); public IEnumerable<Datasource1> getData() { return list; } }
Only the properties in Datasource1 get pulled -- what is in BaseDatasource gets ignored. This does not seem like suitable behavior. Is there any idea if this will be changed by V1?
2) When TargetDataSource is being bound to through xaml to set a datasource, an error message is displayed in the reportviewer during runtime for the first few seconds until the report is finally displayed. The reportviewer then works appropriately, but this overall behavior does not seem ideal from a user experience standpoint. Are you aware of this? Any current plans relating to this?
Thanks.
Yes for V1 you would have to use those workarounds. How does it affect you?
1) This is a bug. It will be fixed for V1.
2) I can’t reproduce the behavior you mention. Can you give me more details about how you are setting the data sources in the XamlReportViewer?
Here's the code that I'm using.
ReportViewer xaml:
<ig:XamReportViewer Name="xamReportViewer1"> <ig:XamReportViewer.RenderSettings> <ig:ClientRenderSettings DefinitionUri= "{Binding Path=ReportDefinition}"> <ig:ClientRenderSettings.DataSources> <ig:DataSource ItemsSource="{Binding Path=GetData}" TargetDataSource="{Binding Path=ReportSource}"/> </ig:ClientRenderSettings.DataSources> </ig:ClientRenderSettings> </ig:XamReportViewer.RenderSettings> </ig:XamReportViewer>
C# code/Binding Location:
private List<Datasource1> data = new List<Datasource1>(); public IEnumerable<Datasource1> GetData { get { return data; } } private string _reportDefinition = "MVVMexample.Reports.Report1.igr, MVVMexample"; public String ReportDefinition { get { return this._reportDefinition; } } private string _reportSource = "Datasource1"; public String ReportSource { get { return this._reportSource; } }
private List<Datasource1> data = new List<Datasource1>();
public IEnumerable<Datasource1> GetData { get { return data; } }
private string _reportDefinition = "MVVMexample.Reports.Report1.igr, MVVMexample"; public String ReportDefinition { get { return this._reportDefinition; } } private string _reportSource = "Datasource1"; public String ReportSource { get { return this._reportSource; } }
This is some basic example code that functions correctly; however, on every machine I've tested it on there is an error message being displayed in the ReportViewer until the report finally gets displayed seconds later. The error message is simply "An unknown error occurred while processing the report."
When I replace the TargetDataSource binding in xaml with a literal string, "Datasource1", this behavior goes away. Instead of the error message, the loading report icon appears until the report is ready to be viewed.
I found a further piece of information that I just discovered. When this scenario is in play: exporting, printing, and the page settings buttons on the toolbar do not work until the refresh button is pressed on the toolbar. They are simply greyed out and unclickable.
Are there any updates on this issue?
I also noticed that when I start doing data bindings in xaml, I get a couple error messages on the debugger whenever the xamreportviewer gets displayed.
System.Windows.Data Error: 40 : BindingExpression path error: 'ParameterControlViewModels' property not found on 'object' ''MainWindowVM' (HashCode=43140121)'. BindingExpression:Path=ParameterControlViewModels; DataItem='MainWindowVM' (HashCode=43140121); target element is 'ItemsControl' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
System.Windows.Data Error: 40 : BindingExpression path error: 'SubmitCommand' property not found on 'object' ''MainWindowVM' (HashCode=43140121)'. BindingExpression:Path=SubmitCommand; DataItem='MainWindowVM' (HashCode=43140121); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')
These don't seem to be a cause of my problem, but I'm also curious as to why they are being displayed. Is this just the beginnings of something in the code that will be fleshed out for the future release?
I've included an example solution that's pretty bare bones and should show you the basics of the problem I'm running into. I set the datacontext property to the correct viewmodel whenever I create the xamreportviewer user control in my mainwindowVM.
I tried out the code you sent and I still can’t reproduce the problem. Where/how are you initializing the DataContext property?