Silverlight 中值转换器的拦截

发布于 2024-09-25 04:59:27 字数 246 浏览 0 评论 0原文

一些 UserControl 使用转换器,通常如下所示:

<UserControl.Resources>
    <Converters:CurrentDataConverter x:Key="CurrentDataConverter"/>
</UserControl.Resources>

我想要一个用于拦截转换器的基本用户控件,例如, 使用依赖注入。 有可能吗? 谢谢。

Some UserControl uses converters, which usually look like this:

<UserControl.Resources>
    <Converters:CurrentDataConverter x:Key="CurrentDataConverter"/>
</UserControl.Resources>

I would like to have a base user control for interception of converters, for example,
to use Dependency Injection.
Would it be possible?
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2024-10-02 04:59:27

转换器(或任何资源)可以在 Xaml 层次结构的任何级别声明,因此注入它们的最佳位置是全局应用程序资源集合(最后搜索键)。

在启动过程中的任何时候,您只需将转换器的实例添加为名称/值对,而不是在 Xaml 中声明它们。这意味着您可以完全控制创建并可以使用 IOC 容器来创建它们。

Converters (or any resource) can be declared at any level of the Xaml hierarchy so the best place to inject them is the global App resource collection (which is searched last for keys).

At any tine during startup you just add instances of the converters as name/value pairs, rather than declaring them in Xaml. That means you have full control over creation and can use an IOC container to create them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文