如何传递 IValueConverter 参数? [英] How to Pass IValueConverter Parameter?

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

问题描述

在XAML中,,这里我想把MainGrid3作为IValueConverter.我该怎么做?

In XAML, <Grid x:Name="MainGrid3">, Here I want to pass MainGrid3 as a parameter of IValueConverter. How can I do this?

推荐答案

您的绑定中有 ConverterParameter,您可以在其中使用另一个绑定与网格的 ElementName.

You have ConverterParameter inside your binding, where you can use another binding with ElementName of your grid.

<Grid Name="MainGrid3"></Grid>
<TextBlock Text="{Binding SomeBinding, Converter={StaticResource SomeConverter}, 
           ConverterParameter={Binding ElementName=MainGrid3}}"></TextBlock>

好吧,显然我错了,您不能在 ConverterParameter 中使用绑定,因为它不是依赖属性.可行的解决方案是像这样使用 x:Reference :

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:Reference like so:

<Grid Name="MainGrid3"></Grid>
<TextBlock Text="{Binding SomeBinding, Converter={StaticResource SomeConverter}, 
           ConverterParameter={x:Reference Name=MainGrid3}}"></TextBlock>

这篇关于如何传递 IValueConverter 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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