This project is read-only.

Project Description
I am experimenting with a way to merge behavior into a model to create a dynamic ViewModel. I am hoping to be able to autowireup commands, and track dependencies.


Currently, the project demonstrates a way to define behavior in a class that derives from BehaviorInjector<DataClassType>. The behavior will expose additional Properties, DependentProperties, and commands, with a constructor that takes a DataClassType the BehaviorInjector has a dynamic ViewModel property that can be used as the dataContext of a WPF view.

In order for the dependency tracking to work in the behavior class, you need to reference all properties of the DataClass, and BehaviorClass using the viewmodel:

 

        public string NameAgeSerialNumber
        {
            get
            {
                return string.Format("{0} - Age: {1} - {2}", ViewModel.Name, ViewModel.Age, DateTime.Now.Millisecond);
            }
        }
 

 

The problem with this is that while you get automatic dependency tracking, you lose design time intellisense.  I have been trying to find a way to expose the best of both worlds, but I think the dependency tracking is cooler than the intellisense, and perhaps there is a way to intoduce a pre-compile helper that can edit the code on compile to switch DataClass, or BehaviorClass references to ViewModel as the ViewModel will contain identically named properties and methods....  If anyone has any ideas for this, I'd love to hear them.

Also, the current implementation uses a constructor to get the dataclass into the behavior, I think I will change this to also include an extension method so it can easily support multiple behaviors:  something like this:

 

var behavior = DataClass.AttachBehavior(Behavior1).AttachBehavior(Behavior2).AttachBehavior(Behavior3)

view.DataContext = behavior.ViewModel;

Also, I am thinking about having a re-map function that can take a changed DataClass (perhaps from a server callback) and remap it to the behaviors automatically, but I don't really know how this would play out yet.

Of course, since I only have 12 days to publish I figure I will leave that for later.

I would love to hear comments or criticisms about this project.  I don't recommend using it in any sort of production environment as I don't really know how it will perform, it may perform really badly.

 

Last edited Apr 1, 2011 at 3:52 PM by LanceWynn, version 4