Skip to content

Commit

Permalink
Add a default for WinRT that follows around the snapped/unsnapped state
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed May 19, 2013
1 parent b49893d commit 6a8df45
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
28 changes: 18 additions & 10 deletions ReactiveUI.Platforms/Xaml/RoutedViewHost.cs
Expand Up @@ -63,23 +63,31 @@ public RoutedViewHost()

if (RxApp.InUnitTestRunner()) return;

#if WINRT
ViewContractObservable = Observable.FromEventPattern<SizeChangedEventHandler, SizeChangedEventArgs>(x => SizeChanged += x, x => SizeChanged -= x)
.Select(_ => Windows.UI.ViewManagement.ApplicationView.Value)
.DistinctUntilChanged()
.StartWith(Windows.UI.ViewManagement.ApplicationView.Value))
.Select(x => x.ToString());
#endif

var vmAndContract = Observable.CombineLatest(
this.WhenAny(x => x.Router, x => x.Value)
.Select(x => x.ViewModelObservable()).Switch(),
this.WhenAnyObservable(x => x.ViewContractObservable),
(vm, contract) => new { ViewModel = vm, Contract = contract, });

vmAndContract.Subscribe(x => {
if (x.ViewModel == null) {
Content = DefaultContent;
return;
}
if (x.ViewModel == null) {
Content = DefaultContent;
return;
}
var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
var view = viewLocator.ResolveView(x.ViewModel, x.Contract);
view.ViewModel = x.ViewModel;
Content = view;
}, ex => RxApp.DefaultExceptionHandler.OnNext(ex));
var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
var view = viewLocator.ResolveView(x.ViewModel, x.Contract);
view.ViewModel = x.ViewModel;
Content = view;
}, ex => RxApp.DefaultExceptionHandler.OnNext(ex));
}
}
}
8 changes: 8 additions & 0 deletions ReactiveUI.Platforms/Xaml/ViewModelViewHost.cs
Expand Up @@ -59,6 +59,14 @@ public ViewModelViewHost()
this.WhenAnyObservable(x => x.ViewContractObservable),
(vm, contract) => new { ViewModel = vm, Contract = contract, });

#if WINRT
ViewContractObservable = Observable.FromEventPattern<SizeChangedEventHandler, SizeChangedEventArgs>(x => SizeChanged += x, x => SizeChanged -= x)
.Select(_ => Windows.UI.ViewManagement.ApplicationView.Value)
.DistinctUntilChanged()
.StartWith(Windows.UI.ViewManagement.ApplicationView.Value))
.Select(x => x.ToString());
#endif

vmAndContract.Subscribe(x => {
if (x.ViewModel == null) {
Content = DefaultContent;
Expand Down

0 comments on commit 6a8df45

Please sign in to comment.