Style multi-file solution (XAML) http://chr1syu.spaces.live.com/Blog/cns in WPF! 6a09cb72c98e0121! 195 simple style notes in entrywpf (XAML)
- Create Resources
- In Solution Explorer, you can add an item called resource dictionary to a project. This item adds a XAML file with the label <resourcedictionary> as root to your project.
- Various resources can be defined by using style, solidcolorbrush, and so on in the above files.
For example: <solidcolorbrush X: Key = "normalbrush" color = "# fcf3d6"/>
In this way, a paint resource whose key is normalbrush is defined.
- If you want to define a style, it is a little effort-consuming. Style can be attached with a key or not. However, if there is no key, targettype is generally used to indicate the default style for a specific type. Example:
<Style X: Key = "buttonfocusvisual">
<Setter property = "control. template">
<Setter. value>
<Controltemplate>
<Border>
<Rectangle margin = "2" strokethickness = "1"
Stroke = "orange" strokedasharray = "1 2"/>
</Border>
</Controltemplate>
</Setter. value>
</Setter>
</Style>
- For style, you can also define its trigger to allow the control to change its appearance based on some attribute changes. The example is as follows:
<Style targettype = "button">
<Setter property = "snapstodevicepixels" value = "true"/>
<Setter property = "overridesdefaultstyle" value = "true"/>
<Setter property = "focusvisualstyle"
Value = "{staticresource buttonfocusvisual}"/>
<Setter property = "template">
<Setter. value>
<Controltemplate targettype = "button">
<Border
X: Name = "border" cornerradius = "2"
Borderthickness = "1"
Background = "{staticresource normalbrush }"
Borderbrush = "{staticresource normalborderbrush}">
<Contentpresenter
Margin = "2"
Horizontalalignment = "center"
Verticalalignment = "center"
Recognizesaccesskey = "true"/>
</Border>
<Controltemplate. triggers>
<Trigger property = "iskeyboardfocused" value = "true">
<Setter targetname = "border"
Property = "borderbrush"
Value = "{staticresource defaultedborderbrush}"/>
</Trigger>............
</Controltemplate. triggers>
</Controltemplate>
</Setter. value>
</Setter>
</Style>
- Application Resources
- First, add the above resources to the app. Open the app. XAML file and add the previously defined XAML file to the tag <application. Resources>. For example:
<Application. Resources>
<Resourcedictionary>
<Resourcedictionary. mergeddictionaries>
<Resourcedictionary source = "rescommon. XAML"/>
.........
</Resourcedictionary. mergeddictionaries>
</Resourcedictionary>
</Application. Resources>
- Then it can be called in any XAML or C # Code. Those with no name but targettype will be set to the default style of the corresponding type. The application method is as follows:
Style = "{staticresource resourcekeyname }"