RoutedViewHost and view regions

330 views
Skip to first unread message

Nikolai Spasov

unread,
Apr 7, 2013, 4:39:31 AM4/7/13
to reacti...@googlegroups.com
I'm working on a small prototype where I try to replace the Prism navigation (RegionManager) with ReactiveUI's Router.
However, the only solution to supporting multiple regions (master-detail view) in my opinion is to define multiple IScreen instances
and bind the 'regions' (RoutedViewHost) to the respective instances.

Am I thinking in the right direction or is there any better way of doing this?

Thanks!

P.S.
A sample CRUD application with master-detail would be nice to have as I'm sure there are a lot of guys out there who do LOB apps.

Paul Betts

unread,
Apr 22, 2013, 11:58:14 PM4/22/13
to ReactiveUI mailing list
Hey Nikolai,


> Am I thinking in the right direction or is there any better way of doing
> this?

Sorry about the late response. You actually don't want to do routing here, you
want to use a control called ViewModelViewHost. It's a ContentControl that you
give a ViewModel, and it will automatically use View Model Location to look up
the correct view for that ViewModel.

So, something like:

class MainViewModel
{
    public ReactiveCollection<ToasterTileViewModel> Toasters { get; protected set; }

    ToasterDetailViewModel _SelectedItem;
    public ToasterDetailViewModel SelectedItem {
        get { return _SelectedItem; }
        set { this.RaiseAndSetIfChanged(ref _SelectedItem, value); }
    }
}

and in the View:

public MainView()
{
    this.OneWayBind(ViewModel, x => x.Toaster, x => x.ToasterListBox.ItemsSource);

    this.WhenAny(x => x.ToasterListBox.SelectedItem, (ToasterTileViewModel)x.Value)
        .Select(x => new ToasterDetailViewModel(x.Model))
        .BindTo(this, x => x.ViewModel.SelectedItem);
}

--
Paul Betts <pa...@paulbetts.org>



--
You received this message because you are subscribed to the Google Groups "ReactiveUI mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactivexaml...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Paul Betts

unread,
Apr 23, 2013, 12:00:19 AM4/23/13
to reacti...@googlegroups.com
Oops, left out a part:

public MainView()
{
this.OneWayBind(ViewModel, x => x.Toaster, x => x.ToasterListBox.ItemsSource);

this.WhenAny(x => x.ToasterListBox.SelectedItem, (ToasterTileViewModel)x.Value)
.Select(x => new ToasterDetailViewModel(x.Model))
.BindTo(this, x => x.ViewModel.SelectedItem);

// DetailView is a ViewModelViewHost
this.OneWayBind(ViewModel, x => x.ViewModel.SelectedItem, x => x.DetailView.ViewModel);
}

--
Paul Betts <pa...@paulbetts.org>
Reply all
Reply to author
Forward
0 new messages