Bind binding property in codebehind WPF

I have XAML code:

<Ellipse x:Name="node" Height="10" Width="10" map:MapCanvas.Latitude="{Binding Latitude}" map:MapCanvas.Longitude="{Binding Longitude}"
                    Fill="Red" Stroke="Red" StrokeThickness="1" Stretch="Uniform" 
                </Ellipse>

      

and this one

xmlns:map="clr-namespace:MapControl;assembly=MapControl"

      

here is the dependency property in the MapCanvas class:

    public static readonly DependencyProperty LatitudeProperty =
        DependencyProperty.RegisterAttached("Latitude", typeof(double), typeof(MapCanvas), new PropertyMetadata(double.PositiveInfinity, OnLatitudeLongitudePropertyChanged));


    public static readonly DependencyProperty LongitudeProperty =
        DependencyProperty.RegisterAttached("Longitude", typeof(double), typeof(MapCanvas), new PropertyMetadata(double.PositiveInfinity, OnLatitudeLongitudePropertyChanged));

      

I know there have been similar questions, but my question is, how can I make the code in code look like XAML for longitude and latitude?

+2


source to share


1 answer


node.SetBinding(MapCanvas.LatitudeProperty, new Binding("Latitude"));

      



You can bind like this ..

+1


source







All Articles