0

ツリー ノードを再帰的に構築する必要がある wpf プロジェクトに取り組んでいます。私がやりたかったのは、たとえば別のモデルからノードのヘッダーを割り当てることです。

    Request Header  --> node1
                -->node1.1
                -->node1.2
    Response Header  -->node2 
                -->node2.1
                -->node2.2

// building tree 
   public List<TreeModel> BuildTree(IEnumerable<string> strings)
      {
        return (
          from s in strings
          let split = s.Split('.')
          group s by s.Split('.')[0] into g
          select new TreeModel
          {
              Value = g.Key,
              Children = BuildTree(
                from s in g
                where s.Length > g.Key.Length + 1
                select s.Substring(g.Key.Length + 1))
          }
          ).ToList();


    }

 // Here I am creating static MessageElementModel  objects  

これらのオブジェクトを作成する理由は、それらを別のコントロール(コンボボックス)に関連付けて選択イベントで作成したいからですが、これは私の質問の一部ではありません。

      public List<MessageElementModel> GetAllMessageElements()
       {
        string[] request = { "NetworkControl.AlternateIndexText.Value" };
        string[] request2 = { "NetworkControl.NetworkControl.AddressData.TransactionOriginatorID.Value" };
        string[] request3 = { "VehicleSummary.VehicleIdentification.IdentificationID.Value" };

       transactionTypeWSRequestXmlType = TransactionTypeModle.TransactionTypeWSRequestXmlType;
        transactionTypeWSResponseXmlType = TransactionTypeModel.TransactionTypeWSRequestXmlType;


        messageElements.Add(new MessageElementModel(1, transactionTypeWSRequestXmlType,transactionTypeWSResponseXmlType, TreeNode.BuildTree(request)));
        messageElements.Add(new MessageElementModel(1, transactionTypeWSRequestXmlType,transactionTypeWSResponseXmlType, TreeNode.BuildTree(request2)));


        return messageElements;

    }

    The transactionTypeWSRequestXmlType,transactionTypeWSResponseXmlType and transactionTypeWSRequestXmlType,transactionTypeWSResponseXmlType are the headers of the tree (TreeNode.BuildTree(request))

私が持っているXAMLで

                <HierarchicalDataTemplate DataType="{x:Type local:TreeViewModel}" ItemsSource="{Binding Children}">
                    <CheckBox IsChecked="{Binding Value}" Content="{Binding Value}" />
                </HierarchicalDataTemplate>
            </TreeView.Resources>

        </TreeView>



    How can I add header from another model? for this case transactionTypeWSRequestXmlType,transactionTypeWSResponseXmlType and transactionTypeWSRequestXmlType,transactionTypeWSResponseXmlType to the treeview for the nodes I am creating in the TreeNode.BuildTree(request) recursively? 


             and the same for var response;
        var treeNode = new ObservableCollection<TransactionTypeViewModel>() { request,   response };
        }
        return treeNode;
       }
 In the messageElementViewModel I am getting the constructed      nods(TreeNodeModel)+roots(TransactionTypeViewModel)

 here I addded Id so that when I chose any transaction from my Transaction combobox the    tree will display only matching Ids

   public List<MessageElementViewModel> GetAllTreeNodesList()
    {
        messageElements = TransactionType.getAllTreeNodes().Select(msgElements => new      MessageElementViewModel
        {
            Id = msgElements.Id,
            Request = msgElements.Request,
            Response = msgElements.Response,

        }).ToList();

        return messageElements;
    }       
//make it observable 

  public ObservableCollection<MessageElementViewModel> GetAllTreeNodes()
    {
        observableMessageElement = new ObservableCollection<MessageElementViewModel>  (messageElements);
        return observableMessageElement;

    }

 //xaml binding to MessageElementViewModel where I have the roots and nodes combination

  How can I bind all these together in the xaml?
4

0 に答える 0