How can i cast
from ObservableCollection<TabItem> into ObservableCollection<object>
this doesnt work for me
(ObservableCollection<object>)myTabItemObservableCollection
How can i cast
from ObservableCollection<TabItem> into ObservableCollection<object>
this doesnt work for me
(ObservableCollection<object>)myTabItemObservableCollection
You can't. ObservableCollection<TabItem>
does not derive from ObservableCollection<object>
.
If you explain why you would want to perhaps we can point out an alternative interface you can use.
you can't in .net 3.5, .net 4 solve this problem in more elegant way. in .net 3.5 you should copy like this
return new ObservableCollection<object>(myTabItemObservableCollection);
Basically, you can't. Not now, and not in .NET 4.0.
What is the context here? What do you need? LINQ has Cast<T>
which can get you the data as a sequence, or there are some tricks with generic methods (i.e. Foo<T>(ObservalbleCollection<T> col)
etc).
Or you can just use the non-generic IList
?
IList untyped = myTypedCollection;
untyped.Add(someRandomObject); // hope it works...
thanx for all answers, but I think I have solve this problem self with a "helpermethode".
Perhaps has any a better method or a linq statement for this.
private void ConvertTabItemObservableCollection()
{
Manager manager = this.container.Resolve<Manager>();
foreach (var tabItem in manager.ObjectCollection)
{
TabItemObservableCollection.Add((TabItem)tabItem);
}
}