开发者

How does one bind to a List<DataRow> collection in WPF XAML?

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 colle开发者_JAVA技巧ction 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜