Can someone guide me how programmatically expand and collapse the tree and subtrees? I currently do not use a property called IsExpand.
My view
<controls:TreeView ItemTemplate="{StaticResource TreeviewDataTemplate}"
ItemsSource="{Binding TreeItems}" Style="{StaticResource TouchTreeViewStyle}"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
Data binding on TreeViewpageViewModel:
private void BuildTree()
{
var tree = BuildChildrenTree(_fullAgendaItems.Where(a => a.PreviousId == null).ToList());
TreeItems = tree;
}
and
private ObservableCollection<AgendaItem> BuildChildrenTree(List<AgendaItem> agendaItems)
{
var tree = new ObservableCollection<AgendaItem>();
const string functionName = "BuildChildrenTree";
try
{
//Logs.Write.Entry(ClassName + functionName);
foreach (var item in agendaItems)
{
item.Children =
BuildChildrenTree(
FullAgendaItems.Where(a => a.PreviousId == item.Id && item.HeadorPaper == 0).ToList());//
#region Change bg color of the currently seleted item
if (_globalSelectedAgendaItem != null && _globalSelectedAgendaItem.Id == item.Id)
{
item.AgendaItemDefaultBg = SelectedColor;
}
#endregion
tree.Add(item);
}
//Logs.Write.Success(ClassName + functionName);
}
catch (Exception ex)
{
Logs.Write.Error(Utility.FmtErrData(ClassName + functionName, ex));
}
return tree;
}