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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:28:19+00:00 2026-05-16T17:28:19+00:00

I’ve got a Canvas and I put some stuff on it, then I scaled

  • 0

I’ve got a Canvas and I put some stuff on it, then I scaled it. But, when you run the scales, they don’t originate from the point they should, like, if you scale it from one origin a bit, then scale from another origin, the second origin acts as if it’s been offset somewhat in a really strange fashion instead of behaving as intended (and as the first origin behaves). I’ve been using ths code to perform the scaling:

        foreach (UIElement element in canvas1.Children)
        {
            Point p = e.MouseDevice.GetPosition(element);
            Matrix m = element.RenderTransform.Value;
            if (e.Delta > 0)
                m.ScaleAt(1.1, 1.1, p.X, p.Y);
            else
                m.ScaleAt(1 / 1.1, 1 / 1.1, p.X, p.Y);
            element.RenderTransform = new MatrixTransform(m);
        }

What on earth could be going on?

I realized that my original question text wasn’t as clear as it could be. I scale from the mouse origin, so you move your mouse to the left of my example pair of text objects, scroll the wheel and they zoom in or out and move across the screen in a perfectly good fashion. But if you then move your mouse to the right far on the other side of the objects, and try to scroll, then they act as if the mouse in the middle of them – that is, they zoom in and out without moving across the screen at all.

  • 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-16T17:28:20+00:00Added an answer on May 16, 2026 at 5:28 pm

    When you create a transformation using ScaleAt, you are creating a translation as well. For example, if the mouse pointer is 100 pixels left of the element, then you are scaling it by 1.1 and also moving it 10 pixels to the right. The next time your code runs, you are scaling that translation as well, so are moving it 1 more pixel to the right in addition to the new translation.

    One solution is to separate out the translation from the previous matrix before applying the scale and then add it back at the end:

    foreach (UIElement element in canvas1.Children)
    {
        Point p = e.MouseDevice.GetPosition(element);
        Matrix m = element.RenderTransform.Value;
        Matrix m2 = m;
        m2.Translate(-m.OffsetX, -m.OffsetY);
        if (e.Delta > 0)
            m2.ScaleAt(1.1, 1.1, p.X, p.Y);
        else
            m2.ScaleAt(1 / 1.1, 1 / 1.1, p.X, p.Y);
        m2.Translate(m.OffsetX, m.OffsetY);
        element.RenderTransform = new MatrixTransform(m2);
    }
    

    A similar option is to always remove the scaling from the RenderTransform and encode it in Canvas.Left and Canvas.Top:

    foreach (UIElement element in canvas1.Children)
    {
        Point p = e.MouseDevice.GetPosition(element);
        Matrix m = element.RenderTransform.Value;
        if (e.Delta > 0)
            m.ScaleAt(1.1, 1.1, p.X, p.Y);
        else
            m.ScaleAt(1 / 1.1, 1 / 1.1, p.X, p.Y);
        Canvas.SetLeft(element, Canvas.GetLeft(element) + m.OffsetX);
        Canvas.SetTop(element, Canvas.GetTop(element) + m.OffsetY);
        m.Translate(-m.OffsetX, -m.OffsetY);
        element.RenderTransform = new MatrixTransform(m);
    }
    

    Update: Actually, I think I missed the larger, related effect. Because you are applying the new scale after the old one, the translation by p.X and p.Y is getting scaled when it should not be. When the scale is large, this gets to be a large error (while the error I mentioned above is always a 10% error).

    Try using ScaleAtPrepend to apply the new transformation first:

    foreach (UIElement element in canvas1.Children)
    {
        Point p = e.MouseDevice.GetPosition(element);
        Matrix m = element.RenderTransform.Value;
        if (e.Delta > 0)
            m.ScaleAtPrepend(1.1, 1.1, p.X, p.Y);
        else
            m.ScaleAtPrepend(1 / 1.1, 1 / 1.1, p.X, p.Y);
        Canvas.SetLeft(element, Canvas.GetLeft(element) + m.OffsetX);
        Canvas.SetTop(element, Canvas.GetTop(element) + m.OffsetY);
        m.Translate(-m.OffsetX, -m.OffsetY);
        element.RenderTransform = new MatrixTransform(m);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
I've got a string that has curly quotes in it. I'd like to replace
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a JSP page retrieving data and when single or double quotes are
this is what i have right now Drawing an RSS feed into the php,

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.