CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    ZIndex or Z-order

    Hi All,

    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?

    regards,

    ger

  2. #2
    Join Date
    Jan 2010
    Posts
    1,133

    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.GetZIndex Method
    Canvas.ZIndex Attached Property

    "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:
    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.

  3. #3
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: ZIndex or Z-order

    Hi,

    Thanks for the reply.
    I don't think I use silverlight.
    Just use C#...

    I want to use the GetZIndex.
    like;
    Code:
    int zOrder = Canvas.GetZIndex(UIElement);
    I do not know how to define the UIElement...

    have a dialog called MyDialog
    with one button; button1

    call the Dialog using

    Code:
    myDialog.showdialog();
    regards,

    ger

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured