在WPF后面的代码中绑定依赖属性

时间:2014-03-14 09:28:26

标签: wpf visual-studio-2010 binding

我有XAML代码:

<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>

和这个

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

这是MapCanvas类中的依赖属性:

    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));

我知道有类似的问题,但我的问题是如何在经典和纬度的XAML代码中对代码进行操作?

1 个答案:

答案 0 :(得分:1)

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

你可以这样绑定..

相关问题