将 IValueConverter 与 DynamicResource 一起使用? [英] Use IValueConverter with DynamicResource?

查看:23
本文介绍了将 IValueConverter 与 DynamicResource 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 DynamicResource 扩展时,有没有办法定义转换器?

Is there a way to define a converter when using the DynamicResource extension? Something in the lines of

<RowDefinition Height="{Binding Source={DynamicResource someHeight}, Converter={StaticResource gridLengthConverter}}" />

不幸的是,这给了我以下异常:

which unfortunately gives me the following excpetion:

DynamicResourceExtension"不能是在类型的源"属性上设置'捆绑'.一个'DynamicResourceExtension' 只能是在一个 DependencyProperty 上设置依赖对象.

A 'DynamicResourceExtension' cannot be set on the 'Source' property of type 'Binding'. A 'DynamicResourceExtension' can only be set on a DependencyProperty of a DependencyObject.

推荐答案

我知道我真的迟到了,但绝对有效的是使用 BindingProxy 像这样的动态资源

I know i am really late to this but what definitely works is using a BindingProxy for the DynamicResource like this

<my:BindingProxy x:Key="someHeightProxy" Data="{DynamicResource someHeight}" />

然后将转换器应用到代理

Then applying the converter to the proxy

<RowDefinition Height="{Binding Source={StaticResource someHeightProxy}, Path=Data, Converter={StaticResource gridLengthConverter}}" />

这篇关于将 IValueConverter 与 DynamicResource 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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