Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
Created May 18, 2012 05:47
Show Gist options
  • Select an option

  • Save anaisbetts/2723425 to your computer and use it in GitHub Desktop.

Select an option

Save anaisbetts/2723425 to your computer and use it in GitHub Desktop.
using System;
using System.Reactive.Linq;
using Gtk;
using ReactiveUI;
using ReactiveUI.Routing;
namespace GitHub
{
public partial class MainWindow : Gtk.Window, IScreen
{
public IRoutingState Router { get; protected set; }
public MainWindow() : base (Gtk.WindowType.Toplevel)
{
Build();
Router = new RoutingState();
routedviewhost1.Router = Router;
routedviewhost1.Child = new TestView();
Router.Navigate.Execute(new TestViewModel(this)); // This eventually sets routedviewHost.Child to TestView
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
}
}
using System;
using Gtk;
using System.Reactive;
using ReactiveUI;
using ReactiveUI.Routing;
namespace ReactiveUI.Gtk
{
[System.ComponentModel.ToolboxItem(true)]
public class RoutedViewHost : Bin
{
IRoutingState _Router;
public IRoutingState Router {
get { return _Router; }
set {
_Router = value;
updateRouter();
}
}
public Widget DefaultContent { get; set;}
IDisposable currentRouterSub = null;
void updateRouter()
{
if (currentRouterSub != null) {
currentRouterSub.Dispose();
currentRouterSub = null;
}
if (Router == null)
return;
currentRouterSub = Router.ViewModelObservable().Subscribe(vm => {
if (vm == null) {
Child = DefaultContent;
return;
}
var view = RxRouting.ResolveView(vm);
view.ViewModel = vm;
Child = (Widget)view;
});
}
}
}
using System;
using ReactiveUI.Routing;
namespace GitHub
{
[System.ComponentModel.ToolboxItem(true)]
public partial class TestView : Gtk.Bin, IViewForViewModel<TestViewModel>
{
public TestView()
{
this.Build();
}
public TestViewModel ViewModel { get; set; }
object IViewForViewModel.ViewModel {
get { return ViewModel; }
set { ViewModel = (TestViewModel)value; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment