x:Type DataGridColumnHeader vs DataGridColumnHeader

i am a very newbee in wpf. my question is

what is the difference between

TargetType="{x:Type DataGridColumnHeader}"
and
TargetType="DataGridColumnHeader"

please help
Amitava_MukherjeeAsked:
Who is Participating?
 
Matthew KellyConnect With a Mentor Commented:
It basically lets you limit the target to a specific control type. Unless you are extending the DataGrid control to make your own custom ones, it probably doesn't matter for DataGridColumnHeader since that control only exists in DataGrid. It comes into play when the type is used in multiple controls; such as TextBlock, referenced below:


http://msdn.microsoft.com/en-us/library/ms745683.aspx

Relationship of the TargetType Property and the x:Key Attribute

As shown in the first example, setting the TargetType property to TextBlock without assigning the style an x:Key causes the style to be applied to all TextBlock elements. In this case, the x:Key is implicitly set to {x:Type TextBlock}. This means that if you explicitly set the x:Key value to anything other than {x:Type TextBlock}, the Style is not applied to all TextBlock elements automatically. Instead, you must apply the style (by using the x:Key value) to the TextBlock elements explicitly. If your style is in the resources section and you do not set the TargetType property on your style, then you must provide an x:Key.

In addition to providing a default value for the x:Key, the TargetType property specifies the type to which setter properties apply. If you do not specify a TargetType, you must qualify the properties in your Setter objects with a class name by using the syntax Property="ClassName.Property". For example, instead of setting Property="FontSize", you must set Property to "TextBlock.FontSize" or "Control.FontSize".

Also note that many WPF controls consist of a combination of other WPF controls. If you create a style that applies to all controls of a type, you might get unexpected results. For example, if you create a style that targets the TextBlock type in a Window, the style is applied to all TextBlock controls in the window, even if the TextBlock is part of another control, such as a ListBox.
0
 
Amitava_MukherjeeAuthor Commented:
thanx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.