我想在同一個集合中保存不同類型的對象,但無法解決問題。如何在c#中的集合中保存不同類型的對象?
public class SetupStep
{
public ObservableCollection</*Picture- or ParameterContaienr*/> Containers {get; set;}
}
public class PictureContainer
{
public ObservableCollection<Picture> Content {get; set;}
}
public class ParameterContainer
{
public ObservableCollection<Parameter> Content {get; set;}
}
我認爲這將是通過接口和仿製藥可解,但我還沒有找到一個有效的解決方案爲止。 最後,容器集合將被綁定到WPF中的ScatterView
的ItemsSource,它應該顯示具有不同內容的單個容器。
'的ObservableCollection
這一切都取決於您是否需要在將Container集合添加到集合後操作Containers集合的元素,即如果您需要設置其屬性或調用其方法後才能處理這個問題。如果不是,則不需要接口或泛型,只需將元素存儲在'ObservableCollection