I'm trying to create a Window-derived class in XAML which can take a generic argument, but I can't seem to define the generic argument in the XAML so that it generates the partial class matching my code-behind file.
What I'm trying to accomplish is a replacement for all the MessageBox calls for asking the user questions, where I can give meaningful button captions ('Save and quit'/'Quit without saving'/'Don't quit' type thing). I'd like to be able to pass the window a generic argument constrained to System.Enum defining the return value for the selected option:
<Window x:Class="EvilPenguin.MultipleChoiceQuestionBox">
...
public partial class MultipleChoiceQuestionBox<T> : Window where T : System.Enum
{
public MultipleChoiceQuestionBox()
{
InitializeComponent();
}
public T SelectedOption
{
get;
}
}
- Is there a way I can make my XAML generate a partial class with the correct generic argument?
- Am I 'doing it wrong'? Is this a bad idea for some reason, or is there an easier way?
- Is this not possible in XAML at the moment? The x:TypeArgument attribute doesn't quite do what I want, but it suggests that at least some aspects of XAML are aware of generic arguments
Any help or hints are much appreciated