DiamonDogX

I have a MapObject class with a Location (attached property):

Code Snippet

public static readonly DependencyProperty LocationProperty =

DependencyProperty.RegisterAttached("Location", typeof(LatLonAlt), typeof(MapObject));

public static void SetLocation(DependencyObject element, LatLonAlt value)

{

element.SetValue(LocationProperty, value);

SetLastUpdate(element, DateTime.UtcNow);

}

public static LatLonAlt GetLocation(DependencyObject element)

{

return (LatLonAlt)element.GetValue(LocationProperty);

}

I have a data template in which I'm trying to bind to the attached property:

Code Snippet

<DataTemplate x:Key="MapObjectToolTipDataTemplate" DataType="{x:Type map:MapObject}">

<TextBlock Text="{Binding Path=(map:MapObject.Location.Latitude)}"

...

...

I'm getting an invalid property path error:

'Path' to object of type 'System.Windows.PropertyPath'. Property path is not valid. Cannot resolve type name 'map:MapObject.Location

It SEEMS the problem has to do with the fact that Location is the dependency property, but it has a subtype of Latitude which is of type double. But I don't quite see why it is having a problem with this. Does EVERY part of the path have to be an attached property



Re: Windows Presentation Foundation (WPF) Invalid property path when binding to attached property

Josh Smith

Try:

Code Snippet

Path=(map:MapObject.Location).Latitude






Re: Windows Presentation Foundation (WPF) Invalid property path when binding to attached property

DiamonDogX

Genius! Many thanks!





Re: Windows Presentation Foundation (WPF) Invalid property path when binding to attached property

DiamonDogX

When trying to use a converter (converting double to string)

Code Snippet

{Binding Path=(map:MapObject.Location).Latitude, Converter=latLonDoubleToStringConverter}

Code Snippet

ValueConversion( typeof( double ), typeof( string ) )]

public class LatLonDoubleToStringConverter : IValueConverter

{

public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )

{

...

...

...

I get an error: 'IValueConverter' type does not have a public TypeConverter class.

No experience with TypeConverters... thought this converter would work find since it's simply a double to string conversion...





Re: Windows Presentation Foundation (WPF) Invalid property path when binding to attached property

Josh Smith

This

Code Snippet

Converter=latLongDoubleToStringConverter

does not make any sense. You probably mean this

Code Snippet

Converter={StaticResource latLongDoubleToStringConverter}

where the converter instance is stored in a resource dictionary somewhere.






Re: Windows Presentation Foundation (WPF) Invalid property path when binding to attached property

DiamonDogX

Apologize... stupid mistake