How to follow the location of an element in Silverlight
I'm new to Silverlight programmi开发者_StackOverflow社区ng, and the DependencyProperty
is still relatively new to me, which causes the following issue:
I'd like to attach to an event, when Canvas.LeftProperty
of Canvas.TopProperty
changes for an UIElement
(a UserControl
in my case).
For example, I'm able to do the following:
source.SizeChanged += delegate
{
target.Width = source.Width;
target.Height = source.Height;
};
But I was unable to find a similar event for location. Is this even possible?
An element does not generally know about it's location in the WPF layout system. The parent element (in your case, a Canvas) is responsible for laying out the element and the element is simply responsible for sizing itself according to the constraints of the layout container.
Having said that, you can use the LayoutUpdated event on the element. It is probably best to set this on the panel and use it as a trigger to re-scan the properties of the children since the LayoutUpdated event (according to the docs) always passes a null reference to the sender parameter.
精彩评论