本文介绍了绑定依赖项属性在codebehind WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有XAML code:

 <椭圆X:NAME =节点HEIGHT =10WIDTH =10地图:MapCanvas.Latitude ={结合纬度}图:MapCanvas.Longitude = {结合经度}
                    填写=红行程=红StrokeThickness =1拉伸=制服
                < /椭圆>

 的xmlns:地图=CLR的命名空间:地图控件;装配=地图控件

下面是MapCanvas类的依赖属性:

 公共静态只读的DependencyProperty LatitudeProperty =
        DependencyProperty.RegisterAttached(纵横中的typeof(双),typeof运算(MapCanvas),新PropertyMetadata(double.PositiveInfinity,OnLatitudeLongitudePropertyChanged));
    公共静态只读的DependencyProperty LongitudeProperty =
        DependencyProperty.RegisterAttached(经度的typeof(双),typeof运算(MapCanvas),新PropertyMetadata(double.PositiveInfinity,OnLatitudeLongitudePropertyChanged));

我知道有类似的问题,但我的问题是如何为经度和纬度做比南,仅次于同code就像在XAML code?


解决方案

  node.SetBinding(MapCanvas.LatitudeProperty,新的绑定(纵横));

您可以绑定这样的..

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

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

here is the dependency property in 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 was similar questions but my question is how can I do bining in code behind same like in XAML code for longitude and latitude?

解决方案
node.SetBinding(MapCanvas.LatitudeProperty, new Binding("Latitude"));

You can Bind like this..

这篇关于绑定依赖项属性在codebehind WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 15:23