开发者

Having an issue with CoverterParameter Binding in silverlight

开发者 https://www.devze.com 2022-12-18 05:40 出处:网络
I am having an issue with the xaml parser not liking my binding statement but i cannot see anything wrong with the statement.

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 p开发者_StackOverflow中文版ass through to the ValueConverter.

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


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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消