我有一個ObservableCollection<Object>
,它包含兩種不同類型的對象:Directory
和File
。這個集合必然是一個控件,有時候我想過濾掉File
。某些類型的過濾器對象ObservableCollection <Object>
我有以下的代碼,這是行不通的:
var files = (from File f in (from Directory d in selectedDirs
select d.Childs)
where f is File
select f);
我得到這個錯誤:
Unable to cast object of type 'System.Collections.ObjectModel.ObservableCollection`1[System.Object]' to type 'CMBraga_FileExplorer.File'.
我怎樣才能得到我的價值觀?我知道他們是File
s。
// this was ran without explicit conversion (just as an example)
? myCollection
Count = 5
[0]: {CMBraga_FileExplorer.File}
[1]: {CMBraga_FileExplorer.File}
[2]: {CMBraga_FileExplorer.File}
[3]: {CMBraga_FileExplorer.File}
[4]: {CMBraga_FileExplorer.File}
地獄是的工作!非常感謝你們! –