Hello I have simple code for Competency and SubCompetencies.
Here is code-behind:
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Controls;
namespace opr.Pages
{
public partial class TeamsAdmin : Page
{
public ObservableCollection<Competency> Competencies { get; set; }
public TeamsAdmin()
{
InitializeComponent();
DataContext = this;
LoadData();
}
private void LoadData()
{
var allCompetencies = new ObservableCollection<Competency>
{
new Competency { Id = "0000000001", ParentId = null, Name = "REVIZIJA", Description = "", Ordinal = 4, State = true },
new Competency { Id = "0000000002", ParentId = null, Name = "RAČUNOVODSVO", Description = "", Ordinal = 3, State = true },
new Competency { Id = "0000000003", ParentId = null, Name = "POREZI", Description = "", Ordinal = 2, State = true },
new Competency { Id = "0000000004", ParentId = null, Name = "INTERNA REVIZIJA", Description = "Probni opis", Ordinal = 1, State = true },
new Competency { Id = "0000000005", ParentId = null, Name = "POSLOVNO SAVETOVANJE", Description = "", Ordinal = 10, State = true },
new Competency { Id = "0000000006", ParentId = "0000000001", Name = "Statutarna revizija", Description = "", Ordinal = 0, State = true },
new Competency { Id = "0000000007", ParentId = "0000000001", Name = "Dobrovoljna revizija", Description = "", Ordinal = 0, State = true },
new Competency { Id = "0000000008", ParentId = "0000000001", Name = "Revizija projekta", Description = "", Ordinal = 0, State = true },
new Competency { Id = "0000000009", ParentId = "0000000001", Name = "Finansijski pregled", Description = "", Ordinal = 0, State = true },
new Competency { Id = "0000000010", ParentId = "0000000001", Name = "Finansijski due diligence", Description = "", Ordinal = 0, State = true },
new Competency { Id = "0000000011", ParentId = "0000000001", Name = "Revizija grupnog paketa", Description = "", Ordinal = 0, State = true }
};
var rootCompetencies = new ObservableCollection<Competency>(
allCompetencies.Where(c => c.ParentId == null)
.Select(c => new Competency
{
Id = c.Id,
ParentId = c.ParentId,
Name = c.Name,
Description = c.Description,
Ordinal = c.Ordinal,
State = c.State,
SubCompetencies = new ObservableCollection<Competency>(
allCompetencies.Where(sub => sub.ParentId == c.Id))
})
);
Competencies = rootCompetencies;
treeListCompetencies.ItemsSource = Competencies;
}
}
public class Competency
{
public string Id { get; set; }
public string ParentId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int Ordinal { get; set; }
public bool State { get; set; }
public ObservableCollection<Competency> SubCompetencies { get; set; } = new ObservableCollection<Competency>();
}
}
ANd here is the xaml:
<Page x:Class="opr.Pages.TeamsAdmin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:local="clr-namespace:opr.Pages"
Title="TeamsAdmin">
<Page.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:Competency}" ItemsSource="{Binding SubCompetencies}">
<StackPanel Orientation="Horizontal">
<CheckBox Content="{Binding Name}" />
</StackPanel>
</HierarchicalDataTemplate>
</Page.Resources>
<Grid>
<dxg:TreeListControl x:Name="treeListCompetencies"
AutoGenerateColumns="None"
ItemsSource="{Binding Competencies}">
<dxg:TreeListControl.View>
<dxg:TreeListView TreeDerivationMode="HierarchicalDataTemplate" />
</dxg:TreeListControl.View>
</dxg:TreeListControl>
</Grid>
</Page>
As you can see on the example screenshot, it generates ok the structure, but something regarding the bindings for the name is not good.
I want to preview name for competency and subcompetency. How can I do that?