views:

196

answers:

1

Using a DataView one can specify the binding for controls in XAML for example as follows:

<Image Source="{Binding Thumbnail}" />

I have a control that displays a number of images. I can get this to work with a DataView as the data source for the control, but I want to use a List collection of DataRow objects, which is not not working for me. My data source is:

List<DataRow>

I could of course convert the List<DataRow> collection to a DataTable and from this obtain a DataView, but I would really like to go straight to the List<DataRow> collection. How would I go about doing the binding in XAML to bind to the "Thumbnail" column of the DataRow's in a List collection.

Edit:

I only need to be able to read the data one way. I do not need to write back changes to the list collection (plus further clarification above).

Elan

A: 

You can do this by using something like as follows:

    <ItemsControl x:Name="RowsContainer" ItemsSource="{Binding Rows}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Background="Azure"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding [0]}" />
                </StackPanel>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

Where "{Binding Rows}" refers to the DataRowsCollection collection and {Binding [0]} refers to the first column in the row.

Mik Kardash