views:

134

answers:

0

I've encountered a strange problem while upgrading an application from Silverlight 3.0 to Silverlight 4.0. The XAML below used to work fine but after upgrading no longer works.

<xxx:FeatureGrid.Columns>
    <agDataGrid:AgDataGridColumnCollection>
        <xxx:FeatureGridTextColumn FieldName="HOUSE_NUM" HeaderContent="Number" />
        <xxx:FeatureGridTextColumn FieldName="ROAD_NAME" HeaderContent="Street" />
        <xxx:FeatureGridTextColumn FieldName="LOCATION" HeaderContent="City" />
        <xxx:FeatureGridTextColumn FieldName="REGISTRATIONTYPE" HeaderContent="Registration Type" />
        <xxx:FeatureGridTextColumn FieldName="REGISTRATIONVALUE" HeaderContent="Registration Value" />
    </agDataGrid:AgDataGridColumnCollection>
</xxx:FeatureGrid.Columns>
<xxx:FeatureGrid.Filters>
    <xxx:FeatureFilterCollection>
        <StaticResource ResourceKey="BlenheimParcelsRoadNameFilter" />
    </xxx:FeatureFilterCollection>
</xxx:FeatureGrid.Filters>

FeatureGrid.Columns and FeatureGrid.Filters are attached properties being defined on another element. Columns is of type AgDataGridColumnCollection which is from the DevExpress AgDataGrid and ultimately derives from ObservableCollection and Filters is a custom collection type that also derives from ObservableCollection.

Essentially, both Columns and Filters are attach properties that are collections. In Silverlight 3, Columns is initialized with an instance of AgDataGridColumnCollection which is populated with the FeatureGridTextColumns. Filters is similarly initialized.

In Silverlight 4, Filters still works as expected, but Columns now behaves quite differently. After setting breakpoints in code, I was able to work out that the Columns attached property getter was being called and returning null (because it hasn't been initialized) which then causes an exception to be thrown. However, the Filters property in SL3 & SL4 and Columns previously in SL3 have the attached property setter called with the value being the instantiated collection, populated with elements declared in the XAML.

The following exception is thrown:

Message: Unhandled Error in Silverlight Application 
Code: 4004    
Category: ManagedRuntimeError       
Message: System.Windows.Markup.XamlParseException: Collection property '__implicit_items' is null. [Line: 99 Position: 68]
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at xxx.Silverlight.Sample.MainPage.InitializeComponent()
   at xxx.Silverlight.Sample.MainPage..ctor()
   at xxx.Silverlight.Sample.App.Application_Startup(Object sender, StartupEventArgs e)
   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)    

I don't understand why in SL4 the Columns attached property is being treated differently than before and why the Filters attach property is treated the same in both SL3 and 4.

Can anyone explain the change in behavior between 3 & 4, and why only one of the attached properties is effected?