如何使用转换器绑定到StaticResource? [英] How to bind to a StaticResource with a Converter?

查看:166
本文介绍了如何使用转换器绑定到StaticResource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Converter来更改StaticResource的值,然后再将其分配给属性.有没有一种模拟Binding的方法,它将在转换后仅设置StaticResource的值?

I want to use a Converter to change the value of a StaticResource before assigning it to a property. Is there a way to simulate a Binding that will just set the value of the StaticResource after converting it?

{Binding Value={StaticResource myStatic}, Converter={StaticResource myConverter}}一样?

推荐答案

这有效:

<TextBox Text="{Binding Source={StaticResource myStatic}, 
                        Converter={StaticResource myConverter},
                        Mode=OneWay}" />

请注意,您必须以一种方式进行绑定,因为绑定需要使用path属性.这是有道理的,因为否则绑定将不得不替换整个资源...

Note that you have to bind one way, because the binding requires a path attribute otherwise. This makes sense, as otherwise the binding would have to replace the whole resource...

这篇关于如何使用转换器绑定到StaticResource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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