c# - Accessing "current class" from WPF custom MarkupExtension -
Trying to write a custom markup extension
to make my life easier by writing me a better The way to specify the binding in XAML, though I would like to know that there is any method, I can use the object that represents the file used in markup extension
.
In other words, suppose that I have UserControl
which defines a particular model of my program's data model. This control has many visual content such as grids, borders, and normal layout if I use my markup extension
on a particular property of an element in this UserControl
It is typed using the example of UserControl
without knowing it (I am planning to use the reflection).
Is this possible?
In .NET 4.0, they added capability, but unfortunately, this is not possible in previous versions . If you are in .NET 4.0, you can do the following:
Public override object ProvideValue (IServiceProvider ServiceProvider) {var rootObjectProvider = serviceProvider.GetService (typeof (IRootObjectProvider)) as IRootObjectProvider; Var root = rootObjectProvider.RootObject; // whatever you need to do}}
Comments
Post a Comment