Implict styling controls used as a base class
Scenario:
When we set an implicit styling for a controlthat is used as a base class control, the style for the sub controls (Customcontrol derived from a base control) remains the default style as it is not setfor the sub control. We need to specify the target type as the name of thecustomcontrol, which repeats the line of code whenever a new control is createdthat has the same base control.
Say, we have 3 custom controls derived from a Button control.
1. CustomAdd : Button
2. CustomDelete : Button
3. CustomModify : Button
Even if we specify an implicit style to theButton control, controls like CustomAdd, CustomDelete and CustomModify, whichare derived from Button uses the default style of the button control, and notthe implicit style.
Solution:
We need to specify style saperately for eachcustom control for which the target type would be the custom control.
e.g.
<Style TargetType="customControl:CustomAdd">
....
....
....
</Style>
To overcome this, there is an alternative.
Use an explicit Style for the Base control; i.e.the button control in the above example and use that style as the BasedOn forthe implicity styling of the custom control and thus, we can reduce theredundant line of code used to set the implicit styling.
e.g.
<Stylex:Key="GeneralAutoCompleteStyle"TargetType="inputControls:AutoCompleteBox">
<SetterProperty="IsTabStop" Value="False" />
<SetterProperty="Padding" Value="2" />
<SetterProperty="BorderThickness" Value="0.5" />
<SetterProperty="BorderBrush" Value="#848484"/>
<SetterProperty="Background" Value="#FFFFFF" />
<SetterProperty="Foreground" Value="#000000" />
<Setter Property="MinWidth"Value="45" />
</Style>
<Style TargetType="customControls:AutoComplete1"BasedOn="{StaticResource GeneralAutoCompleteStyle}"/>
<Style TargetType="customControls:AutoComplete2"BasedOn="{StaticResource GeneralAutoCompleteStyle}"/>
<Style TargetType="customControls:AutoComplete3"BasedOn="{StaticResource GeneralAutoCompleteStyle}"/>
Comments
Post a Comment