1
Vote

Improvement Request: MarkupExtension ProvideValue

description

The current implementation just gets the object (context) and property the markup extension is attached to and always returns a value (in some cases a default value). Good for simple or static markup expressions like retuning a static value. Xaml uses a similar way through the obscure IServiceProvider interface (without good examples you are lost). In complex scenarios like deferred data binding Xaml can return a Expression. Xoml uses DeferredProvideValue to simulate that. Both ways have their advantages but none are perfect. In my opinion Expressions are not needed if the MarkupExtension gets improved.
 
1) Move the context object and the property to a new argument of type Xoml.Context, like:
 
public class Context {
  public object TargetObject { get; } // context
  public PropertyInfo TargetProperty { get; } // property
  ...
}
 
2) Remove the return value of ProvideValue. It is not needed because the MarkupExtension can use TargetProperty.SetValue(TargetObject, value, null)
 
3) Remove the out parameter bool defer (see 4 why) and DeferredProvideValue from MarkupExtension.
 
4) Allow the MarkupExtension to access the current loaded object tree (with the posibility to navigate through the tree using a navigator), like
 
public class Context {
  ...
  public ObjectTree ObjectTree{ get; } // see seperate post - coming later
  public ObjectTreeNavigator Current { get; } //the current position in the tree
  ...
}
 
5) Allow the MarkupExtension to attach to the Loaded event of the object tree to defer the value providing, like
 
public class ObjectTree {
  ...
  public event EventHandler Loaded;
  ...
}
 
6) Pass the context starting from XomlLoader to all MarkupExtensions so it it also possible to extend the context, like
 
public class Context {
  ...
  public Dictionary<string, object> ExtensionData { get; }
  ...
}
 
This could be useful to solve static data bindings.

comments

goosefx wrote Jul 27, 2008 at 12:05 PM

To bad that I cannot update my own posted issue. The context / object tree class above is not the final answer, the Loaded event may cause problems if an object is duplicated and added to a different location in the object tree. Also that the property Current returns directly an navigator might be not that elegant. Futher discussion is needed.

wrote Feb 13, 2013 at 8:18 PM