This might and impossible scenario and I may be trying to do something that I should not be doing in the first place but here it is.
Is this possible? Am i doing something that I should not be doing? Any hints will appreciated. On a side note if I pass the second collection via the XAML all is well, but I do not want to add such restriction to the feature I am implementing.
Edit:
Here are some code snippets to showcase the scenario:
The first collection, note that this collection is inherited from the System.Windows.Controls.ItemsControl
class:
public IEnumerable ItemsSource { get; set; }
The second collection:
public IEnumerable SelectedItems
{
get
{
this.InitializeSelectedItemsCollectionIfRequired();
return (IEnumerable)GetValue(SelectedItemsProperty);
}
set
{
SetValue(SelectedItemsProperty, value);
}
}
private void InitializeSelectedItemsCollectionIfRequired()
{
if (this.GetValue(SelectedItemsProperty) == null)
{
// Here is where I want to initialize the second collection if it was not already set in via a Binding in the XAML
this.SelectedItems = new System.Collections.ObjectModel.ObservableCollection<"dont know how to pass correct type here">();
}
}
答案 0 :(得分:1)
由于您不知道确切的类型,因此您可以简单地恢复为最基本的类型object
this.SelectedItems = new System.Collections.ObjectModel.ObservableCollection<object>();