Recursive XAML binding data templates on the Universal Windows Platform -


so have class task has couple of properties , can have list task objects ( child tasks ) inside it. recursively display each tasks , sub-tasks on 'uwp'. apparently 'wpf' had special 'usercontrols' purpose according post: are recursive datatemplates possible?

but don't seem available on 'uwp'.

you can use treeview control.

here links project: nuget:winrtxamltoolkit , github:winrtxamltoolkit.

install in project using package manager console:install-package winrtxamltoolkit.uwp

i've made basic demo requirement. see codes below:

mainpage.xaml:

<page x:class="treeviewsample.mainpage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:treeviewsample" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="using:winrtxamltoolkit.controls" xmlns:data="using:winrtxamltoolkit.controls.data" mc:ignorable="d">  <grid background="{themeresource applicationpagebackgroundthemebrush}">     <controls:treeview  itemssource="{x:bind mylist}">         <controls:treeview.itemtemplate>             <datatemplate>                 <data:datatemplateextensions.hierarchy>                     <data:hierarchicaldatatemplate itemssource="{binding subtasks}"></data:hierarchicaldatatemplate>                 </data:datatemplateextensions.hierarchy>                 <textblock text="{binding name}"></textblock>             </datatemplate>         </controls:treeview.itemtemplate>     </controls:treeview> </grid> 

mainpage.xaml.cs:

namespace treeviewsample {     public sealed partial class mainpage : page     {         public mainpage()         {             this.initializecomponent();         }         public list<task> mylist;          protected override void onnavigatedto(navigationeventargs e)         {             mylist = new list<task>();             var  taska = new task("taska");             taska.subtasks = new list<task> {             new task("subtaska"),             new task("subtaskb"),             new task("subtaskc")         };         taska.subtasks[0].subtasks = new list<task> {             new task("subsubtaska"),             new task("subsubtaskb"),             new task("subsubtaskc"),             new task("subsubtaskd")         };         mylist.add(taska);     } }      public class task     {         public task(string name) {             this.name = name;         }          private string name;          public string name         {             { return name; }             set { name = value; }         }          public list<task> subtasks { get; set; }      } } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -