本文介绍了如何使用转换器绑定到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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!