Last active
May 6, 2018 18:09
-
-
Save christiannagel/b84d6623419e8d977ced48574bad622d to your computer and use it in GitHub Desktop.
Fill the TreeView with sample data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed partial class MainPage : Page | |
{ | |
public MainPage() => InitializeComponent(); | |
private void OnSelectionChanged(TreeView sender, TreeViewItemInvokedEventArgs args) | |
{ | |
if (args.InvokedItem is TreeViewNode node && node.Content is CultureData cd) | |
{ | |
ViewModel.SelectedCulture = cd; | |
} | |
} | |
public CulturesViewModel ViewModel { get; } = new CulturesViewModel(); | |
protected override void OnNavigatedTo(NavigationEventArgs e) | |
{ | |
void AddSubNodes(TreeViewNode parent) | |
{ | |
if (parent.Content is CultureData cd && cd.SubCultures != null) | |
{ | |
foreach (var culture in cd.SubCultures) | |
{ | |
var node = new TreeViewNode | |
{ | |
Content = culture | |
}; | |
parent.Children.Add(node); | |
foreach (var subCulture in culture.SubCultures) | |
{ | |
AddSubNodes(node); | |
} | |
} | |
} | |
} | |
base.OnNavigatedTo(e); | |
var rootNodes = ViewModel.RootCultures.Select(cd => new TreeViewNode | |
{ | |
Content = cd | |
}); | |
foreach (var node in rootNodes) | |
{ | |
treeView1.RootNodes.Add(node); | |
AddSubNodes(node); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment