[Windows Store]ComboBox & ComboBoxItems

I tried to be clever and created simple concept of filtering items in my app. I ended up with a few ComboBoxes, each containing a few filter options (sorting, show objects published in a certain timespan and whatnot).

The problem seems to be caused by ComboBoxItems. I create a combobox, then in real-time, in async function I populate it with filters:

foreach (var op in options) cb.Items.Add(op.PreviousSibling.InnerText); 

That much works without problems, but when I try to change the name attribute of the ComboBoxItem, app crashes.

ComboBoxItem i = (ComboBoxItem)cb.Items.Last<Object>(); i.Name = op.GetAttributeValue("value", null); 

According to what I remember, this should work, but it seems the .Items list is of type String, not ComboBoxItem, as I expected.

$exception {"Unable to cast object of type 'System.String' to type 'Windows.UI.Xaml.Controls.ComboBoxItem'."} System.Exception {System.InvalidCastException}

What can I do to avoid declaring a lot of temporary lists?

by MrReynevan2 via /r/csharp

Leave a Reply