Hi
Why do I do this? Because looks like it only needed if I use Add New Row functionality, but I don't.
http://help.infragistics.com/Help/Doc/WPF/2012.1/CLR4.0/html/xamGrid_RequireEmptyConstructor_Exception.html
In this scenario it isn't that the view model object can't return null, it is that its properties aren't expected to throw a NullReferenceException. You could also check if the someObject is null and return a null value or equivalent value from your property if the object isn't set.
I'll look into it. The only reason I ask is that we are occasionally seeing a null ref exception when filtering on one of our xamGrids. The view model is implemented in a way similar to how I've shown above. The stack trace points us to a get_Property method returning null and the only way that's possible is if the object was constructed using the parameterless constructor. Just wanted to verify that it's even possible and figure out if we need to change our implementations if that's a possibility. I wasn't able to find any sort of documentation that said that the view model object should always have default non-Null values on it's properties.
Are you able to just create a new instance of someObject in the parameterless constructor? That is probably the best way to avoid the issue. Note I am not sure if we actually access the property for the filter row.
Alternatively, is there a reason that you don't just expose a property for someObject instead of its child properties so that they can be accessed that way?
So does this mean that if you intend on using filtering in your xamGrid that the view model for the object must always have default values when called with the parameter less constructor?
For example, you couldn't do something like this, as doing so could result in null reference exception if the Infragistics code were to create an instance of the class calling the parameter less constructor and then tried to access it's property:
// Parameterless constructor to satisfy this requirement.
class SomeClass()
{
}
// Actual constructor that gets called throughout the code.
class SomeClass(object someObject)
_someObject = someObject;
// Property1, which will throw a null reference exception if accessed when the object is constructed from the parameter less constructor
bool Property1
get
return _someObject.BoolProperty;
OK got it, Thanks
The last question, why this object needed when I use the filter menu?