binding data to an arraylist in xaml

Oct 25, 2008 at 8:46 PM
I am creating a datagrid which work very nicely 
But I have a ComboBoxColumm
which look like this



<dg:DataGridComboBoxColumn DataFieldBinding="{Binding Path=Opcode}" Header="Op Code" >

But the complete data is in a resource so I would like to use it directly.

something like:
<col:ArrayList ItemSource="{Binding Source={StaticResource OpCodes}, XPath=/OpList/Number/OpName}" />

why is <dg:DataGridComboBoxColumn ItemsSource ="{Binding Source={StaticResource OpCodes}, XPath=/OpList/Number/OpName}" />

not working either.



Oct 30, 2008 at 1:55 PM
Could you be a little more specfic on what is not working.  Also, have you tried the v1 DataGrid bits?  Maybe that can help you out as well.
Oct 30, 2008 at 5:50 PM
It all work great but I cannot perform what I believe to be a perfectly legitimate operation.

My problem and sorry if it is not clear.

I would like to bind a StaticResource in a DataGridComboBoxColumn .

A combobox expect an arraylist as an itemsource. I think, but have no proof, that it is the only type of input that a combobox will accept.

So my problem has become how to bind a static resource to an arraylist.
If someone know how to bind a static resource to a combobox this would also solve this problem.

I think I am working with the most recent version of the datagrid.

Hope this clarify my question.

Oct 31, 2008 at 2:24 PM
A ComboBox.ItemsSource is not bound by ArrayList only.  It can accept any IEnumerable object.  A IEnumberable StaticResource should work just fine.  Here is a small example:



<ObjectDataProvider x:Key="customerDataProvider" ObjectType="{x:Type local:Customers}" MethodName="GetCustomers" />




<dg:DataGridComboBoxColumn SelectedValueBinding="{Binding CustomerID}" 
            Header="CustomerID (ContactName alias using SelectedValueBinding)"
            ItemsSource="{Binding Source={StaticResource customerDataProvider}}">

What excactly is going wrong when you declare a StaticResource?


Nov 2, 2008 at 9:55 AM
 I hate to post a long example but here it is.
The dg:DataGridComboBoxColumn.ItemsSource is intialize as an arraylist. 
The ListBox ItemsSource uses a static resource.
It is not possible to use the same static resource to initialize the dg:DataGridComboBoxColumn.ItemsSource
this is my problem. This sould be possible. I want to use one column of my data to init a combobox which is a column.

Thanks you for trying

<Window x:Class="WpfApplication3.Window1"
    Title="Window1" Height="300" Width="300">
        <XmlDataProvider x:Key="OpCodes">
                <OpList xmlns="">
                    <Number OpNumber="0"><OpName>h</OpName><OpDescription>Halt</OpDescription></Number>
                    <Number OpNumber="1"><OpName>a</OpName><OpDescription>Add</OpDescription></Number>
                    <Number OpNumber="-1"><OpName>s</OpName><OpDescription>Subtract</OpDescription></Number>
                <RowDefinition Height="128*" />
                <RowDefinition Height="134*" />
            <dg:DataGridTextColumn DataFieldBinding="{Binding Path=Label}" Header="Label " CanUserSort="False" />
            <dg:DataGridComboBoxColumn DataFieldBinding="{Binding Path=Opcode}" Header="Op Code" >
        <ListBox Grid.Row="1">
            <ListBox ItemsSource="{Binding Source={StaticResource OpCodes}, XPath=/OpList/Number/OpName}" />