Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change z-order of Wpf AdornerLayer children?

I have an image editing application, and I have custom adorners which get added to an AdornerLayer. When the user clicks on an Adorner, I want to bring it to top - meaning if it is dragged over another adorner, I want the first click to be caught by the topmost adorner.

I can't figure out how to change the z-order of the child elements of the AdornerLayer. It doesn't seem to allow me to sort them. Even if I remove and re-add the Adorner, it doesn't get topmost.

like image 345
Sugrue Avatar asked Jun 18 '12 17:06

Sugrue


2 Answers

I had a similar problem, but just needed a specific ordering of my adorners. I ended up using reflection to set the orders:

var setZOrderMethodInfo = adornerLayer.GetType().GetMethod("SetAdornerZOrder", System.Reflection.BindingFlags.NonPublic |  System.Reflection.BindingFlags.Instance);     
setZOrderMethodInfo.Invoke(adornerLayer, new object[] { adorner1, 0 });     
setZOrderMethodInfo.Invoke(adornerLayer, new object[] { adorner2, 1 });

from http://social.msdn.microsoft.com/Forums/en/wpf/thread/40bff84e-c4b5-4ea0-87ea-43461df9f24b

like image 72
Dennis S. Avatar answered Oct 05 '22 09:10

Dennis S.


Please have a look on that,

http://social.msdn.microsoft.com/forums/en-us/wpf/thread/C6780661-EF6D-4141-B4CA-0C7A2461D314

like image 38
Md. Rashim Uddin Avatar answered Oct 05 '22 08:10

Md. Rashim Uddin