wpf 如何使用转换器绑定到静态资源?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16623343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to bind to a StaticResource with a Converter?
提问by Ignacio Soler Garcia
I want to use a Converterto change the value of a StaticResourcebefore assigning it to a property. Is there a way to simulate a Bindingthat will just set the value of the StaticResourceafter converting it?
我想在将ConverteraStaticResource分配给属性之前使用 a更改 a 的值。有没有办法模拟 a在转换后Binding只设置它的值StaticResource?
Something like {Binding Value={StaticResource myStatic}, Converter={StaticResource myConverter}}?
像{Binding Value={StaticResource myStatic}, Converter={StaticResource myConverter}}什么?
回答by Marc
This works:
这有效:
<TextBox Text="{Binding Source={StaticResource myStatic},
Converter={StaticResource myConverter},
Mode=OneWay}" />
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...
请注意,您必须以一种方式绑定,否则绑定需要一个路径属性。这是有道理的,否则绑定将不得不替换整个资源......

