MarkupExtension.ProvideValue - 是否IServiceProvider的实际使用? [英] MarkupExtension.ProvideValue -- Is the IServiceProvider actually used?

查看:336
本文介绍了MarkupExtension.ProvideValue - 是否IServiceProvider的实际使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要通过我的一些旧的代码并在混合的IValueConverter / 的MarkupExtension 类来了。这让我想知道如果的IServiceProvider ProvideValue 方法实际上是有用的,以及它如何将是有益的?



我看到的IServiceProvider 只有一个方法:的GetService ,它必须被转换为合适的服务类型。我又看了看 MarkupExtension.ProvideValue MSDN页面,它列出了不同类型的服务。 ?我想,我只是想知道,或如果有这些服务是有用的,我应该只是离开我的方法,因为它是



当前的方法:

 公共对象ProvideValue(的IServiceProvider的ServiceProvider)
{
返回新MyConverter();
}



基本上,我应该做到以下几点:

 公共对象ProvideValue(的IServiceProvider的ServiceProvider)
{
VAR提供商=的ServiceProvider为SOMETYPE;

如果(供应商== NULL)返回新MyConverter();

//难道这里的供应商的东西吗?
}


解决方案

如果你的的MarkupExtension 工作没有neeeding与的IServiceProvider 任何交互则显然没有什么可以访问它获得。所有的MarkupExtension / ValueConverter 组合我见过,写我自己也属于这一类。



这是实际的事情谈完,如果你只是寻找阅读材料有什么服务提供者可以腾出更多的信息,他们怎么可能有用的这里


I was going through some old code of mine and came across a hybrid IValueConverter / MarkupExtension class. It got me wondering if the IServiceProvider in the ProvideValue method was actually useful, and how it would be useful?

I see that IServiceProvider only has one method: GetService, which must be cast to the proper service type. I also looked at the MarkupExtension.ProvideValue MSDN page and it lists different types of services. I guess, I'm just wondering if any of those services are useful or should I just leave my method as it is?

Current Method:

public Object ProvideValue(IServiceProvider serviceProvider)
{
    return new MyConverter();
}

Basically, should I do the following:

public Object ProvideValue(IServiceProvider serviceProvider)
{
    var provider = serviceProvider as SomeType;

    if (provider == null) return new MyConverter();

    //Do something with the provider here?
}

解决方案

If your MarkupExtension works without neeeding any interaction with the IServiceProvider then obviously there's nothing to be gained from accessing it. All MarkupExtension/ValueConverter combos I 've seen and written myself also fall into this category.

Moving on from practical matters, if you are just looking for reading material there's more information on what services the provider can make available and how they might be useful here.

这篇关于MarkupExtension.ProvideValue - 是否IServiceProvider的实际使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆