Stephen Ellis
Stephen Ellis

Reputation: 2711

How to set the default binding converter in Wpf?

I'm moving project from Silverlight to WPF and I've come across a problem.

I have a control with an INotifyPropertyChanged property GeoRect of type GeoRect. GeoRect has a variety of public properties that are set in its constructor each of type IGeoPosition.

I am setting a binding to one of these properties like so:

 <TextBlock Text="{Binding GeoRect.TopRight, ElementName=x_SomeControl}"></TextBlock>

In Silverlight the default ToString method is called on IGeoPosition instance every time the GeoRect property changes. In Wpf I don't get any text at all.

I can correct this in Wpf by adding a ValueConverter to the TextBlock which simply calls the ToString method on the object, but this appears to be unnecessary fat. Can anyone help?

Upvotes: 0

Views: 656

Answers (2)

Vinit Sankhe
Vinit Sankhe

Reputation: 19885

I guess that ElementName=x_SomeControl and GeoRect.TopRight are causing a probable "Source and Path" comination error. Are you sure your x_SomeControl has a property called 'GeoRect'? Also is x_SomeControl.GeoRect not null? And x_SomeControl.GeoRect.TopRight has a correct value?

As HCL pointed out, this will become apparent when you view your Output window where BindingExpression error must have appeared for this binding.

Please check.

Upvotes: 0

HCL
HCL

Reputation: 36775

I suspect that there is another problem in your binding. Also in WPF, data binding calls the ToString() method to build the text of a Text-control.
Have you checked the output window of visual studio for a binding error? Or maybe the GeoRect-class does not support INotifyPropertyChanged for the TopRight property?

Upvotes: 1

Related Questions