Check Object type in List of Objects

后端 未结 4 1186
刺人心
刺人心 2021-01-28 13:03

Got a WPF Form with a StackPanel containing Expanders with StackPanels in it.


    

        
4条回答
  •  天命终不由人
    2021-01-28 13:23

    You can use OfType<> to filter for just a specific type in a list. I understand that you want to loop through all the StackPanels (in the list), so you can do something like this:

    foreach(var panel in tmpList.OfType()){
        //your work here ...
    }
    

    If you want to check if there is any StackPanel, then use this:

    if(tmpList.OfType().Any()){
        //...
    }
    

提交回复
热议问题