The style mechanism of WPF has been used to locate styles in the resource system. As you can see in chapter 5th, the style is defined in the element's resource fragment, and the style is referenced by its name, as shown in example 6-18:
Example 6-18
<Window x:Class="ResourcePlay.Window1" Text="ResourcePlay"
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005">
<Window.Resources>
<Style x:Key="myStyle">
<Setter Property="Button.FontSize" Value="36" />
</Style>
</Window.Resources>
<Grid>
<Button Style="{StaticResource myStyle}">Hello</Button>
</Grid>
</Window>
However, how to define a style, apply it automatically to an element without having to display the resource you specify to reference--this is achievable and useful--when you need to apply a style to all elements of a unique type, rather than adding a resource reference to each element. Example 6-19 makes some modifications to example 6-18, demonstrating the functionality of implicit declarations.
Example 6-19
<Window x:Class="ResourcePlay.Window1" Text="ResourcePlay"
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005">
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Button.FontSize" Value="36" />
</Style>
</Window.Resources>
<Grid>
<Button>Hello</Button>
</Grid>
</Window>
Note that the button label no longer has its particular style attribute. However, this style is still applied to the button by targettype instead of defining a key, which uses x:type to set the TargetType, and then notifies the XAML to provide a System.Type object for the TargetType class.
If FrameworkElement does not display the specified style, it always looks for a style resource that uses its own type as its target type.
If you set up some non-styled resources, such as SolidColorBrush, and you set the type of x:key as a UI element, an error occurs if you try to use the type of the element. This is because you created a style with TargetType but did not specify x:key,x:key implicitly set to the same as TargetType. This key is used to locate style. Therefore, in general, you should avoid setting the x:key to the type object.
Because the element will search for its style in the resource, you can take advantage of the system-level resources. You can define a style resource in a local scope, if you only want to affect a small number of elements, or in a broad scope, such as Window.resource, or in the scope of the application. And the style may be deferred to the system level. The connection between this style and resources is the key to using the skin and the body