Ive done some tranfor开发者_StackOverflowms for my object in the canvas, like rotating and transforming.
How can i store the new coordinates afterwards? If I try to move the object around it will only use the new Transforms.
From what I can see, this is fairly non-trivial. Generally, you'll want to let WPF handle that kind of thing for you.
That said, here's what I've been able to come up with, based on information from here. Given a text block "textBlockName":
HwndSource hwndSource = PresentationSource.FromVisual(textBlockName) as HwndSource;
Visual root = hwndSource.RootVisual;
// Translate the point from the visual to the root.
GeneralTransform transformToRoot = textBlockName.TransformToVisual(root);
Point p = new Point(0,0);
p = transformToRoot.Transform(p);
p = hwndSource.CompositionTarget.TransformToDevice.Transform(p ) ;
//Display the top left point of the text box, after transforms.
MessageBox.Show(p.ToString() );
Edit: Looking at this further, I cannot find a better solution to this. This seems to handle every situation I can think to throw at it, though.
精彩评论