Accessing “current class” from WPF custom MarkupExtension

后端 未结 1 1369
星月不相逢
星月不相逢 2021-01-02 12:37

I\'m attempting to write a custom MarkupExtension to make my life easier by giving me a better way to specify bindings in XAML. However I would like to know if

相关标签:
1条回答
  • 2021-01-02 12:48

    In .NET 4.0, they added the IRootObjectProvider ability, but unfortunately, it isn't 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;
        // do whatever you need to do here
    }
    
    0 讨论(0)
提交回复
热议问题