WPF DataGrid Data Binding

Source: Internet
Author: User
Tags wpf datagrid

The DataGrid control is a control that displays data, obtains information from a collection of objects, and displays information in a grid with rows and cells. Each row corresponds to a single object, and each column corresponds to an attribute in the object.

The DataGrid control adds many skills that are required to process data in WPF. Its column-based model provides significant formatting flexibility, and its selection model allows you to select a single row, multiple rows, or a combination of cells whose editing support is very powerful, and you can use the DataGrid control as a unified data editor for simple data and complex data.

Described above are introduced, the following I will use the function of the DataGrid in my project to share with you, but also hope that you can point out the shortcomings.

<datagrid x:name="grid1" autogeneratecolumns="True"> </DataGrid>
    1. DataGrid Data Binding
      1. Set AutoGenerateColumns to "True" to automatically generate columns and populate datagrid:grid1 by setting the Itemsource property. ItemsSource = prolist; effects such as:
      2. Using automatically generated columns is not a good way to control the display of the column, set the AutoGenerateColumns to "False", so we can define the display of the column, we usually use the most. Here I bind the columns of the five DataGrid-supported types separately:
        <DataGrid.Columns> <datagridcheckboxcolumn header="Select"Width=" -"></DataGridCheckBoxColumn> <datagridtextcolumn header="Product Name"Width=" -"binding="{Binding Path=proname}"> </DataGridTextColumn> <datagridcomboboxcolumn header="Product Category"Width=" the"selecteditembinding="{Binding Path=procategory}"Itemssource="{Binding source={staticresource keycategory}}"></DataGridComboBoxColumn> <!--Combox binding to get the resource keycategory defined above. Get the category's data from the background--&L T;datagridhyperlinkcolumn header="Product Link"Width=" -"binding="{Binding Path=prolink}"></DataGridHyperlinkColumn> <datagridtemplatecolumn header="Product Image"Width=" -"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <image source="{Binding Path=proimage}"Width=" -"height=" -"></Image> </DataTemplate> </datagridtemplatecolumn.celltemplat E> </DataGridTemplateColumn> </DataGrid.Columns>
        View Code

        Background settings:

         Public enum ProductCategory    {        travel,deception,tools,general    }
        View Code

        The interface is as follows:

WPF DataGrid Data Binding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.