本文整理汇总了C#中ReactiveProperty.Select方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveProperty.Select方法的具体用法?C# ReactiveProperty.Select怎么用?C# ReactiveProperty.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveProperty
的用法示例。
在下文中一共展示了ReactiveProperty.Select方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializationViewModel
public SerializationViewModel()
{
// Observable sequence to ObservableCollection
Items = Observable.Interval(TimeSpan.FromSeconds(1))
.Take(30)
.ToReactiveCollection();
IsChecked = new ReactiveProperty<bool>();
SelectedIndex = new ReactiveProperty<int>();
Text = new ReactiveProperty<string>();
SliderPosition = new ReactiveProperty<int>();
var serializedString = new ReactiveProperty<string>(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe);
Serialize = serializedString.Select(x => x == null).ToReactiveCommand();
Deserialize = serializedString.Select(x => x != null).ToReactiveCommand();
// Click Serialize Button
Serialize.Subscribe(_ =>
{
// Serialize ViewModel's all ReactiveProperty Values.
// return value is string that Serialize by DataContractSerializer.
serializedString.Value = SerializeHelper.PackReactivePropertyValue(this); // this = ViewModel
});
// Click Deserialize Button
Deserialize.Subscribe(_ =>
{
// Deserialize to target ViewModel.
// Deseirlization order is same as DataContract.
// Can control DataMemberAttribute's Order Property.
// more info see http://msdn.microsoft.com/en-us/library/ms729813.aspx
SerializeHelper.UnpackReactivePropertyValue(this, serializedString.Value);
serializedString.Value = null; // push to command canExecute
});
}
示例2: ReactivePropertyBasicsPageViewModel
public ReactivePropertyBasicsPageViewModel()
{
// mode is Flags. (default is all)
// DistinctUntilChanged is no push value if next value is same as current
// RaiseLatestValueOnSubscribe is push value when subscribed
var allMode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe;
// binding value from UI Control
// if no set initialValue then initialValue is default(T). int:0, string:null...
InputText = new ReactiveProperty<string>(initialValue: "", mode: allMode);
// send value to UI Control
DisplayText = InputText
.Select(s => s.ToUpper()) // rx query1
.Delay(TimeSpan.FromSeconds(1)) // rx query2
.ToReactiveProperty(); // convert to ReactiveProperty
ReplaceTextCommand = InputText
.Select(s => !string.IsNullOrEmpty(s)) // condition sequence of CanExecute
.ToReactiveCommand(); // convert to ReactiveCommand
// ReactiveCommand's Subscribe is set ICommand's Execute
// ReactiveProperty.Value set is push(& set) value
ReplaceTextCommand.Subscribe(_ => InputText.Value = "Hello, ReactiveProperty!");
}
示例3: AsynchronousViewModel
public AsynchronousViewModel()
{
// Notifier of network connecitng status/count
var connect = new CountNotifier();
// Notifier of network progress report
var progress = new ScheduledNotifier<Tuple<long, long>>(); // current, total
// skip initialValue on subscribe
SearchTerm = new ReactiveProperty<string>(mode: ReactivePropertyMode.DistinctUntilChanged);
// Search asynchronous & result direct bind
// if network error, use OnErroRetry
// that catch exception and do action and resubscript.
SearchResults = SearchTerm
.Select(async term =>
{
using (connect.Increment()) // network open
{
return await WikipediaModel.SearchTermAsync(term, progress);
}
})
.Switch() // flatten
.OnErrorRetry((HttpRequestException ex) => ProgressStatus.Value = "error occured")
.ToReactiveProperty();
// CountChangedStatus : Increment(network open), Decrement(network close), Empty(all complete)
SearchingStatus = connect
.Select(x => (x != CountChangedStatus.Empty) ? "loading..." : "complete")
.ToReactiveProperty();
ProgressStatus = progress
.Select(x => string.Format("{0}/{1} {2}%", x.Item1, x.Item2, ((double)x.Item1 / x.Item2) * 100))
.ToReactiveProperty();
}
示例4: ReactionEditViewModelBase
public ReactionEditViewModelBase(PageManager pageManager, FolderReactionModel reactionModel)
{
PageManager = pageManager;
Reaction = reactionModel;
_CompositeDisposable = new CompositeDisposable();
IsValid = new ReactiveProperty<bool>(false)
.AddTo(_CompositeDisposable);
ValidateState = IsValid
.Select(x => x ? ValidationState.Valid : ValidationState.Invalid)
.ToReactiveProperty(ValidationState.WaitFirstValidate)
.AddTo(_CompositeDisposable);
}
示例5: NearAedPageViewModel
public NearAedPageViewModel ()
{
AedsViewModel = new ReactiveProperty<AedsViewModel>(new AedsViewModel());
IsUpdating = new ReactiveProperty<bool>(false);
UserLocation = new ReactiveProperty<Position?>(null);
SearchNearAedsCommand = IsUpdating.Select(x => !x).ToReactiveCommand<Map>();
SearchNearAedsCommand.Subscribe(async map =>
{
if(map?.VisibleRegion != null)
{
Settings.RegionLatitude = map.VisibleRegion.Center.Latitude;
Settings.RegionLongitude = map.VisibleRegion.Center.Longitude;
Settings.RegionRadius = map.VisibleRegion.Radius.Meters;
}
await UpdateNearAeds().ConfigureAwait(false);
});
}
示例6: AppOptionSelectDialogViewModel
public AppOptionSelectDialogViewModel(IAppPolicyManager appPolicyManager)
{
_CompositeDisposable = new CompositeDisposable();
AppPolicyManager = appPolicyManager;
Options = AppPolicyManager.Policies.SelectMany(x =>
{
return x.OptionDeclarations
.Concat(x.OutputOptionDeclarations)
.Select(y => new AppOptionListItemViewModel(x, y));
})
.ToList();
SelectedOption = new ReactiveProperty<AppOptionListItemViewModel>()
.AddTo(_CompositeDisposable);
IsSelectedOption = SelectedOption.Select(x => x != null)
.ToReactiveProperty(false);
}
示例7: Enemy
public Enemy(int initialHp)
{
// Declarative Property
CurrentHp = new ReactiveProperty<long>(initialHp);
IsDead = CurrentHp.Select(x => x <= 0).ToReactiveProperty();
}
示例8: InitializeSearchBar
/// <summary>
/// 検索バー用プロパティの初期化
/// </summary>
private void InitializeSearchBar()
{
SearchWord = new ReactiveProperty<string>("");
PageNumber = new ReactiveProperty<int>(1);
//実行中⇔停止中を通知
var isProcessing = progress.IsProcessingObservable.StartWith(false);
//[検索]コマンド
// 検索ボックスに文字が入っていて、検索実行中でない場合に実行可能
SearchCommand = new[]{
SearchWord.Select(x => string.IsNullOrWhiteSpace(x)),
isProcessing
}
.CombineLatestValuesAreAllFalse()
.ToReactiveCommand();
SearchCommand.Subscribe(_ =>
{
PageNumber.Value = 1;
SearchImage();
}).AddTo(disposables);
//[キャンセル]コマンド
//検索中の場合のみ実行可能
CancelCommand = isProcessing.ToReactiveCommand();
CancelCommand.Subscribe(_ =>
{
webImageStore.Cancel();
}).AddTo(disposables);
//検索コマンドのCanExecuteイベント を IObservable<bool> に変換
IObservable<bool> canSearchCommand = SearchCommand.CanExecuteChangedAsObservable().Select(_ => SearchCommand.CanExecute());
//ページめくり(戻す)コマンドの実行可否を表す IObservable<bool>
IObservable<bool> canPrevPageCommand = new[] {
PageNumber.Select(n => n > 1),
canSearchCommand
}.CombineLatestValuesAreAllTrue();
//ページめくり(送る)コマンドの実行可否を表す IObservable<bool>
IObservable<bool> canNextPageCommand = new[] {
PageNumber.Select(n => imageCountPerPage * n < maxResultCount),
canSearchCommand
}.CombineLatestValuesAreAllTrue();
//ページめくり(戻す)コマンド
PrevPageCommand = canPrevPageCommand.ToReactiveCommand();
PrevPageCommand.Subscribe(_ =>
{
PageNumber.Value--;
SearchImage();
}).AddTo(disposables);
//ページめくり(送る)コマンド
NextPageCommand = canNextPageCommand.ToReactiveCommand();
NextPageCommand.Subscribe(_ =>
{
PageNumber.Value++;
SearchImage();
}).AddTo(disposables);
//ページめくり(先頭ページ)コマンド
HeadPageCommand = canPrevPageCommand.ToReactiveCommand();
HeadPageCommand.Subscribe(_ =>
{
PageNumber.Value = 1;
SearchImage();
}).AddTo(disposables);
//ページめくり(最終ページ)コマンド
TailPageCommand = canNextPageCommand.ToReactiveCommand();
TailPageCommand.Subscribe(_ =>
{
PageNumber.Value = maxResultCount / imageCountPerPage;
SearchImage();
}).AddTo(disposables);
}
示例9: MainWindowViewModel
public MainWindowViewModel()
{
// Load
LoadDefaultConfiguration();
var useConnectionType = UseConnectionTypeSelectedIndex
.Select(x => (ConnectionProtocol)Enum.Parse(typeof(ConnectionProtocol), UseConnectionType[x]))
.ToReactiveProperty();
// Setup peer
peer = new ReactiveProperty<ObservablePhotonPeer>(new UseJsonObservablePhotonPeer(useConnectionType.Value));
peer.Select(x => x.ObserveStatusChanged())
.Switch()
.Subscribe(x =>
{
if (x == StatusCode.Connect)
{
CurrentConnectionStatus.Value = "Connecting : " + Address.Value + " " + AppName.Value;
}
else
{
CurrentConnectionStatus.Value = x.ToString();
}
Log.WriteLine(CurrentConnectionStatus.Value);
});
// Setup Properties
HubInfoListSelectedIndex.Subscribe(x =>
{
foreach (var item in OperationInfoList)
{
item.Dispose();
}
OperationInfoList.Clear();
if (x == -1) return;
if (HubInfoList.Count - 1 < x) return;
var hub = HubInfoList[x];
foreach (var item in hub.Operations)
{
OperationInfoList.Add(new OperationItemViewModel(peer, Log, item));
}
});
// Setup Commands
var photonProcessExists = Observable.Interval(TimeSpan.FromSeconds(1)).Select(x => Process.GetProcessesByName("PhotonSocketserver").Any());
KillPhotonProcess = photonProcessExists.ToReactiveCommand();
KillPhotonProcess.Subscribe(_ =>
{
var processes = Process.GetProcessesByName("PhotonSocketServer");
foreach (var item in processes)
{
item.Kill();
}
});
StartPhotonProcess = ProcessPath.CombineLatest(WorkingDir, (processPath, workingDir) => new { processPath, workingDir })
.Select(x => !string.IsNullOrWhiteSpace(x.processPath + x.workingDir))
.CombineLatest(photonProcessExists, (x, y) => x && !y)
.ToReactiveCommand();
StartPhotonProcess.Subscribe(_ =>
{
try
{
var processPath = ProcessPath.Value;
var workingDir = WorkingDir.Value;
var pi = new ProcessStartInfo
{
FileName = ProcessPath.Value,
Arguments = ProcessArgument.Value,
WorkingDirectory = workingDir
};
System.Diagnostics.Process.Start(pi);
SaveConfiguration(); // can start, save path
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
});
ReloadDll = DllPath.Select(x => File.Exists(x.Trim('\"'))).ToReactiveCommand(ImmediateScheduler.Instance); // needs Immediate check for InitialLoad(see:bottom code)
ReloadDll.Subscribe(_ =>
{
try
{
HubInfoList.Clear();
var hubInfos = HubAnalyzer.LoadHubInfos(DllPath.Value.Trim('\"'));
SaveConfiguration(); // can load, save path
hubInfoLookup = hubInfos.ToDictionary(x => x.HubId);
foreach (var hub in hubInfos)
{
HubInfoList.Add(hub);
}
//.........这里部分代码省略.........
示例10: MainWindowViewModel
/// <summary>
///
/// </summary>
/// <param name="manager"></param>
public MainWindowViewModel(ApplicationManager manager)
{
_manager = manager;
_manager.Error += manager_Error;
_applications = _manager.Applications.ToSyncedSynchronizationContextCollection(x => new ApplicationViewModel(_manager, x), SynchronizationContext.Current);
IsSettingsOpen = new ReactiveProperty<bool>(false);
IsDetailsOpen = new ReactiveProperty<bool>(false);
IsProgressActive = new ReactiveProperty<bool>(false);
ShowWindowRightCommands = IsSettingsOpen.CombineLatest(IsDetailsOpen, (a, b) => !a && !b)
.ToReactiveProperty();
InitialDirectory = _manager.Settings.ToReactivePropertyAsSynchronized(x => x.ApplicationRootDirectoryPath);
ShowHelpCommand = new ReactiveCommand();
ShowHelpCommand.Subscribe(_ => ShowHelp());
RegisterApplicationCommand = IsProgressActive.Select(x => !x).ToReactiveCommand();
RegisterApplicationCommand.Subscribe(_ => RegisterApplication());
InstallApplicationCommand = IsProgressActive.Select(x => !x).ToReactiveCommand();
InstallApplicationCommand.Subscribe(_ => InstallApplication());
OpenSettingCommand = new ReactiveCommand();
OpenSettingCommand.Subscribe(_ => ShowSettings());
ShowDetailsCommand = new ReactiveCommand<ApplicationViewModel>();
ShowDetailsCommand.Subscribe(ShowDetails);
CurrentItem = new ReactiveProperty<ApplicationViewModel>();
SettingsViewModel = new ReactiveProperty<SettingsViewModel>();
}
示例11: FilterViewModelBase
public FilterViewModelBase(FolderReactionModel reactionModel, ReactiveFilterBase filter)
{
ReactionModel = reactionModel;
Filter = filter;
_CompositeDisposable = new CompositeDisposable();
FilterType = Filter.OutputItemType.ToString();
IncludeFilterText = new ReactiveProperty<string>("");
IncludeFilterPatterns = Filter.IncludeFilter
.ToReadOnlyReactiveCollection()
.AddTo(_CompositeDisposable);
ExcludeFilterText = new ReactiveProperty<string>("");
ExcludeFilterPatterns = Filter.ExcludeFilter
.ToReadOnlyReactiveCollection()
.AddTo(_CompositeDisposable);
/*
SampleItems = FolderFilter.ObserveProperty(x => x.FolderFilterPattern)
.Throttle(TimeSpan.FromSeconds(0.25))
.SelectMany(x => FolderFilter.DirectoryFilter(ReactionModel.WorkFolder))
.Select(x => $"/{x.Name}")
.ToReadOnlyReactiveCollection()
.AddTo(_CompositeDisposable);
*/
AddIncludeFilterTextCommand = IncludeFilterText
.Select(x => Filter.IsValidFilterPatternText(x))
.ToReactiveCommand<string>();
AddIncludeFilterTextCommand.Subscribe(AddIncludeFilterText);
AddExcludeFilterTextCommand = ExcludeFilterText
.Select(x => Filter.IsValidFilterPatternText(x))
.ToReactiveCommand<string>();
AddExcludeFilterTextCommand.Subscribe(AddExcludeFilterText);
}