Я пытаюсь изменить код, в котором содержимое, созданное с помощью ObservableCollection, в коллекцию, созданную с помощью XMLDataprovider.Я могу сгенерировать контент с XMLDataProvider успешно.Проблема, которую я сейчас пытаюсь решить, состоит в том, чтобы изменить код, на который он ссылается, на контент, сгенерированный из ObservableCollection.Каждый раз, когда я запускаю описанный ниже метод, мое приложение зависает.Похоже, что IList не является подходящей ссылкой на коллекцию XML.Что следует использовать вместо этого?Заранее спасибо.
public static void InsertItemInItemsControl(ItemsControl itemsControl, object itemToInsert, int insertionIndex)
{
if (itemToInsert != null)
{
IEnumerable itemsSource = itemsControl.ItemsSource;
if (itemsSource == null)
{
itemsControl.Items.Insert(insertionIndex, itemToInsert);
}
// It looks like IList is not appropriate reference to XML collection else if (itemsSource is IList)
{
((IList)itemsSource).Insert(insertionIndex, itemToInsert);
}
else
{
Type type = itemsSource.GetType();
Type genericIListType = type.GetInterface("IList`1");
if (genericIListType != null)
{
type.GetMethod("Insert").Invoke(itemsSource, new object[] { insertionIndex, itemToInsert });
}
}
}
}