Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 983337463c
Fetching contributors…

Cannot retrieve contributors at this time

72 lines (63 sloc) 2.509 kb
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Windows;
using ReactiveUI;
using ReactiveUI.Xaml;
#if WINRT
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
#else
using System.Windows.Controls;
#endif
namespace ReactiveUI.Routing
{
/// <summary>
/// This control hosts the View associated with a Router, and will display
/// the View and wire up the ViewModel whenever a new ViewModel is
/// navigated to. Put this control as the only control in your Window.
/// </summary>
public class RoutedViewHost : TransitioningContentControl
{
IDisposable _inner = null;
/// <summary>
/// The Router associated with this View Host.
/// </summary>
public IRoutingState Router {
get { return (IRoutingState)GetValue(RouterProperty); }
set { SetValue(RouterProperty, value); }
}
public static readonly DependencyProperty RouterProperty =
DependencyProperty.Register("Router", typeof(IRoutingState), typeof(RoutedViewHost), new PropertyMetadata(null));
/// <summary>
/// This content is displayed whenever there is no page currently
/// routed.
/// </summary>
public object DefaultContent {
get { return (object)GetValue(DefaultContentProperty); }
set { SetValue(DefaultContentProperty, value); }
}
public static readonly DependencyProperty DefaultContentProperty =
DependencyProperty.Register("DefaultContent", typeof(object), typeof(RoutedViewHost), new PropertyMetadata(null));
public RoutedViewHost()
{
HorizontalContentAlignment = HorizontalAlignment.Stretch;
VerticalContentAlignment = VerticalAlignment.Stretch;
if (RxApp.InUnitTestRunner()) return;
this.WhenAny(x => x.Router.NavigationStack, x => x.Value)
.SelectMany(x => x.CollectionCountChanged.StartWith(x.Count).Select(_ => x.LastOrDefault()))
.Subscribe(vm => {
if (vm == null) {
Content = DefaultContent;
return;
}
var view = RxRouting.ResolveView(vm);
view.ViewModel = vm;
Content = view;
}, ex => RxApp.DefaultExceptionHandler.OnNext(ex));
}
}
}
Jump to Line
Something went wrong with that request. Please try again.