Type Converters

Let’s look at the C# code equivalent to the preceding Button declaration that sets both Content and Background properties:

Windows.UI.Xaml.Controls.Button b = new Windows.UI.Xaml.Controls.Button(); b.Content = "Stop"; b.Background = new Windows.UI.Xaml.Media.SolidColorBrush (Windows.UI.Color .Red);

Wait a minute. How can "Red" in the previous XAML file be equivalent to the SolidColorBrush instance used in the C# code? Indeed, this example exposes a subtlety with using strings to set properties in XAML that are a different data type than System.String or System.Object. In such cases, the XAML parser must look for a type converter that knows how to convert the string representation to the desired ...

Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.