#67 – XAML Attributes Map to Property Values
September 17, 2010 2 Comments
In the same way that XAML elements map to instances of .NET types, XAML attributes map to properties of those types.
In the example below, we create a new instance of a Button and then specify values for the following properties: Content, Height, Width, Name and Background.
<Button Content="Press Me" Height="23" Name="button2" Width="75" Background="#FFE3E316" />
Note that we set each property by specifying a string, despite the Button object’s properties having different types:
- Content – object
- Height – double
- Width – double
- Name – string
- Background – System.Windows.Media.Brush
When the XAML file is processed, the string values will be converted to the appropriate types.
Pingback: #70 – Specifying Event Handlers in XAML « 2,000 Things You Should Know About WPF
Pingback: #78 – Setting the Value of a Content Property By Setting Child Element « 2,000 Things You Should Know About WPF