#67 – XAML Attributes Map to Property Values

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.

Advertisements