views:

282

answers:

1

Hello,

I have authored some custom classes that I would like to create using XAML:

<Grid Width="300" Height="300">
    <l:DashboardTable>
        <l:DashboardTable.DashboardTableQuery>
            <dq:DashboardTableQuery 
                ConnectionString="Data Source=bunkerhill;Initial Catalog=emgov_data;User Id=emgovadmin;Password=p@$$word;"
                Query="select datename(month, cr_tb_DateDue) AS Month, sum(cr_tb_AmountTransaction) AS Total from cr_tb_transactionbill where Year(cr_tb_DateDue) = 2005 and Month(cr_tb_DateDue) IN (1,2,3,4) group by datename(month, cr_tb_DateDue)"
                >
                <dq:DashboardTableQuery.DataColumns>
                    <dq:DataColumn ColumnName="Month" ColumnOrder="0" Label="Month" />
                    <dq:DataColumn ColumnName="Total" ColumnOrder="1" Label="Total" />
                </dq:DashboardTableQuery.DataColumns>
            </dq:DashboardTableQuery>
        </l:DashboardTable.DashboardTableQuery>
    </l:DashboardTable>
</Grid>

The problem is that I get a XamlParseException when I try to run this XAML. I have determined it is when it gets to the dq:DataColumn element. It seems like this is only happening when I have a property that then has a collection and then several items in the collection that I am getting this issue.

Has any encountered anything similar? I am try to achieve this all in XAML declaratively.

+1  A: 

There are a couple of things I can think of for the post Xaml to work.

  • The DashboardTableQuery must create an instance of the collection that is then exposed as the DataColumns property.
  • The collection type exposed by DataColumns must implement IList.
AnthonyWJones
Thanks for your response. The DataColumns property on the DashbboardTableQuery object has a field that is a new List<DataColumn>(). I would think this would satisfy both of the requirements for the Xaml to work. One other caveat is that the object model is coming from a WCF Service via a Web Reference.
mattduffield
@mattduffield: If it really is a "field" change it to a Property. For your xaml to work it really should be a read-only property or at least a Property that has the collection initialised ready to have items added.
AnthonyWJones
It is a property with the field that is being wrapped defaulted to a new List<DataColumn>(). Sorry for the confusion. I agree that this could be a read-only property.
mattduffield
@mattduffield: Then so far I can't see anything wrong, can you provide more details regarding the exception you are seeing?
AnthonyWJones
It turns out that it was an issue with creating the WCF Service Reference. It will by default serialize List as Arrays. You can change this behavior but that still doesn't help us on the Xaml side of things since it wants a ready to use initialized collection.
mattduffield