本文整理汇总了C#中Operation.ToReactivePropertyAsSynchronized方法的典型用法代码示例。如果您正苦于以下问题:C# Operation.ToReactivePropertyAsSynchronized方法的具体用法?C# Operation.ToReactivePropertyAsSynchronized怎么用?C# Operation.ToReactivePropertyAsSynchronized使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Operation
的用法示例。
在下文中一共展示了Operation.ToReactivePropertyAsSynchronized方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainWindowViewModel
public MainWindowViewModel()
{
Op = new Operation(
//new MockWorker() ??
//new NetshWorker() ??
new NativeWifiWorker() as IWlanWorker);
this.Profiles = Op.Profiles.ToReadOnlyReactiveCollection(x => new ProfileItemViewModel(x));
#region AutoReloadEnabled/Suspended/ConfigMode
IsAutoReloadEnabled = Op
.ToReactivePropertyAsSynchronized(x => x.IsAutoReloadEnabled);
IsSuspended = Op
.ToReactivePropertyAsSynchronized(x => x.IsSuspended);
IsConfigMode = new ReactiveProperty<bool>();
IsAutoReloadEnabled
.Merge(IsSuspended)
.Where(x => x)
.Subscribe(_ => IsConfigMode.Value = false);
IsConfigMode
.Where(x => x)
.Subscribe(_ => IsAutoReloadEnabled.Value = false);
#endregion
#region Load
IsLoading = Op.IsLoading
.Where(_ => !Op.IsWorking.Value)
//.Select(x => Observable.Empty<bool>()
// .Delay(TimeSpan.FromMilliseconds(10))
// .StartWith(x))
//.Concat()
.ObserveOnUIDispatcher()
.ToReadOnlyReactiveProperty();
ReloadCommand = IsLoading
.Select(x => !x)
.ToReactiveCommand();
ReloadCommand
.Subscribe(async _ => await Op.LoadProfilesAsync(true));
Profiles
.ObserveElementObservableProperty(x => x.Position)
.Throttle(TimeSpan.FromMilliseconds(10))
.ObserveOn(SynchronizationContext.Current)
.Subscribe(_ => ProfilesView.Refresh()); // ListCollectionView.Refresh method seems not thread-safe.
#endregion
#region Work
IsNotWorking = Op.IsWorking
.Select(x => !x)
.StartWith(true) // This is necessary for initial query.
.ObserveOnUIDispatcher()
.ToReadOnlyReactiveProperty();
// Query for a profile which is selected.
var querySelectedProfiles = Profiles
.ObserveElementObservableProperty(x => x.IsSelected)
.Where(x => x.Value)
.Select(x => x.Instance)
.Publish();
// Query for the selected profile which is connected or disconnected.
var queryConnectedProfiles = Profiles
.ObserveElementObservableProperty(x => x.IsConnected)
.Where(x => x.Instance.IsSelected.Value)
.Select(x => x.Instance)
.Publish();
// Query for the selected profile which changes to be available or unavailable.
var queryAvailableProfiles = Profiles
.ObserveElementObservableProperty(x => x.IsAvailable)
.Where(x => x.Instance.IsSelected.Value)
.Select(x => x.Instance)
.Publish();
#region MoveUp
var queryMoveUp = querySelectedProfiles
.Select(x => x.Position.Value > 0);
MoveUpCommand = new[] { IsNotWorking, queryMoveUp }
.CombineLatestValuesAreAllTrue()
.ToReactiveCommand();
MoveUpCommand
.Subscribe(async _ => await Op.MoveUpProfileAsync());
#endregion
#region MoveDown
var queryMoveDown = querySelectedProfiles
//.........这里部分代码省略.........