Hi,
I am building a Silverlight application using Prism 4. An extended version of the Infgragistics DataSourceBase is being used to supply data to a xamPivotGrid as well as other types of visualisation i.e. Column Chart, Bar Chart, Stacked Column etc.
If the data source has been populated with measures, rows or columns and the view is switched to the pivot grid (using Prism's view discovery) the grid fails to initialize with the following error:
{System.NullReferenceException: Object reference not set to an instance of an object. at Infragistics.Controls.Grids.PivotGridLayout.InitializeLayout()}
If the pivot grid is accessed prior to any dimensions or measures being added then it works as expected.
Any advice would be greatly appreciated as this is really holding us up at the moment.
Regards,
Chris
Hi
It seems it is an issue with layout system of the control. Could you post the whole call stack and more details about how you use prism4 and pivot grid
ThanksTodor
Hi Todor, thanx for coming back to me on this.
We use the xamPivotGrid as one of a number of different visualisation options provided to the user in order to analyse multi-dimensional data. We have the idea of a visualisation provider that uses Prism's view discovery mechnism to load a given visualisation into a Prism region within the main content area of the shell application:
_regionManager.RequestNavigate(RegionNames.VisualisationRegion, opt.VisualisationViewUri);
Each VisualisationViewUri is a URI to a Silverlight User Control that hosts the given visualisation i.e.
xamPivotGrid/xamDataGrid/xamWebChart (with a number fo different configurations)
We are using MVVM to bind the DataSource to the grid as follows:
<Views:VisualisationBase x:Class="Insurer.Analytics.Common.Visualisations.Views.PivotGridVisualisation" 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:ig="http://schemas.infragistics.com/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Views="clr-namespace:Insurer.Analytics.Common.Visualisations.Views" d:DesignHeight="300" d:DesignWidth="400" mc:Ignorable="d"> <ig:XamPivotGrid DataSource="{Binding AnalyticsDataSource}" /></Views:VisualisationBase> The data source that is part of the underlying view model will always have been initialised prior to the RequestNavigate method being called. As mentioned if I simply stick a pivot grid into the main content area and bind it to the view model everything works as expected. Full stack trace below: Message: Unhandled Error in Silverlight Application Code: 4004 Category: ManagedRuntimeError Message: System.NullReferenceException: [Arg_NullReferenceException]Arguments: Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.60129.0&File=mscorlib.dll&Key=Arg_NullReferenceException at Infragistics.Controls.Grids.PivotGridLayout.InitializeLayout() at Infragistics.Controls.Grids.XamPivotGrid.ArrangeLayout() at Infragistics.Controls.Grids.XamPivotGrid.OnApplyTemplate() at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget) Line: 63Char: 13
<Views:VisualisationBase x:Class="Insurer.Analytics.Common.Visualisations.Views.PivotGridVisualisation" 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:ig="http://schemas.infragistics.com/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Views="clr-namespace:Insurer.Analytics.Common.Visualisations.Views" d:DesignHeight="300" d:DesignWidth="400" mc:Ignorable="d"> <ig:XamPivotGrid DataSource="{Binding AnalyticsDataSource}" /></Views:VisualisationBase>
The data source that is part of the underlying view model will always have been initialised prior to the RequestNavigate method being called.
As mentioned if I simply stick a pivot grid into the main content area and bind it to the view model everything works as expected.
Full stack trace below:
Message: Unhandled Error in Silverlight Application Code: 4004 Category: ManagedRuntimeError Message: System.NullReferenceException: [Arg_NullReferenceException]Arguments: Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.60129.0&File=mscorlib.dll&Key=Arg_NullReferenceException at Infragistics.Controls.Grids.PivotGridLayout.InitializeLayout() at Infragistics.Controls.Grids.XamPivotGrid.ArrangeLayout() at Infragistics.Controls.Grids.XamPivotGrid.OnApplyTemplate() at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget) Line: 63Char: 13
Message: Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.NullReferenceException: [Arg_NullReferenceException]
Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.60129.0&File=mscorlib.dll&Key=Arg_NullReferenceException
at Infragistics.Controls.Grids.PivotGridLayout.InitializeLayout()
at Infragistics.Controls.Grids.XamPivotGrid.ArrangeLayout()
at Infragistics.Controls.Grids.XamPivotGrid.OnApplyTemplate()
at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)
Line: 63
Char: 13
I downloded prism4 and try the pivot grid with one of samples from prism instalation.
The sample is located in \prism4\Quickstarts\View-Switching Navigation\Silverlight\View-Switching Navigation\
In this sample I place PivotGrid in ComposeEmailView.xaml file. it similates the case you point.
In the first screen a have to click "New" button to navigate to screen with pivot grid. The navigation is made with code that you point before:
.MainContentRegion, ComposeEmailViewUri);
And it works without exceptions. Is this case the case you discribe or i need something more.
Btw which version do you use. Do you try with latest Service Release? Could you attach simple project that i can test for this issue?
Regards
Todor
Hi Todor,
This issue can be easily recreated without the need for Prism.
In a view simply have a named ContentControl with a xamPivotDataSelector pointing at a data source. Also place a button in the view. In code behind for the button simply create a xamPivotGrid, bind its data source to the same view model as the data selector and set the content of the ContentControl to the grid. The exact same error is recieved as I have been experiencing:
private void Button_Click(object sender, System.Windows.RoutedEventArgs e) { var grid = new XamPivotGrid(); grid.SetBinding(XamPivotGrid.DataSourceProperty, new Binding() { Source = this.DataContext, Path = new System.Windows.PropertyPath("DataSource") }); gridContainer.Content = grid; }
Please could you investigate and let me know if a) there is a workaround or b) a fix can be made available if no workaround exists.
Kind Regards,
FYI - I have managed to suppress the exceptions thrown by calling the below method prior to setting the binding. The only issue is that the actual cell data is not displayed until the data source is next updated. The column and row headers display fine:
grid.UpdateLayout();
As a workaround you can use next code. This code will not produce an exception and will work as expect.
private void Button_Click(object sender, RoutedEventArgs e) { var grid = new XamPivotGrid(); grid.SetBinding(XamPivotGrid.DataSourceProperty, new Binding() { Source = this.DataContext, Path = new System.Windows.PropertyPath("DataSource") }); // Add next line grid.DataSource.RefreshGrid(); gridContainer.Content = grid; }
Thanx Todor. I managed to get it working late yesterday evening by calling RefreshGrid() so all is now good.