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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With