private void CategoryTree_Expanded(object sender, RoutedEventArgs e) { TreeViewItem this_TreeViewItem = e.Source as TreeViewItem; TypeDigest parentCategoryTypeDigest = (TypeDigest)this_TreeViewItem.Tag; if (this_TreeViewItem.Items.Count > 0 && this_TreeViewItem.Items[0] is TreeViewItem && ((TreeViewItem)this_TreeViewItem.Items[0]).Tag is LoadingTreeViewItem) { this_TreeViewItem.Items.Clear(); foreach (TypeDigest childTypeDigest in _typeRepository.GetTypeDigestsByParent(parentCategoryTypeDigest.Id)) { this_TreeViewItem.Items.Add(CreateCategoryTreeViewItem(childTypeDigest.Code, childTypeDigest)); } } }