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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:05:49+00:00 2026-05-31T23:05:49+00:00

I have a selfcreated usercontrol that inherits from canvas. Now it is nessesary that

  • 0

I have a selfcreated usercontrol that inherits from canvas.
Now it is nessesary that this canvas object has always a ratio between width and height.
How is this possible?
I tried this one but it does not work:

        private void Canvas_SizeChanged(object sender, SizeChangedEventArgs e)
    {

        Vector vec = VisualTreeHelper.GetOffset(this);
        if(e.WidthChanged)
            Arrange(new Rect(vec.X, vec.Y, ActualWidth, Image.Height / Image.Width * this.ActualWidth));
        else if(e.HeightChanged)
            Arrange(new Rect(vec.X, vec.Y, Image.Width / Image.Height * this.ActualHeight, ActualHeight));

    }

Now i would like to ask if you have any ideas. The ratio is Image.Height/Image.Width (Image is the background image of the canvas object)

  • 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-31T23:05:51+00:00Added an answer on May 31, 2026 at 11:05 pm

    You could override ArrangeOverride:

    protected override Size ArrangeOverride(Size arrangeSize)
    {
        Size size = base.ArrangeOverride(arrangeSize);
        double aspectRatio = ...
    
        return new Size(size.Width, size.Width / aspectRatio);
    
        // or, if Height determines the final size
        // return new Size(size.Height * aspectRatio, size.Height);
    }
    

    And you have to make sure that the Canvas’ parent does not set its Width or Height at the same time.

    You could for example put it inside another Canvas and set either your Canvas’ Width or Height explicitely. Or you put it in a Grid and set proper values for HorizontalAlignment and VerticalAlignment.

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

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
Have converted devise new session from erb to Haml but doens't work, this is
I have the following Django model: created=models.DateTimeField(auto_now_add=True) I now need a model object method
Have some dates in my local Oracle 11g database that are in this format:
I have a problem when I update an object. This is the model: class
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
**Have it working now. I forgot to populate the Array List. How embarrassing. I'm
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:
Have a bunch of WCF REST services hosted on Azure that access a SQL
have been trying couple of hours now to make my iphone app universal. The

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.