I am using the MV-VM pattern
In my virtual machine, I have code like
public class ViewModel { public XmlDocument Document { ... } .... }
I have a markup extension from which I would like to use the specified 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 created an attached property Foo.Document and attached it to my page (the DataContext of the page is set by an instance of my ViewModel class
<Page ... lc:Foo.Document="{Binding Document}"> ... </Page>
(so as not to enter it as a parameter every time I use the markup extension)
Now, in my markup extension, when I try to read a property attached to a document, I always get a null document. When debugging the binding, he sees that the problem with synchronization is that the attached property gets the correct value after starting the markup extension.
Is it possible to make this work somehow?
source share