Question

I am having an issue with the xaml parser not liking my binding statement but i cannot see anything wrong with the statement.

Invalid attribute value {Binding VehicleSpeed, ConverterParameter={Binding InMiles}, Converter={StaticResource SpeedConverter}, Mode=TwoWay} for property DataMemberBinding

VehicleSpeed and InMiles are parameters on the class that I have in the DataContext property of the xaml top level grid of the xaml document.

This statement used to work without the ConverterParameter by it is now complaining after added the second binding to the "bool InMiles" that i am trying to pass through to the ValueConverter.

If anyone can see anything wrong with this line please let me know.

Was it helpful?

Solution

You cannot bind the converter parameter, because it is not a dependency property of the binding object.

Instead you can pass the whole data item to the converter and use its VehicleSpeed and InMiles properties in the Convert() method.

OTHER TIPS

I'm not sure you can use DataBinding for a Converter Parameter. I think instead you would need to pass in the bound object and access the properties from there.

Blockquote Instead you can pass the whole data item to the converter and use its VehicleSpeed and InMiles properties in the Convert() method. Blockquote

Yes, it is could be right approach, but sometime you have object which is not changed, only properties of that object changed (via INotifyPropertyChanged).

So if you do like this

<Grid DataContext={Binding Model}>
 <MyControl SomeProperty={Binging, converter={staticResourse ConverterWhichTakesViewModel}/>
</Grid>

changes in properties of the Model will not have impact on MyControl, because Model is not changed.

So it would be nice to have do something like this:

<Grid DataContext={Binding Model}>
     <MyControl SomeProperty={Binging Model.MyProperty, converter={staticResourse ConverterWhichTakesViewModel}, ConverterParameter ={Bindging}/>
 </Grid>

But it doesn't work...-(((. Exception: Operation is not valid due to the current state of the object

Any thought on this?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top