Request For Change: Change ModelManager to inherit from FrameworkElement (instead of DependencyObject)

Developer
Nov 20, 2010 at 7:11 AM

I'm able to implement a useful of UI Composition pattern, but have found I'm unable to set bindings on properties for the ModelManager class. This is easily resolved by changing the base class that ModelManager inherits from to a FrameworkElement which includes the neccesary SetBinding methods.

Therefore I would like to propose changing the base class for Bxf.ModelManager:

Current:

  /// <summary>
  /// Manages a model or viewmodel object, wrapping it
  /// for access through a XAML resource dictionary.
  /// </summary>
  public class ModelManager : DependencyObject
  { ... }

Proposed:

  /// <summary>
  /// Manages a model or viewmodel object, wrapping it
  /// for access through a XAML resource dictionary.
  /// </summary>
  public class ModelManager : FrameworkElement
  { ... }

NB: Rocky, I'd be happy to make the change and check it in, provided you agree with the change.

Regards,
Jaans

Coordinator
Nov 20, 2010 at 11:49 PM

Really? Usually DependencyObject is sufficient to support binding scenarios (which is why I chose it). But if it isn't sufficient, then the change is fine. The whole point of this type is to provide a meaningful alternative to CollectionViewSource for a single object instead of a list.

Developer
Nov 21, 2010 at 12:19 AM

Yep, you are right... DependencyObject is sufficient enough for binding to use it as a source, but if the target element is to be the ModelManager itself, then it must be a FrameworkElement.

Normally the Data property of the Model Manager is set via code, but as mentioned, I have a composisition scenario whereby I actually use binding to set the Data property.Usually your UI Controls (like TextBlock, Button, etc.) are the target elements in binding, but in the scenario I'm describing the ModelManager is actually the target and it uses the "parent" composisition container as the source.

The Model Manager turns out to be a very handy alternative to CVS is is just so combersome and overkill when the usercontrol is dealing with a single item. I believe it's much more efficient, and the d:DesignInstance attached properties work great to enable the VS Designer to build data binding expressions.