绑定到转换器参数转换器、绑定、参数

2023-09-02 01:48:24 作者:帅有什么用,能当饭吃么

是否可以绑定到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.