observable collections in Silverlight
My application is developed using MVVM architecture in Silverlight and have below piece of code that is trying to retrieve all the Items(collection) and their corresponding Sub items from UI and it's working fine without any issue.
public ObservableCollection<DemoViewModel> Items { get; private set; }
foreach (var demoviewmodelitem in DemoViewModel.Items) //Items collection (Count=8)
{
foreach (var item in demoviewmodelitem.SubItems)
{
}
}
Now the requirement is changed and dont want to retreive all the Items (collection) and their corresponding subitems in the above code instead we need to just retrieve the Selected Item in UI with the corresponding subitems.For this requirement my team has changed the code in the viewModel class by adding a property selectedItem that contains item selected by the user and their corresponding subitems.
When I debug the above code in the Add Watch I can see DemoViewModel.selectedItem contains selected item by the user in UI (for instance Item6) and the corresponding subitems.
So I have changed the outer foreach loop from
foreach (var demoviewmodelitem in DemoViewModel.Items) //collection
to
foreach (var demoviewmodelitem in DemoViewModel.selectedItem)//Property
and getting following error. How can I get rid of this error and want to retrieve only selecteditem and the corresponding subitems from the above code?
Error: foreach statement cannot operate on variables of type "class name XXXXXXXXX" does not contain a public definition for 'GetEnumerator'
Thanks in Advance
应该删除外部循环,其余(以前的内部)循环应该看起来像这样:
foreach (var item in DemoViewModel.selectedItem.SubItems)
{
}
链接地址: http://www.djcxy.com/p/53892.html
上一篇: 如果在ImpersonateSelf()失败后RevertToSelf()会致命吗?
下一篇: Silverlight中的可观察集合