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 6574241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:14:12+00:00 2026-05-25T15:14:12+00:00

I am able to render a collection of items and move them around with

  • 0

I am able to render a collection of items and move them around with the mouse. I am having trouble getting the canvas itemspanel to resize automatically. Try the code as is and see how the rectangles are rendered and how they can be dragged hither and thither with the mouse. Note that they are constrained to the parent bounds (400×400). Next find the commented line <!--<Canvas>--> uncomment it and comment out the line above it <Canvas Height="400" Width="400">. Now note how the rectangles are rendered correctly but as soon as you drag one they fly off to the top left corner and cannot be moved anymore! Please help!

You will need these namespaces

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"

Complete XAML is below, drop this in on a page or in a control

<Grid x:Name="LayoutRoot">

    <UserControl>

        <UserControl.Resources>
            <DataTemplate x:Key="ItemTemplateKey">
                <Canvas Height="400" Width="400">
                <!--<Canvas>-->
                    <Rectangle Height="50" Width="50" Fill="Red">
                        <i:Interaction.Behaviors>
                            <ei:MouseDragElementBehavior ConstrainToParentBounds="True"/>
                        </i:Interaction.Behaviors>
                    </Rectangle>
                </Canvas>
            </DataTemplate>
        </UserControl.Resources>

        <Grid x:Name="LayoutRoot2">
            <ItemsControl
                ItemsSource="{Binding anArrayOfThreeOrFourThingsInTheVM}"
                ItemTemplate="{StaticResource ItemTemplateKey}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </Grid>

    </UserControl>

</Grid>

In the VM or the code behind provide a collection for the itemssource to bind to:

    public int[] anArrayOfThreeOrFourThingsInTheVM { get { return new int[] { 1, 2, 3 }; } }

Edit:
Sweet baby Jesus! As a last ditch effort before bed I tried replacing the canvas with a grid and it all worked!

Here is the new working xaml in case someone else has the same problem:

<Grid x:Name="LayoutRoot">

    <UserControl>

        <UserControl.Resources>
            <DataTemplate x:Key="ItemTemplateKey">
                <Grid>
                    <Rectangle Height="50" Width="50" Fill="Red">
                        <i:Interaction.Behaviors>
                            <ei:MouseDragElementBehavior ConstrainToParentBounds="True"/>
                        </i:Interaction.Behaviors>
                    </Rectangle>
                </Grid>
            </DataTemplate>
        </UserControl.Resources>

        <Grid x:Name="LayoutRoot2">
            <ItemsControl
                ItemsSource="{Binding anArrayOfThreeOrFourThingsInTheVM}"
                ItemTemplate="{StaticResource ItemTemplateKey}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </Grid>

    </UserControl>

</Grid>
  • 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-25T15:14:13+00:00Added an answer on May 25, 2026 at 3:14 pm

    I edited my question above with this answer. Putting it here to answer/close the question.

    Here is the new working xaml in case someone else has the same problem:

    <UserControl>
    
        <UserControl.Resources>
            <DataTemplate x:Key="ItemTemplateKey">
                <Grid>
                    <Rectangle Height="50" Width="50" Fill="Red">
                        <i:Interaction.Behaviors>
                            <ei:MouseDragElementBehavior ConstrainToParentBounds="True"/>
                        </i:Interaction.Behaviors>
                    </Rectangle>
                </Grid>
            </DataTemplate>
        </UserControl.Resources>
    
        <Grid x:Name="LayoutRoot2">
            <ItemsControl
                ItemsSource="{Binding anArrayOfThreeOrFourThingsInTheVM}"
                ItemTemplate="{StaticResource ItemTemplateKey}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </Grid>
    
    </UserControl>
    

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

Sidebar

Related Questions

i am not being able to render a bulleted list through xml/xsl transformation. I
I want to be able to render a Grid while the number of some
Lets say I wish to be able to render different view logic for two
i want to be able to take html code and render plain text out
I want to be able to register scripts and stylesheets. These items would then
In my Backbone.js app, I need to be able to insert new items between
I've looked around for a while now and have not been able to find
I currently am able to render a partial in JS like so: $(#cmtList_<%= @commentable.id
I'm struggling to paginate using mongoid. I'm able to call paginate on my collection
I'm trying to render a Backbone.js collection as a select list using an Underscore.js

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.