locked
bind xaml grid to collection object. RRS feed

  • Question

  • i have a collection built in the middle tier. how do i bind my grid to this object.

     

    all examples have collections build in code behind and use <local: collectionname.

     

    i think i need to use datacontext but i get the error the object was not found.

     

    any help would be great.

     

     

    Thursday, June 28, 2007 10:45 AM

Answers

  • Hello, first make sure you’ve initialized the collection correctly. Then you can set the DataContext to the Collection, such as this.DataContext = myCollection. Now you can bind with something like:

            <ListView ItemsSource="{Binding}">

                <ListView.View>

                    <GridView>

                        <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>

                    </GridView>

                </ListView.View>

            </ListView>

     

    Or you can use a CollectionViewSource so you can perform operations such as sorting and filtering. Please have a look at Data Binding Overview, especial how to bind to a collection.

    Monday, July 2, 2007 8:10 AM