Z Order of Map object and whole InformationLayer

2 posts, 0 answers
  1. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 17 May 2013 Link to this post

    I have multiple InformationLayers inside my RadMap control, each of them showing different MapItems. The objects (MapItems) are bound via ItemsSource.

    How can I bringt a MapItem to front?
    It seems that there is no ZIndex Property. I managed it by moving an object to the end of the ItemsSource. Is there a better way?

    How can I bring a whole InformationLayer to Front?
    When moving an object to the end of ItemsSource like said above, it is still covered by MapItems which are part of a "higher" layer. Is there anything like good old "BringToFront()" for InformationLayer?
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 18 May 2013 Link to this post

    Hi Johannes,

    You can use the Canvas.ZIndex attachable property for map item to bring it to front. But when you use MVVM with a data template then you should apply this property to the container for the item.
    You can also use the Canvas.ZIndex to bring a whole InformationLayer to front.
    The sample code is below.
    It uses the MouseLeftButtonDown event from a data template for a map item. I hope it helps.
    private int maxElementZIndex = 1;
    private int maxLayerZIndex = 1;
     
    private void BringElementToFront(UIElement newTopElement)
    {
        int zIndex = Canvas.GetZIndex(newTopElement);
        if (zIndex < maxElementZIndex)
        {
            Canvas.SetZIndex(newTopElement, ++maxElementZIndex);
        }
    }
     
    private void BringLayerToFront(UIElement newTopElement)
    {
        int zIndex = Canvas.GetZIndex(newTopElement);
        if (zIndex < maxLayerZIndex)
        {
            Canvas.SetZIndex(newTopElement, ++maxLayerZIndex);
        }
    }
     
    private void ItemMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        FrameworkElement element = sender as FrameworkElement;
        if (element != null)
        {
            InformationLayer layer = element.GetVisualParent<InformationLayer>();
            if (layer != null)
            {
                this.BringLayerToFront(layer);
                if (!layer.Items.Contains(element) && element.DataContext != null)
                {
                    // element is a part of the datatemplate for item
                    // get the container for the item
                    element = layer.ItemContainerGenerator.ContainerFromItem(element.DataContext) as FrameworkElement;
                }
     
                if (element != null)
                {
                    this.BringElementToFront(element);
                }
            }
     
            e.Handled = true;
        }
    }

    Note that the sample code uses the GetVisualParent extension. So, you should also add the 'using Telerik.Windows.Controls' statement in your code.

    All the best,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top