February 20th, 2011, 06:47 AM
ZIndex or Z-order
I would like to know the Z-oder number of one of my dialogs.
I tried to use GetZIndex, but failed.
should I use the Panel.GetZIndex or the Canvas.GetZindex.
anyone worked with this feature?
February 20th, 2011, 08:52 AM
Re: ZIndex or Z-order
Canvas.GetZindex(...) is found in Silverlight but not in "standard" .NET4, so I'm guessing it's what you work with - you could have mentioned it, though.
WPF/Silverlight UI's are made of a bunch of different elements alongside or on top of each other (which in turn might have their own child elements), so I'm guessing that the z-indices are probably relative to the parent element.
What values are you getting, and what values you expected?
The GetZIndex(UIElement) method of the canvas class accepts a UIElement (as u can see) and returns its [element's] z-index, so I presume that by using this method you can get the z-index of the given element even if it's own class doesn't expose it, but I'm not sure. You'll have to experiment a bit.
If I'm right, then you just need to determine the right top level element.
Also, here are some links to some MSDN articles and a quote from one of them, in hope that it'll be useful.
Canvas.ZIndex Attached Property
Make sure to check out the examples there (scroll down), these will show you how the method and the property are meant to be used, and help clarify things further.
"The z-order of an object determines whether the object is in front of or behind another overlapping object. By default, the z-order of objects within a Panel is determined by the sequence in which they are declared. Objects that are declared later appear in front of objects that are declared earlier. You can change this behavior by setting the Canvas.ZIndex attached property on objects within the Panel. Higher values are closer to the foreground; lower values are farther from the foreground.
This property is an example of an attached property syntax, whereby non-Canvas objects can set this property that can then be read and interpreted by a parent Canvas. For more information about attached properties, see Attached Properties Overview.
The value of the Canvas.ZIndex property is expressed as any numeric value. Although you can specify the value as a Double in markup, internally the value is converted to and treated as an integer.
You can also set the Canvas.ZIndex value to a negative value, such as "-99", which places the object even farther from the foreground. Canvas.ZIndex values are aligned along the z-axis -- higher values are closer to the foreground; lower values are farther from the foreground. The following illustration shows the relationship of z-order to z-axis."
Relationship of z-order to z-axis:
February 20th, 2011, 11:51 AM
Re: ZIndex or Z-order
Thanks for the reply.
I don't think I use silverlight.
Just use C#...
I want to use the GetZIndex.
I do not know how to define the UIElement...
int zOrder = Canvas.GetZIndex(UIElement);
have a dialog called MyDialog
with one button; button1
call the Dialog using
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!