In WPF/Silverlight, can I get the calculated value of a UIElement
after a transformation is applied?
(Per the comment below):
I've got a stack panel and I've applied a TranformGroup
to it. There are two translate and one scale transforms in this group.
(warning, psuedo code ahead)
groupTransform.children.add(new TranslateTransform());
groupTransform.children.add(new ScaleTransform());
groupTransform.children.add(new TranslateTransform());
containerToScale.RenderTransform = groupTransform;
...
// code that sets values to all the transforms
Obviously the scale transform is the one I'm most interested in.
you could simply apply the transform:
control.LayoutTransform.Transform(new Point(0,0))
Matthew, as you pointed out
ActualWidth
andActualHeight
don't change if you apply transforms.ActualWidth
andActualHeight
represent the calculated width/height after the layout system has finished calculating the size of a control (based on values such asMargin
,HorizontalAlignment
, etc.)One way to get the size of a control taking into account all of the scale transformations that have been applied to it is to walk up the visual tree and apply all scale transforms to the
ActualWidth
andActualHeight
of a control:Keep in mind that this might be inefficient if your visual tree is deep or you perform this many times. In practice I've never run into any problems with this, however.
Yes, you can check
ActualWidth
andActualHeight
on anyFrameworkElement
to figure this out. You'll need to check whether it is visible though if you have elements that hide.If you want to know after the control has loaded use the
Loaded
event.