简体   繁体   中英

How do Transforms in WPF work?

I recently used a TranslateTransform in my WPF application to implement dragging a UserControl across the screen. There is a new bug in that after the first time you drag it somewhere else on the screen, when you click on the "Title bar" on the control, it jumps back to where it was originally displayed. It will still follow the mouse, but that initial jump is disconcerting.

I don't know what's going on, but this got me to wondering. Since WPF controls don't have a left or top property of their own, unless you put them into a Canvas , and those are attached properties anyway, just what properties are being modified by the TranslateTransform ?

WPF's layout and render passes have intrinsic knowledge of transforms. By modifying the X and Y properties of the TranslateTransform , you're causing the layout/render pass to take those new values into consideration when positioning the associated FrameworkElement .

To put it another way: the TranslateTransform is not modifying other properties, but by modifying its properties you are triggering another layout/render pass and thus affecting the on-screen positioning of the associated FrameworkElement .

Read here for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM