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.

Powered by Drupal, an open source content management systemCreative Commons LicenseSyndicate content