我有 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 代码中一样对经度和纬度的代码进行合并?
最佳答案
node.SetBinding(MapCanvas.LatitudeProperty, new Binding("Latitude"));
你可以像这样绑定(bind)..
关于wpf - 在 WPF 后面的代码中绑定(bind)依赖属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22400892/