Sorry for the stupid title, had no idea how to say it
I am creating a class that has two lists of the same type. It was used to copy the object reference in the first list to the second list.
Although both lists will be of the same type (keep the same type of object), it can be different each time this class is initialized.
So, I assume that I should make List types a sort of abstract list. I would like them to be strongly typed when they were created (but not necessarily if they are problematic). The problem is that the method that moves the selected items from the lists list1 to list2 usually does not have methods for this.
I suppose that the usual solution would be to make the generic class (className <T> thingy), but I'm not sure I can do it (at least I don't know how), because this class inherits from WPF UserControl.
Here is the code:
public partial class SubsetSelectionLists : UserControl { public static DependencyProperty SetCollectionProperty = DependencyProperty.Register("SetCollection", typeof("Need a abstract list type here"), typeof(SubsetSelectionLists)); public static DependencyProperty SubsetCollectionProperty = DependencyProperty.Register("SubsetCollection", typeof("Need a abstract list type here"), typeof(SubsetSelectionLists)); public "Need a abstract list type here" SetCollection { get { return ("Need a abstract list type here") GetValue(SetCollectionProperty); } set { SetValue(SetCollectionProperty, value); } } public "Need a abstract list type here" SubsetCollection { get { return ("Need a abstract list type here")GetValue(SubsetCollectionProperty); } set { SetValue(SubsetCollectionProperty, value); } } public SubsetSelectionLists() { InitializeComponent(); SubsetSelectiongrid.DataContext = this; } private void selectionBtnClick(object sender, RoutedEventArgs e) { SubsetCollection.AddTheseItems(SET.SelecctedItems) } private void removeBtnClick(object sender, RoutedEventArgs e) { SUBSET.RemoveTheseItems(SUBSET.SelectedItem); } }
EDIT: Solution
In some answers, I pointed out the optimal solution for creating a Generic Class. However, this can be problematic in WPF. You will need to skip XAML in the top-level generic class.
This would mean that you can do XAML in child classes of the type you don't want to do (unless the code is something you would reuse, but the look is variable). You could also design control with code, I think, but I'm not sure how efficient it is.
I pointed to an IList object, which is an abstract list that many others inherit, and I will use. It's a bit of a hack, but since it won't be used in an open library, I'm fine. Otherwise, I would use a common route.
collections generics c # abstract-class user-controls
Ingó vals
source share