Syndicate content

Follow me on:

A Generic WPF-Control

There are several ways to reference generic types from XAML for bindings. Unfortunately there is no way to define a generic type using XAML.

I needed to port a fancy dialog for selecting from a list of items from Winforms to WPF. The original dialog had a generic type parameter for the type of the items. Something along the lines of public class SelectionDialog<TItem> : Form. This is not possible if you want to design the layout of a control with XAML, because the XAML type definition does not allow to define type parameters.

All I did to circumvent this limitation was to create a non generic dialog class which I designed with the Visual Studio XAML designer. Then I created a second class with a type parameter for the items. This class is derived from the XAML designed class and voilà I got a XAML dialog with a type parameter.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.