Created
May 18, 2012 05:47
-
-
Save anaisbetts/2723425 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| }); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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