我试图在wpf中以非绑定模式devexpress控制构造一棵树。 我已经提到以下链接Building a Tree in Unbound Mode。请检查图像,我在xaml代码中出现错误。所需的输出是硬编码数据必须出现在树形图中,但如果我从第38-44行删除了xaml代码,则出现的输出只是树形结构。我知道错误是在xaml中我仍然提供cs代码。
***************************代码******************* **********************
namespace PstImporter
{
/// <summary>
/// Interaction logic for pstSelect.xaml
/// </summary>
public partial class pstSelect : Window
{
string stgPath;
public pstSelect ()
{
InitializeComponent();
treePstSelect.Visibility = Visibility.Hidden;
List < MailboxHelper.Folder > lstMailBoxHelper = Globals.selectFolder(fileName);
buildTree(lstMailBoxHelper);
treeListView1.ExpandAllNodes();
this.barButtonItem1.ItemClick += this.barButtonItem1_ItemClick;
}
public class ProjectObject
{
public string Name { get; set; }
public string Executor { get; set; }
}
private void buildTree (List<MailboxHelper.Folder> lstMailBoxHelper)
{
TreeListNode rootNode = CreateRootNode(new ProjectObject() { Name = lstMailBoxHelper[0].displayName, Executor = lstMailBoxHelper[1].displayName });
TreeListNode childNode = CreateChildNode(rootNode, new ProjectObject() { Name = lstMailBoxHelper[2].displayName, Executor = lstMailBoxHelper[1].displayName });
CreateChildNode(childNode, new ProjectObject() { Name = lstMailBoxHelper[3].displayName, Executor = lstMailBoxHelper[1].displayName });
}
private TreeListNode CreateRootNode(object dataObject)
{
TreeListNode rootNode = new TreeListNode(dataObject);
treeListView1.Nodes.Add(rootNode);
return rootNode;
}
private TreeListNode CreateChildNode (TreeListNode parentNode, object dataObject)
{
TreeListNode childNode = new TreeListNode(dataObject);
parentNode.Nodes.Add(childNode);
return childNode;
}
答案 0 :(得分:1)
您不能在xaml中引用嵌套类。下面是MSDN关于嵌套类的说法
http://msdn.microsoft.com/en-us/library/ms753379.aspx
您的自定义类不能是嵌套类。嵌套类和 &#34;点&#34;在他们的一般CLR使用语法中干扰其他WPF 和/或XAML功能,例如附加属性。
您可以从Window类
中取出ProjectObject
课程
namespace PstImporter
{
public class ProjectObject
{
public string Name { get; set; }
public string Executor { get; set; }
}
}
然后你可以参考它
xmlns:local="clr-namespace:PstImporter"
<local:ProjectObject>