public MainViewModelTest() { ApplicationContext context = new ApplicationContext(); repos = new PhoneRepositoryAsync(context); // model = new MainViewModel(repos, new DialogManager(new DialogProvider(typeof(App).Assembly)) ) }
public MainViewModel(IPhoneRepositoryAsync repository, IDialogManager dialogManager) { MainViewController _controller = new MainViewController(repository, dialogManager, this); this.WhenActivated(disposables => { _controller.BindTitle().DisposeWith(disposables); _controller.BindRefreshFilter().DisposeWith(disposables); _controller.BindRefreshCommand().DisposeWith(disposables); _controller.BindTestCommand().DisposeWith(disposables); _controller.BindEditCommand().DisposeWith(disposables); _controller.BindConfirmCommand().DisposeWith(disposables); _controller.BindOpenFilesCommand().DisposeWith(disposables); _controller.BindOpenFolderCommand().DisposeWith(disposables); RefreshCommand.Execute().Subscribe(phones => { var m = this; //то что сделать после обработки по умолчанию }).DisposeWith(disposables); }); }
public MainViewController(IPhoneRepositoryAsync repository, IDialogManager dialogManager, MainViewModel model) : this(repository, dialogManager) { _model = model; }
public MainViewController(IPhoneRepositoryAsync repository, IDialogManager dialogManager) { _repository = repository; _dialogManager = dialogManager; }
public ReposPhone() { PgApplicationContext context = new PgApplicationContext(); repos = new PhoneRepositoryAsync(context); }
// private readonly ReactiveCommand<Unit, EditPhoneViewModelResult> _edit; public MainWindowModel() { IScheduler _sheduler = RxApp.MainThreadScheduler; IPhoneRepositoryAsync _repos = Locator.Current.GetService <IPhoneRepositoryAsync>(); //https://itnan.ru/post.php?c=1&p=418007 //https://github.com/jamilgeor/FormsTutor //https://jamilgeor.com/refreshing-a-listview-with-reactivecommand/ //https://github.com/reactiveui/ReactiveUI#throttling-network-requests-and-automatic-search-execution-behaviour //https://dynamic-data.org/category/reactiveui/ //https://github.com/reactiveui/DynamicData //https://oz-code.com/blog/mvvm-gone-reactive-creating-wpf-twitter-client-reactiveui/ //this.WhenAnyValue(x => x.SearchTerm).InvokeCommand(this, x => x.Search); если есть данные в троке, то выполняю ReactiveCommand "Search", можно отложить на 1 сек Throttle // _refresh = ReactiveCommand.CreateFromTask(() => _repos.GetAllAsEnumerable()); var t = getPhones(); _refresh = ReactiveCommand.CreateFromTask(() => getPhones()); var canEdit = this .WhenAnyValue(x => x.SelectedPhone) .IsEmpty() .Select(x => !x); //.Select(x => true); /* _edit = ReactiveCommand.CreateFromObservable<Unit, EditPhoneViewModelResult>( * _ => { * return Locator.Current.GetService<IDialogManager>().Open(new EditPhoneViewModel(SelectedPhone)); * }, canEdit, _sheduler); */ _phones = _refresh .Select(phones => phones.Select(phone => new RxPhone(phone.Id, phone.Title))) .ObserveOn(_sheduler) .ToProperty(this, x => x.Phones); _errorMessage = _refresh .ThrownExceptions .Select(exception => exception.Message) .Log(this, $"Error refresh data") .ObserveOn(_sheduler) .ToProperty(this, x => x.ErrorMessage); _hasErrors = _refresh .ThrownExceptions .Select(exception => true) .Merge(_refresh.Select(unit => false)) .ObserveOn(_sheduler) .ToProperty(this, x => x.HasErrors); _isBusy = _refresh .IsExecuting .ObserveOn(_sheduler) .ToProperty(this, x => x.IsBusy); /* this.WhenAnyValue(vm => vm.Phones) * .Where(x => x != null) * .Select(list => list.FirstOrDefault(p => p.Id == 3)) * .Select(item => new RxPhone(item.Id, item.Title)) * .ObserveOn(_sheduler) * .Subscribe(phone => SelectedPhone = phone);*/ this.WhenAnyValue(vm => vm.Phones) .Where(x => x != null) .Select(list => list.Count()) .ObserveOn(_sheduler) .ToProperty(source: this, property: vm => vm.CountPhones, result: out _countPhones, initialValue: 0); //this.WhenActivated(disposables => //{ // _refresh.Execute().Subscribe().DisposeWith(disposables); //}); }
public EditPhoneViewModelController(IPhoneRepositoryAsync repos, IScheduler scheduler, IDialogManager dialogManager) { _repos = repos; _scheduler = scheduler; _dialogManager = dialogManager; }
public PhoneRepositoryAsyncTest() { ApplicationContext context = new ApplicationContext(); repos = new PhoneRepositoryAsync(context); }