WPF frameworks

40 views
Skip to first unread message

Paul Stovell

unread,
Nov 9, 2009, 12:43:09 AM11/9/09
to wpf-di...@googlegroups.com
Hi all,

I'm trying to gather up a list of WPF MVVM, MVP, MVC and related frameworks. I know of:
I think at least 50% of everyone on this list has written an MVVM framework ;) - but I am sure there are more.

My goal is to demonstrate how/whether Magellan can work with each of them. Did I miss any?

--
Paul Stovell

Karl Shifflett

unread,
Nov 9, 2009, 1:48:18 AM11/9/09
to wpf-di...@googlegroups.com

Paul,

 

I have a v2 coming out this week.  I added more features to my demo app today. 

 

Had to take care of my Rita’s Services.

 

Karl

Sacha Barber

unread,
Nov 9, 2009, 3:42:51 AM11/9/09
to wpf-di...@googlegroups.com
Looks pretty complete to me. Though the chap that did nRoute is now doing MVVM framework. You may want look at his too, Mike Brown seems to know where it is.
--
Sacha Barber
sacha....@gmail.com

Peter O'Hanlon

unread,
Nov 9, 2009, 3:52:58 AM11/9/09
to wpf-di...@googlegroups.com
Paul
 
I've got one called Goldlight that I'm currently working on.
Pete
On Mon, Nov 9, 2009 at 5:43 AM, Paul Stovell <pa...@paulstovell.com> wrote:



--
Peter O'Hanlon

Mark Smith

unread,
Nov 9, 2009, 8:52:55 AM11/9/09
to wpf-di...@googlegroups.com
I have one as well -- the next version will be released sometime this week, it will be at:


but right now, the link is still from my blog:

You can also scan the WPF disciples page - it has a full list that was recently updated -- I think you have most though.

Glenn Block

unread,
Nov 9, 2009, 11:06:13 AM11/9/09
to wpf-di...@googlegroups.com
I am working on one, but it's not out there yet.

--
Sent from my mobile device

Paul Stovell

unread,
Nov 9, 2009, 7:48:58 PM11/9/09
to wpf-di...@googlegroups.com
Hi Mark,

This one will be interesting to make work.

Magellan controllers are typically written like this:

public ActionResult Get(int customerId)
{
    Model = GetCustomer(customerId);
    return View();
}

Magellan instantiates the view, and also sets the view's data context to the model.

However, your MVVM framework uses a markup extension to connect events on the VM to closing and activating the window. Your extension does two things - it instantiates the model, and it connects it to the window.

The workaround for me would be to write a custom View Engine that when opening a Window, instead of setting the datacontext directly, it uses your markup extension to set it. The problem there is your markup extension wants to create the VM - I can't just give it the one from the controller.

I can probably take some of the code from the markup extension that does the wiring up for the window and just replicate it in the custom Magellan view engine. It would look something like this:

    public class JulmarWindowViewEngine : UIElementViewEngine
    {
        private readonly IViewActivator _viewActivator;

        public JulmarWindowViewEngine(IViewActivator viewActivator) : base("", "View", "Window", "Dialog", "ViewWindow", "ViewDialog")
        {
            _viewActivator = viewActivator;
        }

        protected override IEnumerable<Type> FilterCandidateTypes(ControllerContext controllerContext, ParameterValueDictionary viewParameters, string viewName, IEnumerable<Type> candidates)
        {
            return candidates.Where(type => typeof (Window).IsAssignableFrom(type));
        }

        protected override ViewEngineResult CreateViewResult(ControllerContext controllerContext, ParameterValueDictionary viewParameters, Type type)
        {
            return new JulmarWindowViewEngineResult(controllerContext, viewParameters, type, _viewActivator);
        }
    }

    public class JulmarWindowViewEngineResult : ViewEngineResult
    {
        private readonly ControllerContext _controllerContext;
        private readonly ParameterValueDictionary _viewParameters;
        private readonly Type _viewType;
        private readonly IViewActivator _viewActivator;

        public WindowViewEngineResult(ControllerContext controllerContext, ParameterValueDictionary viewParameters, Type viewType, IViewActivator viewActivator)
            : base(true, new string[0])
        {
            _controllerContext = controllerContext;
            _viewParameters = viewParameters;
            _viewType = viewType;
            _viewActivator = viewActivator;
        }

        public override void Render()
        {
            var instance = (Window)_viewActivator.Instantiate(_viewType);
            if (_viewParameters.ContainsKey("Model"))
            {
                var model = _viewParameters["Model"];
                if (instance is IView) ((IView)instance).Model = model;
                else instance.DataContext = model;

                // Copied and pasted from ViewModelCreatorExtension.cs
                var jvm = model as JulMar.Windows.Mvvm.ViewModel;

                if (jvm != null)
                {
                    jvm.CloseRequest += ((s, e) =>
                         {
                             try
                             {
                                 winTarget.DialogResult = e.Result;
                             }
                             catch (InvalidOperationException)
                             {
                                 // Raised if this was displayed via Show() vs. ShowDialog
                                 winTarget.Close();
                             }
                         });
                    jvm.ActivateRequest += ((s, e) => winTarget.Activate());
                }
            }
          
            instance.Show();
        }
    }

It's a shame to have to replicate this code though. What do you think?

Paul
--
Paul Stovell

Paul Stovell

unread,
Nov 9, 2009, 7:54:30 PM11/9/09
to wpf-di...@googlegroups.com
Hi Peter,

Goldlight+Magellan (MVVM+MVC) should just work out of the box, which is nice. The only possible issue is that in MVC, the controller typically creates the model. But in Goldlight, at least in the sample application, I see you are declaring the VM as a XAML resource dictionary entry instead. How critical do you think it is for the VM to be created by the XAML?

Paul
--
Paul Stovell

Mark Smith

unread,
Nov 9, 2009, 11:51:55 PM11/9/09
to wpf-di...@googlegroups.com
Hi Paul,

It doesn't actually require the markup extension -- that was more for convenience to wire up some events that are nice to have.  You can simply associate the DataContext (either in code behind or XAML) and everything except the close and activate request should work.  Most of the time I don't need it on the main window -- it's child windows where it gets really convenient so you know when the view is closed to return info to the original caller.  That said, your solution would work - but I wonder if there is a way to share that code without copying it.. I'll have to think on that some.

mark

Peter O'Hanlon

unread,
Nov 10, 2009, 3:32:48 AM11/10/09
to wpf-di...@googlegroups.com
Paul
 
It's not critical at all - it's just a habit that I have developed over the last 18 months or so as I like to try and avoid all code in the code behind where possible. There's no real reason that the controller couldn't do this instead. It's good that it should just work.

--
Peter O'Hanlon
Reply all
Reply to author
Forward
0 new messages