Hopefully this is a quick question. I have a class in C# which inherits from Window (WPF). I would like to treat this like a modal dialog, and am trying to make the dialog accept a generic type. The code is below:
public partial class PickingOptionsDialog<T> : Window
{
private T _SelectedOption;
public PickingOptionsDialog(ECartState State, String Bin)
{
InitializeComponent();
DataContext = new OptionsViewModel(State, Bin);
}
public PickingOptionsDialog()
{
InitializeComponent();
DataContext = new OptionsViewModel(ECartState.Picking, "1");
}
public T SelectedOption
{
get { return _SelectedOption; }
}
}
With this code, I get a compile time error stating that InitializeComponent() doesnt exist in the current context. Why does it do this?
In addition to this problem, I would like to make it so that the generic type allowed has to be an Enum. In java (if Enum was a type) I could do this like < T extends Enum >
. How can I accomplish this in C#?