public DynamicDataGrid() { var obs = Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(h => this.Loaded += h, h => this.Loaded -= h).Select(_ => 0); var obs2 = Observable.When(KeyChangeSubject.And(ValueChangeSubject).And(ItemsSourceSubject).Then((a, b, c) => 0)); obs.Amb(obs2) .CombineLatest(KeyChangeSubject.StartWith(Key).DistinctUntilChanged(), (a, b) => b) .CombineLatest(ValueChangeSubject.StartWith(Value).DistinctUntilChanged(), (a, b) => b) .CombineLatest(ItemsSourceSubject.DistinctUntilChanged(), (a, b) => b) .Subscribe(_ => { this.Dispatcher.InvokeAsync(() => this.SetValue(ItemsSourceProperty, DynmamicHelper.OnGetData(_, Key, Value)), System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken)); }); }
public ExtractClassButtonViewModel( IProject project, IContext context, Action <IExtractClassViewModel> openDialogAction, IFileSystem fileSystem, IClassExtractor classExtractor) { _hovering = new BehaviorSubject <bool>(false); var allClassNames = project.Classes.Select( elements => { var elementList = elements as IList <IElement> ?? elements.ToList(); if (!elementList.Any()) { return(Observable.Return(new List <Optional <string> >())); } return(elementList.Select(el => el.UxClass()).CombineLatest()); }).Switch().Select(x => new HashSet <string>(x.NotNone())).Replay(1).RefCount(); var canExtractSelectedElement = context.CurrentSelection.IsEmpty.IsFalse() .And(context.CurrentSelection.Parent.IsEmpty.IsFalse()) // Not the App(root) element // We can't extract an element which is already a class .And(context.CurrentSelection.UxClass().Is(Optional.None())) // Extracting classes listed in _invalidUxClassNames creates invalid UX .And(context.CurrentSelection.Name.Select(name => !_invalidUxClassNames.Contains(name))) .Replay(1) .RefCount(); _highlightSelectedElement = _hovering.And(canExtractSelectedElement); _command = Command.Create( canExtractSelectedElement, context.CurrentSelection.Name.CombineLatest( allClassNames, (selectedElementName, classNames) => (Action)(() => { openDialogAction( new ExtractClassViewModel( context: context, suggestedName: GetClassNameSuggestion(selectedElementName, classNames), allClassNames: allClassNames, classExtractor: classExtractor, fileSystem: fileSystem, project: project)); }))); }
public DynamicDataGrid() { //Uri resourceLocater = new Uri("/UtilityWpf.View;component/Themes/DynamicDataGrid.xaml", System.UriKind.Relative); //ResourceDictionary resourceDictionary = (ResourceDictionary)Application.LoadComponent(resourceLocater); //Style = resourceDictionary["DynamicDataGridStyle"] as Style; var obs = Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(h => this.Loaded += h, h => this.Loaded -= h).Select(_ => 0); var obs2 = Observable.When(KeyChangeSubject.And(ValueChangeSubject).And(ItemsSourceSubject).Then((a, b, c) => 0)); obs.Amb(obs2) .CombineLatest(KeyChangeSubject.StartWith(Key).DistinctUntilChanged(), (a, b) => b) .CombineLatest(ValueChangeSubject.StartWith(Value).DistinctUntilChanged(), (a, b) => b) .CombineLatest(ItemsSourceSubject.DistinctUntilChanged(), (a, b) => b) .Subscribe(_ => { this.Dispatcher.InvokeAsync(() => this.SetValue(ItemsSourceProperty, DynmamicHelper.OnGetData(_, Key, Value)), System.Windows.Threading.DispatcherPriority.Background, default(System.Threading.CancellationToken)); }); }