Can I pass my own service via MarkupExtension.ProvideValue's IServiceProvider argument?

365 Views Asked by At

Is it possible - in a WPF, .NET Framework app, to inject my own, user-defined services into the IServiceProvider argument received by MarkupExtension.ProvideValue?

Typically I've made all my value converters derive from Markup Extension merely so I could create them inline in attribute bindings if I desired (instead of declaring them as StaticResource).

Like this:

public class MyConverter : MarkupExtension, IValueConverter
{
    public override object ProvideValue(IServiceProvider serviceProvider) => this;

    //  (IValueConverter implementation here... blah blah blah...)

I've never used that IServiceProvider argument but there it is, already available to me. The documentation talks about built-in services I can use there. But is there any way to register my own services sometime when my application starts so that my markup extension could then retrieve them?

(I already realize I can use MultiBindings, I'm just trying to understand if I can avoid them in some cases)

0

There are 0 best solutions below