private IEnumerable <IDisposable> Binding() { yield return (this.WhenAnyValue(x => x.ItemsSource).Where(x => x != null).Subscribe( itemsSource => { var collection = itemsSource.Union(itemsSource.SelectMany(x => x.Childs)); if (SelectedItem == null && collection.Any(x => x.IsAccess)) { CatalogHierarchical selectCatalog = collection.First(x => x.IsAccess); SelectedItem = new Catalog(selectCatalog.Rn) { Name = selectCatalog.Name }; } TrvAcatalog.ItemsSource = itemsSource; })); yield return (this.WhenAnyValue(x => x.TrvAcatalog.SelectedItem) .Where(x => x != null && ((CatalogHierarchical)x).IsAccess) .Subscribe( selectedItem => { var selecCatalog = (CatalogHierarchical)selectedItem; SelectedItem = new Catalog(selecCatalog.Rn) { Name = selecCatalog.Name }; })); }
private static bool FindChildrenHierarchical(CatalogHierarchical catalog, IList <Acatalog> accessCatalog) { foreach (var elem in catalog.Childs) { elem.IsAccess = FindChildrenHierarchical(elem, accessCatalog); } return(accessCatalog.Where(x => x.Rn == catalog.Rn).Any()); }