Setter


SetterHierarchy: Object SetterBase

     <Setter         Property="PropertyBeingSet"         TargetName="{x:Type NameOfTheTarget}"         Value="ValueBeingSet"|{"DynamicResource ResourceName"} |               {"StaticResource ResourceName"} /> 

<Setter .../> defines a property for a specific element. It is used to apply a Style or trigger to multiple elements of a specific type, e.g., all Buttons, all TextBlocks, etc. The element declares the attribute (property) to be set, the target element type, and the value to which to set the attribute. For example, Setter could be used to set the Background of all Button elements to a specific Color (Example 10-2) or to set the width of all Button elements to the same size (Example 10-3).

Attributes


Property (required)

The name of the attribute being set. Examples include Font, Height, and Background.


TargetName (required)

The type of the child node the Setter will target, if any (Example 10-4).


Value (required)

The value for the attribute. The value may be a literal representation ("Blue", "2") or a reference to a DynamicResource or a StaticResource.

Example 10-4. Example of setting the TargetName of the Setter to a child node

 TargetName="{x:Type ComboBoxItem}" TargetName="{x:Type Button}" 




XAML in a Nutshell
XAML in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596526733
EAN: 2147483647
Year: 2007
Pages: 217

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net