Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding to Converter Parameter

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}}" /> 
like image 357
dparker Avatar asked Dec 08 '10 14:12

dparker


2 Answers

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.

like image 112
Joe McBride Avatar answered Sep 22 '22 02:09

Joe McBride


Another option is to get fancy by creating a custom converter that wraps your other converter and passes in a converter param from a property. As long as this custom converter inherits DependencyObject and uses a DependencyProperty, it can be bound to. For example:

<c:ConverterParamHelper ConverterParam="{Binding ...}">      <c:ConverterParamHelper.Converter>          <c:RealConverter/>      </c:ConverterParamHelper.Converter>  </c:ConverterParamHelper> 
like image 33
Tim Greenfield Avatar answered Sep 24 '22 02:09

Tim Greenfield