绑定到转换器参数 [英] Binding to Converter Parameter

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

问题描述

是否可以绑定到ConverterParameter在Silverlight 4.0?

比如我希望做这样的事情,并绑定ConverterParameter到对象的视图模型的实例。

如果无法做到这一点还有没有其他选择?

 <单选按钮
  内容={绑定路径=方式}
  =器isChecked{结合
    转换器= {的StaticResource ParameterModeToBoolConverter},
    ConverterParameter = {绑定路径= DataContext.SelectedMode,的ElementName =根}}
/>
 

解决方案

偏偏不,你不能绑定到一个ConverterParameter。还有我用过去两个选项:而不是使用一个转换器,在您的视图模型(或任何你绑定)来完成转换为您创建一个属性。如果你还是想要去的转换路径,传递整个绑定的对象的转换器,然后你可以做你计算的方式。

Is it possible to bind to a ConverterParameter in Silverlight 4.0?

For instance I would like to do something like this and bind the ConverterParameter to an object in a ViewModel for instance.

If this is not possible are there any other options?

<RadioButton
  Content="{Binding Path=Mode}"
  IsChecked="{Binding
    Converter={StaticResource ParameterModeToBoolConverter},
    ConverterParameter={Binding Path=DataContext.SelectedMode,ElementName=root}}"
/>

解决方案

Unfortunetly no, you can't bind to a ConverterParameter. There's two options I've used in the past: instead of using a Converter, create a property on your ViewModel (or whatever you're binding to) which does the conversion for you. If you still want to go the Converter route, pass the entire bound object to the converter and then you can do your calculation that way.

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

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