Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x:Key & TargetType in styles

Is there any difference (or advantage) for use this statement:

Style x:Key="{x:Type DataGridCell}" TargetType="{x:Type DataGridCell}"

with omitting the x:Key attribute?

I think WPF assigns the key to the same x:Type under the hood.

like image 767
Manuel Avatar asked Nov 13 '11 01:11

Manuel


People also ask

What are the X-keys?

X-keys provide rugged, reliable computer input hardware - programmable keypads, keyboards, and controls. Serving everyone from individual users to multinational corporations and providing mission-critical controls with unparalleled support.

How do you use X-keys?

Plug the male end of the X-keys cord into the keyboard port of your computer. Slide programming switch up (red dot showing) Press a key to program on the X-keys Type Press the same key to end programming on that key Slide programming switch down (or select another key to program).

What is a second keyboard layout?

The secondary keyboard is mainly your numeric and punctuation keyboard. There are other common symbols available on this keyboard as well. To get to the secondary keyboard touch one of the "123" found on either side of the space bar.

Are all keyboards programmable?

Many keyboards have some degree of programmability, allowing users to set up several hot keys which can be used to access frequently used applications, but other keyboards have been specifically designed for programmable functions, with a range of potential configurations.


1 Answers

The MSDN documentation for Style.TargetType confirms your suspicions:

Setting the TargetType property to the TextBlock type without setting an x:Key implicitly sets the x:Key to {x:Type TextBlock}. This also means that if you give the above Style an x:Key value of anything other than {x:Type TextBlock}, the Style would not be applied to all TextBlock elements automatically. Instead, you need to apply the style to the TextBlock elements explicitly.

If the resource dictionary key of a style is a type, that style is used as the default style for all instances of that type that don't explicitly specify a style. Since the target type is usually supplied, the syntax of omitting the key is simply a shortcut for defining a default style.

like image 51
Rick Sladkey Avatar answered Oct 08 '22 21:10

Rick Sladkey