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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:39:35+00:00 2026-05-14T08:39:35+00:00

Can you drag a canvas in WPF? How do you set the position of

  • 0

Can you drag a canvas in WPF? How do you set the position of the canvas? Here is what I got so far:

/// xaml

<Window x:Class="TestApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="350" Width="525"
        WindowStyle="None" ResizeMode="NoResize" AllowsTransparency="True"
        Background="Transparent" Loaded="MainWindow_Loaded">


    <Canvas Name="ParentCanvas" Background="#FF6E798D">
    </Canvas>
</Window>

/// code behind

public partial class MainWindow : Window
{
    private Boolean isMouseCapture;

    public MainWindow()
    {
        InitializeComponent();
    }

    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {            
        this.ParentCanvas.MouseLeftButtonDown += new MouseButtonEventHandler(_MouseLeftButtonDown);
        this.ParentCanvas.MouseLeftButtonUp += new MouseButtonEventHandler(_MouseLeftButtonUp);
        this.ParentCanvas.MouseMove += new MouseEventHandler(_MouseMove);
    }

    void _MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        this.ParentCanvas.ReleaseMouseCapture();
        isMouseCapture = false;
    }

    void _MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        this.ParentCanvas.CaptureMouse();
        isMouseCapture = true;
    }

    void _MouseMove(object sender, MouseEventArgs e)
    {
        if (isMouseCapture)
        {
            this.ParentCanvas.X= e.GetPosition(this).X;
            this.ParentCanvas.Y = e.GetPosition(this).Y;
        }
    }
}

‘X’ is not a property of Canvas (i.e.”this.ParentCanvas.X”). What do I use to set the position?

  • 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-14T08:39:35+00:00Added an answer on May 14, 2026 at 8:39 am

    To set the position of an element in pixels, the element must be contained in a Canvas panel.

    You can then call Canvas.SetTop and Canvas.SetLeft.

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

Sidebar

Related Questions

I'm trying to create a WPF application where I can drag an image around.
I'm trying to have a WPF canvas with rounded rectangles on that I can
I want to make a WPF Grid in which users can drag and drop
I have a canvas (Panel Control) in my WinForms app where users can drag
How can I make a drag and drop editor like the one in wufoo.com
Can anybody recommend a treeview component for ASP.NET that supports drag & drop (between
I'm working with a WPF app, more specifically a Canvas with draggable elements. Once
I have a Canvas in which user can add UserControl subclasses containing a form.
I am new to WPF. I want to draw a small circle on Canvas
Why does this work so well in wpf <ScrollViewer HorizontalScrollBarVisibility=Auto VerticalScrollBarVisibility=Auto> <Canvas x:Name=MyDesigner> </Canvas>

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.