Creating a Custom Control

The beauty of the user control model lies in having the class definition spread across a XAML file and a C# code-behind file. This provides a familiar development experience, just like creating a Page. We can leverage this model for a more sophisticated control, even one that doesn’t derive from UserControl. In this section, we’re going to create such a control called PlayingCard, which represents a playing card to be used in card games.

The tendency for designing a simple user control is to start with the user interface and then later add behavior, as we did with NumericUpDown. For a control that includes better support for things like restyling, it usually makes more sense to start with the behavior. That’s because ...

Get XAML 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.