[Silverlight entry series] bind the column header of the DataGrid

Source: Internet
Author: User

All frameworkelementdependencyobject columns in the Silverlight DataGrid have a header attribute. In general, we set the header to "symbol ":

If we want to bind the header to a resource, for example, if your Silverlight application is in multiple languages, we must bind the header, as shown in the following code:

You will find an error in Header = "{binding meetingname, source = {staticresource locstrings.

Why cannot I bind it?

Only frameworkelement of Silverlight supports data binding context. It supports data binding and resource attributes through the dependencyproperty class, and any dependencyobject can have dependencyproperty, however, frameworkelement is used to set values for data context that may be inherited. In other words, dependencyobject cannot bind data. To bind data

Frameworkelement is derived.

The header property is not dependencyproperty because
Datagridcolumn is a dependencyobject, and is bound
Dependencyobjects does not work. In addition, column itself is not a visual element and is not on the visual tree. Therefore, the datagridcolumn cannot be a frameworkelement and cannot be bound. Non-frameworkelement members must bind/datatrigger/behavior to avoid detours.

 

How many frameworkelement members are in the uielement?

How to bind the column header of the DataGrid?

You can use controltemplate to solve the problem. Each column is defined as follows:

However, after controltemplate is set in this way, the visual style of the column header of the DataGrid is gone, which is ugly. Just try the datatemplate method:

Of course, another way to set the header is to use *. XAML. CSCodeDynamic settings.

The next section describes the differences between controltemplate and datatemplate.

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.