wpf 如何传递 IValueConverter 参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37459122/
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 Pass IValueConverter Parameter?
提问by MVK
回答by Matas
You have ConverterParameterinside your binding, where you can use another binding with ElementNameof your grid.
您有ConverterParameter内部绑定,您可以在其中使用ElementName网格的另一个绑定。
<Grid Name="MainGrid3"></Grid>
<TextBlock Text="{Binding SomeBinding, Converter={StaticResource SomeConverter}, ConverterParameter={Binding ElementName=MainGrid3}}"></TextBlock>
Edit:Ok, so apparently I was wrong, you can't use bindings inside ConverterParameter as it is not a dependency property. Working solution would be to use x:Referencelike so:
编辑:好的,显然我错了,您不能在 ConverterParameter 中使用绑定,因为它不是依赖属性。工作解决方案是这样使用x:Reference:
<Grid Name="MainGrid3"></Grid>
<TextBlock Text="{Binding SomeBinding, Converter={StaticResource SomeConverter}, ConverterParameter={x:Reference Name=MainGrid3}}"></TextBlock>


