I'm using M-V-VM pattern
In my VM I have code like
public class ViewModel {
public XmlDocument Document { ... }
....
}
I have a markup extension from which I would like to use said document
public override object ProvideValue(IServiceProvider serviceProvider) {
IProvideValueTarget valueProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
if (valueProvider != null) {
DependencyObject target = valueProvider.TargetObject as DependencyObject;
XmlDocument doc = Foo.GetDocument(target);
if (doc != null) {
var n = doc.SelectSingleNode("/.../text()");
if (n != null) return n.Value;
}
}
return "«" + ObjectProperty + "»";
}
I have created attached property Foo.Document, and attached it to my Page (the DataContext of the page is set to an instance of my ViewModel class
<Page ... lc:Foo.Document="{Binding Document}">
...
</Page>
(in order to not having to type it as a parameter each and every time I use the markup extension)
Now, in my markup extension when I try to read the Document attached property I always get a null document. By debugging the binding it seeems like a timing issue in that attached property gets proper value after markup extension has been run.
Is is possible to get this to work somehow?