private void TreeView_SelectedItemChanged(object item) { if (item is TreeViewItem viewItem) { var hierarchyItem = (HierarchyItemViewModel)viewItem.Tag; if (hierarchyItem.IsFolder) { return; } var entityViewModel = (EntityViewModel)hierarchyItem; dispatcher.DispatchToActiveEditor(new SelectEntityCommand(), entityViewModel); } }