3

也许我在这里遗漏了一些简单的东西,但是我找不到从画布包含的项目中删除附加属性的方法。

代码示例:

//Add an image to a canvas; set the location to the top
theCanvas.Children.Add(theImage);
Canvas.SetTop(theImage, 0);

//Move the image to the bottom of the canvas
Canvas.SetBtoom(theImage, 0);

这不起作用,因为顶部附加属性优先于底部附加​​属性;所以我们尝试“取消设置”顶部附加属性

//Move the image to the bottom of the canvas
Canvas.SetTop(theImage, DependencyProperty.UnsetValue);
Canvas.SetBtoom(theImage, 0);

...并且编译器抱怨 UnsetValue 无法转换为双精度值。

我在这里遗漏了什么,我们如何删除 Top 附加属性?

4

2 回答 2

7

您可以使用 ClearValue 删除本地 DependendencyProperty 值:

theImage.ClearValue(Canvas.TopProperty);

或在 DependencyObject 的代码中从自身中删除值:

ClearValue(Canvas.TopProperty, theImage);
于 2011-03-28T22:19:26.497 回答
1

Canvas.Top文档

默认值为NaN

尝试设置Canvas.SetTop(theImage, double.NaN);,这一定有帮助。

于 2011-03-28T20:20:33.103 回答