In creating a custom  XAML UserControl, a need arose to make use of generics with the UserControl class. The control is based upon the XAML AutoSuggestionBox control and  implements a quick lookup of a user from an app supplied list of users. The control uses Linq queries to efficiently search through a list of  type User using Name and Id properties. The search can be on partial name completion or on user’s initials. So as to allow the use of a broad range of  list types for the supplied user list, as provided in the UserControl’s hosting app, the app’s user type needs to implement a specific set of properties that are used in queries and so it must implement a specific interface (called IUser). It would have been nice to have parameterised the UserControl class using generics to specify the list of users’ data type as the apps user type and constrain it to implement the interface using generics. But the custom UserControl class does not permit generics.   Consider the following: ...

Read the rest of entry »