Using Bxf with Silverlight navigation

Coordinator
Aug 10, 2010 at 7:11 PM
Edited Aug 10, 2010 at 7:14 PM

Jav:

My App is structured almost exactly like the very first SlDemo from the Mvvm Videos, i.e., a central are for main navigable content with ouside fixed areas for buttons etc.  I use SL Navigation.

I hear in the video that the main reason to use Mvvm pattern is to make testing easier and to eliminate code behind - and I buy that.  My venture into MvvM, however, was the result of Detour sign on the highway that said:  DataProviders permanatly closed - Use MvvM - Turn Left Here.

I have been thankful for the ViewModel availability and have been speeding along, displaying contect in a Frame using Silverlight Navigation system, and everything's been sweet. 

Now in the MvvM videos, all I hear about is the MainContent Presenter and a View Changer, with no mention of Csla Navigation which was there  at one time, nor of the SL navigation which essentially replaced Csla navigation.  So before I do something stupid and start dismantling my SL Navigation, I have some questions.

1.  Is this meant to be a replacement for the existing Navigation System, and would it present comparable functionality like pressing the Back key to go to a previous view, or seeing a list of all previous views in a dropdown list from Browser's Backup funtionality - and whatever else may be there.

2. If I want to stay with SL navigation, what are the caveats in creating VM's for all child objects (and collections of child objects) of my object graph, many of them are lazy-loaded and what would be the best place to plug in that functionality, i.e., creation of the VM for the newly created collection or the object.  I did study the code in SlDemo videos but the examples appear to tie it into Shell.Instance.ShowView()?

3.  Can I use the Bxf's Status and Error display functionalty while continuing to use SL navigation.  In fact the only status I need to display outside the navigation frame is the IsValid status of each object in the object graph - and that is on the wish list.

Thank you.

Jav

====================================

Rocky:

Bxf is, fist and foremost, a teaching tool intended to distill MVVM to the smallest possible implementation. So it doesn't integrate with the back button or anything like that, no.

Of course Bxf is an open source framework - I'm very happy to have people contribute to the project. I don't want it to get big or complex - no sense competing with pre-existing MVVM frameworks out there - but there's certainly room to enhance the framework while keeping it extremely lightweight and simple.

All that said, I suspect it can work with SL navigation with little or no change.

Bxf requires that you implement a "presenter" that is responsible for handling the three events (to show a view, error and status). You can implement those three behaviors any way you choose - including having OnShowView call SL navigation to navigate to a new view.

On the flip side, SL navigation (I think) has ways for you to run initialization code as a new page is initialized. Sadly I haven't had time to dig into SL navigation as much as I'd like... But this is one area where Bxf might need a little enhancement - since it may not be possible for this navigation initialization code to call Bxf to hook up the viewmodel to the view.

I assume SL navigation will create the view, and thus any CollectionViewSource resources, etc. Something then needs to create the viewmodel (based on the query parameter data) and hook up the viewmodel to the view.

However, InitializeBindingResource() is a protected method, so it might be as simple as creating a custom subclass of Shell that exposes a method to create an IView with a pre-existing view (the one created by SL navigation) and the viewmodel you create based on the query parameters - and then this Shell subclass would invoke InitializeBindingResource() to connect the viewmodel to the view.

Aug 10, 2010 at 11:00 PM

Rocky,

Thanks for your suggestions.

I took a quick look at the InitializeBindingResource() and the two ShowView methods.  It looks promising.  Will report back when I have some success.

Right now I have the following method in App.xaml

        public static void Navigate(UserControl newPage)
        {
            App currentApp = (App)Application.Current;
            currentApp.rootGrid.Children.Clear();
            currentApp.rootGrid.Children.Add(newPage);
        }

My Navigation region is a frame comtrol called mainframe.  In a Button.Click, I do:

        mainFrame.Navigate(new Uri("/MyPageToDisplay.xaml", UriKind.Relative))

Jav

Nov 16, 2010 at 11:38 PM

Anyone made any progress on this?

Coordinator
Nov 17, 2010 at 12:10 AM

The current Bxf release includes a sample that uses Silverlight navigation and demonstrates how to integrate Bxf into that model, while maintaining things like direct/deep linking of URLs, etc.