【问题标题】:WPF Bind XSD Schema to TreeViewWPF 将 XSD 架构绑定到 TreeView
【发布时间】:2016-08-23 06:29:23
【问题描述】:

我的数据集的表名将作为我的树视图的节点。 我想将 XSD 模式绑定到 treeView 我厌倦的代码是: System.IO.StreamReader xmlStream = new System.IO.StreamReader(@"C:\code\depot\profile.xsd"); 数据集数据集 = 新数据集(); dataSet.ReadXmlSchema(xmlStream); xmlStream.Close(); 返回数据集.Tables[0]; 和 grid.ItemsSource = ViewModel.GetDataFromXML(); XAML

我什至可以在任何地方使用 Telerik/infragistics。

注意:我想提一下它是模式,将显示在 treeView 中,XSD 不包含任何数据。

【问题讨论】:

    标签: wpf xsd telerik treeview infragistics


    【解决方案1】:

    你可以试试这个:

     System.IO.StreamReader xmlStream = new System.IO.StreamReader(@"C:\NORTHWNDDataSet.xsd");
     DataSet dataSet = new DataSet();
     dataSet.ReadXmlSchema(xmlStream);
     xmlStream.Close();
    
     treeView.ItemsSource = dataSet.Tables;
     reeView.DisplayMemberPath = "TableName";
    

    【讨论】:

    • 您好,非常感谢!!我能够在树视图中将表名称显示为节点。但是,它丢失了 XSD 中的层次结构,并且所有树节点都位于同一级别。 它显示为 b c x y 希望我们非常接近答案。
    • 我不确定你的意思。 DataSet 有一个 Tables 属性,它是表的集合,并且没有表层次结构,因此它们显示在 1 级。
    • 是的,你是对的。在这种情况下,我将使用传统方式而不是这种快捷方式;):读取架构并创建 C# 对象并将其绑定到树视图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    • 2017-07-09
    • 2011-01-31
    • 2014-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多