问题
I need an element that can know when it's render size has changed.
The render size not the ActualSize and it's the element size in screen. And I can get the size but cant know when it's changed.
For the element is in the ViewBox or in other Control that is in ViewBox and when the ViewBox change size, the element should know that it's render size has changed.
<ViewBox>
<OtherControl>
<Element>How can the elementh know it's actual size has changed</Element>
</OtherColtrol>
</ViewBox>
I cant do it for we cant know that there are many viewBox surround the control.
We can use SizeChanged to know the control's size has changed when the control not in the ViewBox. When the element in grid and grid has changed the size that the element can easy to know it's size havs changed. And we can easy get the control's actual size but I can't know when is the control actual size has changed.
I find two way to know but both is not well.
The first way is use Timer and a while.
In instance write a method to while true check the size.
Check()
{
while(true)
{
if(_lastSize!=ActualSize)
{
//size changed
}
await Task.Delay(1000);
}
}
On the other hand, we can set a property in the outside grid that is the root grid to know it's children that contain a viewBox or other can scrol. And the element what want know it's actual size has changed is binding to the property.
But I want the element as a three part control that must separate to project and dever can drop the element in to grid and it can run well.
来源:https://stackoverflow.com/questions/42411455/how-to-know-the-element-render-size-have-change-by-other-control