Wednesday 8 May 2019

wpf - 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 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

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...