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

  • Home
  • SEARCH
  • 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 7173933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:55:41+00:00 2026-05-28T15:55:41+00:00

I have created a custom user control, which is basicly a ItemsControl with it’s

  • 0

I have created a custom user control, which is basicly a ItemsControl with it’s ItemsPanelTemplate set to canvas.

On the mainpage I bind a List<Element> to it, where Element is a custom class.

However, all the controls are placed right on top of eachother. A easy way to fix this ofcourse is by making the Canvas a WrapPanel but I’m not sure if this will colide with the ability of Drag & Drop on the control

So my question would be, is it possible to have a property in the model Element which checks on which position it is of a list, if it is in a list?

something like:

public class Element 
{
    public int positionInList { get { return (this.IsInList) ? this.ListPosition : 0; } }
}

Update

What I wish to accomplish is that when the elements are added to the canvas, they automaticly pick their spot by 2 properties (which will be bound to the Canvas.Left and Canvas.Top or something similar)

public double GetX { get { return 50 * (Element.PositionInList % 5); } }
public double GetY { get { return 50 * (Element.PosotionInList / 5); } }

Without manually having to set the element’s position in the list.

  • 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-05-28T15:55:42+00:00Added an answer on May 28, 2026 at 3:55 pm

    When you place elements in a Canvas, you must specify the coordinates where the elements will be placed (left upper corner for each element). Maybe is better to derivate from Canvas a new class that will perform the placement for you and use this class for ItemsPanelTemplate. Also, Drag & Drop should work with WrapPanel but depends on your requirements.

    A quick and non optimal sample:

    class CustomCanvas : Canvas
    {
    private int mChildsNum = 0;
    ...
    CustomCanvas()
    {
        // Track changes that appear in canvas when new
        // children are added
        this.LayoutUpdated += CanvasChangeTracker;
    }
    ...
    private void CanvasChangeTracker(object source, EventArgs e)
    {
        if ( this.Children.Count != mChildsNum )
        {
            // A new child was added.
            // Update the coordinates for children
            mChildsNum = this.Children.Count;
        }
    }
    ...
    }
    

    This example can be considerably improved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a somewhat complex custom user control, created in C# .NET, which is
i have created a custom user control which im using on my main xaml
I have a custom user control in XAML that creates a ItemsControl which ItemsPanel
I have created a user control which exposes a custom type property called SoftwareItem.
I have created a custom WPF user control which is intended to be used
I have made one custom user control (search text box), which basically consists of
I created a custom password box user control which is able to show and
I created a custom control which contains an Image control. I'd like to have
If have created a custom role within SqlServer which I added to the db__denydatareader
I have created a custom list as a feature in sharepoint. i need to

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.