输出“米期待是这样的,设置模板代码结合背后
<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>
我不不知道什么是错的,有人可以请帮忙
路径将PropertyList.Min这是我的错误。 1)我使用Object obj = XamlReader.Load(*流指向预期的输出*)。 2)用obj玩一点。 3)string output = XamlWriter.Save(obj)在此输出字符串中,而不是绑定x:Null即将到来。 –
@ vikram.ma:你可以忘记这一点,['XamlWriter'不写绑定](http://msdn.microsoft.com/en-us/library/ms754193.aspx#Extension_References_are_Dereferenced)。 –
@ vikram.ma:我不知道任何这样的方法,为什么你需要这样做?通常情况下,如果你不能做的事情,这只是你不应该做的事情。 –