Hello,
I put an empty XamWebGrid on page like this (copied this from your demo page):
<igGrid:XamWebGrid x:Name="dataGrid" AutoGenerateColumns="false">
<igGrid:XamWebGrid.Columns>
<igGrid:TextColumn Key="ID">
<igGrid:TextColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="Customer ID" />
</DataTemplate>
</igGrid:TextColumn.HeaderTemplate>
</igGrid:TextColumn>
<igGrid:TextColumn Key="Company">
<TextBlock Text="Company" />
<igGrid:TextColumn Key="Name">
<TextBlock Text="Name" />
</igGrid:XamWebGrid.Columns>
</igGrid:XamWebGrid>
and do some actions in code:
ObservableCollection<Person> _persons = new ObservableCollection<Person>();
public MainPage()
{
_persons.Add(new Person(1, "Adam Smith", "Coca-cola"));
_persons.Add(new Person(2, "John Michaels", "Pepsi-cola"));
_persons.Add(new Person(3, "Mary James", "Boo-cola"));
InitializeComponent();
this.Loaded += new RoutedEventHandler(PersonsLoaded);
}
private void PersonsLoaded(object sender, RoutedEventArgs e)
dataGrid.ItemsSource = _persons;
When I run application I get a NullReferenceException in PersonsLoaded method. When I inspect ItemsSource property, I see that it has been set to a proper value. But anyway I get that error, no matter if I set XamWebGrid.Columns manually or set AutoGenerateColumns to TRUE. Can you please tell me what's wrong?
Thank you.
I tried out the situation you described with the following mock up and did not see your reported results. I tried it out against both the release version of the DLL and a current dev build of the control. Could you post the stack trace from the debugger so we can see where the NRE is raised? Which version of the DLL are you using? Are you turning on any other feature besides the ones listed?
public class Person
public int ID { get; set; }
public string Company { get; set; }
public string Name { get; set; }
public Person(int id, string name, string comp)
this.ID = id;
this.Name = name;
this.Company = comp;
<UserControl x:Class="SilverlightApplication9.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:igGrid="clr-namespace:Infragistics.Silverlight.Controls;assembly=Infragistics.Silverlight.XamWebGrid.v9.1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot">
</Grid>
</UserControl>
Looks like this happened because class Person has been not declared as public. I discovered this after copy/paste your code and got everything running ok.
I thought that was not necessary if it had been declared in the same codebehind file.