System.invalidoperationexception:'items collection在使用itemssource之前必须为空。' [英] System.invalidoperationexception: 'items collection must be empty before using itemssource.'
本文介绍了System.invalidoperationexception:'items collection在使用itemssource之前必须为空。'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我点击按钮系统时抛出异常
When I click on the button system throws exception
System.InvalidOperationException: 'Items collection must be empty before using ItemsSource.'
我无法找到问题
我的尝试:
点击这样的按钮我想创建一个树
I am unable to find the problem
What I have tried:
I am trying to create a tree when click on a button like this
<pre>private void Button_Click_1(object sender, RoutedEventArgs e)
{
var subModules = new List<ITreeNode>
{
new SubModule { Name = "Sub Module 1" }
};
var subThreads = new List<ITreeNode>
{
new SubThread { Name = "Sub Thread 1" }
};
var nodes = new List<ITreeNode>
{
new Thread { Name = "Thread ", ChildNodes = subThreads },
new Module { Name = "Module ", ChildNodes = subModules }
};
var processes = new List<RunProcesses>
{
new RunProcesses{ Name = "Process1", ChildNodes = nodes }
};
TreeView.ItemsSource = processes;
}
推荐答案
阅读错误信息,它非常明确:
Read the error message, it's pretty explicit:
System.InvalidOperationException: 'Items collection must be empty before using ItemsSource.'
您正在设置已包含数据的集合(Treeview)的ItemsSource属性。
检查您的XAML,或清空Items Collection。
You are setting the ItemsSource property of a collection (the Treeview) which already has data in it.
Check your XAML, or empty the Items Collection.
这篇关于System.invalidoperationexception:'items collection在使用itemssource之前必须为空。'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文