Members of Style
The styling of WPF controls is made up with the help of a class called Style. The style object exposes few properties which help you to define various behavior.
Lets look into the properties:
=> Resources : It holds the reference for the ResourceDictionary where the Style is defined.
=> Setters : It is a collection which holds all the DependencyProperty configuration for the whole control.
=> TargetType : TargetType defines the type of the control for which the Style can be applied. So based on the TargetType the Style setters are defined to. So
if you define a style for TextBox you cannot use Content as property Setter.
=> BasedOn : This is used to allow Style inheritance. You can use an existing style key to inherit all the properties to a new Style.
=> Triggers : A collection of Setters which would be applied based on certain conditions.
Using those properties you can define your own styles.
What about Explicit and Implicit Styles ?
WPF controls can have two type of styles associated with it. A control can have a style defined in the application and applied to its Style property. If your control is using a Style to define its look and feel or basically your control has set an object of Style into its Style property, then it is using an Explicit Style.
On the other hand, if your control takes the style from external environment (Theme) and the Style property is set to Null, then your control is using Implicit Style.
Basically any WPF control automatically defines a DefaultStyle for it, so that you can set only the portion of the control which you need to change.
Say for instance, you have a Button. If you want to have its Text to be colored Red, you just need to change the Foreground of the Button. You need not to define the whole style. If there is no Default Style defined for Buttons, you need to define all the properties individually to make it appear. Thus the default color of the Text is Black if not defined otherwise.
The styling of WPF controls is made up with the help of a class called Style. The style object exposes few properties which help you to define various behavior.
Lets look into the properties:
=> Resources : It holds the reference for the ResourceDictionary where the Style is defined.
=> Setters : It is a collection which holds all the DependencyProperty configuration for the whole control.
=> TargetType : TargetType defines the type of the control for which the Style can be applied. So based on the TargetType the Style setters are defined to. So
if you define a style for TextBox you cannot use Content as property Setter.
=> BasedOn : This is used to allow Style inheritance. You can use an existing style key to inherit all the properties to a new Style.
=> Triggers : A collection of Setters which would be applied based on certain conditions.
Using those properties you can define your own styles.
What about Explicit and Implicit Styles ?
WPF controls can have two type of styles associated with it. A control can have a style defined in the application and applied to its Style property. If your control is using a Style to define its look and feel or basically your control has set an object of Style into its Style property, then it is using an Explicit Style.
On the other hand, if your control takes the style from external environment (Theme) and the Style property is set to Null, then your control is using Implicit Style.
Basically any WPF control automatically defines a DefaultStyle for it, so that you can set only the portion of the control which you need to change.
Say for instance, you have a Button. If you want to have its Text to be colored Red, you just need to change the Foreground of the Button. You need not to define the whole style. If there is no Default Style defined for Buttons, you need to define all the properties individually to make it appear. Thus the default color of the Text is Black if not defined otherwise.

No comments:
Post a Comment