【发布时间】:2011-11-24 15:13:41
【问题描述】:
我们期待的输出是这样的,
<Canvas Width="800" Height="600">
<Ellipse Stroke="#FF000000" StrokeThickness="2" Width="284" Height="288"
ToolTip="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Min}"
Canvas.Left="312" Canvas.Top="122" />
</Canvas>
使用此代码,
//This will ultimately hold object of type UIElement, which is Ellipse in this case.
private DependencyObject selectedObject;
public void AddBinding(DependencyProperty dependencyProperty, DependencyProperty ipartProperty)
{
Binding binding = new Binding(ipartProperty.Name); //Here Name is Min, an attached property
binding.RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent);
BindingOperations.SetBinding(selectedObject, dependencyProperty, binding);
}
但实际输出是
<Canvas Width="800" Height="600">
<Ellipse Stroke="#FF000000" StrokeThickness="2" Width="284" Height="288"
ToolTip="{x:Null}" Canvas.Left="312" Canvas.Top="122"/>
</Canvas>
我不知道怎么回事,请有人帮忙
【问题讨论】:
标签: c# wpf xaml data-binding