Skip to content

Instantly share code, notes, and snippets.

var canSearch = this.WhenAnyValue(vm => vm.SearchTerm)
.Where(x => !string.IsNullOrWhiteSpace(x) && x.Length >= 3)
.Publish()
.RefCount();
SearchCmd = ReactiveCommand.CreateFromObservable<string, IEnumerable<string>>(term => Observable.StartAsync(_ => _movieService.GetMovies(term)).TakeUntil(canSearch));
SearchCmd.Subscribe(results =>
{
Results.Clear();
_isSearching = SearchCmd.IsExecuting.ToProperty(this, vm => vm.IsSearching);
readonly ObservableAsPropertyHelper<bool> _isSearching;
public bool IsSearching => _isSearching.Value;
public ReactiveCommand<string, IEnumerable<string>> SearchCmd { get; set; }
public ReactiveList<string> Results { get; set; }
string _searchTerm;
public string SearchTerm
{
get { return _searchTerm; }
set { this.RaiseAndSetIfChanged(ref _searchTerm, value); }
}
Results = new ReactiveList<string>();
var canSearch = this.WhenAny(x => x.SearchTerm, x => !string.IsNullOrWhiteSpace(x.Value) && x.Value.Length >= 3);
SearchCmd = ReactiveCommand.CreateFromTask<string, IEnumerable<string>>(term => _movieService.GetMovies(term), canSearch);
SearchCmd.Subscribe(results =>
{
Results.Clear();
Results.AddRange(results);
});
public partial class MainPage : ContentPage, IViewFor<MainViewModel>
{
public MainPage()
{
InitializeComponent();
ViewModel = new MainViewModel(new MovieService());
this.Bind(ViewModel, vm => vm.SearchTerm, v => v.entryField.Text);
this.OneWayBind(ViewModel, vm => vm.Results, v => v.resultList.ItemsSource);
this.OneWayBind(ViewModel, vm => vm.IsSearching, v => v.loadingBar.IsVisible);
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ReactiveUIExampleXamarinForms"
x:Class="ReactiveUIExampleXamarinForms.MainPage">
<StackLayout Padding="12">
<Label Text="Search:" VerticalOptions="Center" HorizontalOptions="Center" />
<Entry x:Name="entryField" />
<ActivityIndicator x:Name="loadingBar"/>
await _dialogService.ShowMessage("Message, "Title", "Ok", AfterAction);
public RelayCommand AddMonthCmd => new RelayCommand(async () =>
{
// w DashboardViewModel
await _navigationService.Navigate<MonthEditPage>();
});
public RelayCommand SaveCmd => new RelayCommand(async () =>
{
// w MonthEditViewModel - wracamy do Dashboardu
// zapisujemy...
public class DashboardViewModel : ViewModelBase
{
IDbService _dbService;
INavigationService _navigationService;
IMonthService _monthService;
public DashboardViewModel(IDbService dbService, INavigationService navigationService, IMonthService monthService)
{
_dbService = dbService;
_navigationService = navigationService;