#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.

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #67 – XAML Attributes Map to Property Values

  1. Pingback: #70 – Specifying Event Handlers in XAML « 2,000 Things You Should Know About WPF

  2. Pingback: #78 – Setting the Value of a Content Property By Setting Child Element « 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: