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.