Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8618803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:11:38+00:00 2026-06-12T06:11:38+00:00

I have an image editor in silverlight that allows the user to add, manipulate

  • 0

I have an image editor in silverlight that allows the user to add, manipulate and delete image and text elements on a canvas. I notice it seems to act strangely when adding new elements sometimes and they will be placed behind an existing element for example. Below is the code for adding image elements, and the order elements method which it calls. I inherited this code from someone else so at times I can’t follow what his intention was. The code doesn’t seem to do what it is supposed to though.

Can someone suggest a better way to assign a Z-Index value to elements that I am adding?

XAML of my workspace canvas –

<Canvas x:Name="pnlCanvas" HorizontalAlignment="Center" VerticalAlignment="Center" Height="{Binding Path=CanvasHeight, Mode=OneWay,UpdateSourceTrigger=Default}"
                        Width="{Binding Path=CanvasWidth, Mode=OneWay, UpdateSourceTrigger=Default}" >
                    <ItemsControl ItemsSource="{Binding Path=Elements, Mode=OneWay}"  >
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <Canvas Background="{Binding Path=CanvasBackground, Mode=OneWay}"
                                    Height="{Binding Path=CanvasHeight, Mode=OneWay,UpdateSourceTrigger=Default}"
                                    Width="{Binding Path=CanvasWidth, Mode=OneWay, UpdateSourceTrigger=Default}" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </Canvas>

Adding image element –

private void AddImageElement(object param)
    {
        bool? gotImage;
        string fileName;
        BitmapImage imageSource = GetImageFromLocalMachine(out gotImage, out fileName);
        OrderElements();

        if (gotImage == true)
        {
            Image image = new Image();
            image.Name = fileName;
            image.Source = imageSource;
            image.Height = imageSource.PixelHeight;
            image.Width = imageSource.PixelWidth;
            image.MaxHeight = imageSource.PixelHeight;
            image.MaxWidth = imageSource.PixelWidth;
            image.Cursor = Cursors.Hand;
            image.Tag = null;



            AddDraggingBehavior(image);
            image.MouseLeftButtonUp += element_MouseLeftButtonUp;

            this.Elements.Add(image);
            numberOfElements++;

            this.SelectedElement = image;
            this.SelectedImageElement = image;
        }
    }

Order Elements –

private void OrderElements()
    {
        var elList = (from element in this.Elements
                      orderby element.GetValue(Canvas.ZIndexProperty)
                      select element).ToList<FrameworkElement>();

        for (int i = 0; i < elList.Count; i++)
        {
            FrameworkElement fe = elList[i];
            fe.SetValue(Canvas.ZIndexProperty, i);

        }

        this.Elements = new ObservableCollection<FrameworkElement>(elList);

    }

My end intention once I have this sorted out is to include a layers container like in Photoshop etc. where I will be able to reorder the elements. Hopefully someone can help get me moving in that direction. Basically how do I set the Z-Index correctly because I don’t think this is doing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:11:39+00:00Added an answer on June 12, 2026 at 6:11 am

    An ItemsControl wraps each element in a <ContentPresenter> tag, so although the ZIndex is set on your element, it doesn’t get applied because the ZIndex on the ContentPresenter is what matters

    What actually gets rendered looks like this:

    <Canvas>
        <ContentPresenter>
            <Image Canvas.ZIndex="0" />
        </ContentPresenter>
        <ContentPresenter>
            <Image Canvas.ZIndex="1" />
        </ContentPresenter>
        ...
    </Canvas>
    

    To fix the issue, set the ZIndex in the ItemContainerStyle so it gets applied to the ContentPresenter instead of the UI Element

    <ItemsControl.ItemContainerStyle>
        <Style>
            <Setter Property="Canvas.ZIndex" Value="{Binding Canvas.ZIndex}" />
        </Style>
    </ItemsControl.ItemContainerStyle>
    

    For more information, see the bottom section of my blog post about WPF’s ItemsControl

    Edit:

    Apparently Silverlight doesn’t have an ItemsContainerStyle for the ItemsControl.

    In that case, simply set an implicit style for the ContentPresenter that sets the Canvas.ZIndex value in your ItemsControl.Resources

    <ItemsControl.Resources>
        <Style TargetType="ContentPresenter">
            <Setter Property="Canvas.ZIndex" Value="{Binding Canvas.ZIndex}" />
        </Style>
    </ItemsControl.Resources>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an image editor in Flex to add text and other changes. Once
I am working on my minor project. I have to create an image editor
I have image Array with two images out of that first image its showing
I have image map that can I move, but this map will be so
i have a div that it have image content .i wanna implement animation when
I am using nicEdit editor and I have added my own custom image resizing
I have used jQuery's jqrte text editor, but it has many drawbacks. Could anyone
I have to create website in PHP, which need image editor functionality like image
I'm looking for image editor with the same functionality with Paint. It should have
I'm creating somekind of 2D image editor in Android and I have the big

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.