Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF TreeView : How to create header and nodes from different models
    primarykey
    data
    text
    <p>I am working on a wpf project where I have to build tree nodes recursively. What I wanted to do is assign header for the nodes from another model for example:</p> <pre><code> Request Header --&gt; node1 --&gt;node1.1 --&gt;node1.2 Response Header --&gt;node2 --&gt;node2.1 --&gt;node2.2 // building tree public List&lt;TreeModel&gt; BuildTree(IEnumerable&lt;string&gt; 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 &gt; g.Key.Length + 1 select s.Substring(g.Key.Length + 1)) } ).ToList(); } // Here I am creating static MessageElementModel objects </code></pre> <p>The reason why I am creating these objects is I want to associate them to another control(combobox) to create on select event but this is not part of my question.</p> <pre><code> public List&lt;MessageElementModel&gt; 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)) </code></pre> <p>In the XAML I have </p> <p> </p> <pre><code> &lt;HierarchicalDataTemplate DataType="{x:Type local:TreeViewModel}" ItemsSource="{Binding Children}"&gt; &lt;CheckBox IsChecked="{Binding Value}" Content="{Binding Value}" /&gt; &lt;/HierarchicalDataTemplate&gt; &lt;/TreeView.Resources&gt; &lt;/TreeView&gt; 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&lt;TransactionTypeViewModel&gt;() { 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&lt;MessageElementViewModel&gt; GetAllTreeNodesList() { messageElements = TransactionType.getAllTreeNodes().Select(msgElements =&gt; new MessageElementViewModel { Id = msgElements.Id, Request = msgElements.Request, Response = msgElements.Response, }).ToList(); return messageElements; } //make it observable public ObservableCollection&lt;MessageElementViewModel&gt; GetAllTreeNodes() { observableMessageElement = new ObservableCollection&lt;MessageElementViewModel&gt; (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? </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload