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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:14:31+00:00 2026-06-05T12:14:31+00:00

I try to rotate a Border and have the MainWindow change his size based

  • 0

I try to rotate a Border and have the MainWindow change his size based on the new space taken by the Border rotation.
I’ve set SizeToContent="WidthAndHeight" but window size does’t take change when I rotated the border.

Do I need to programmatically set the Width and Height for the MainWindow or this can be achieved changing the xaml code in some other way?

My xaml code:

<Window x:Class="MyClass.MainWindow"
        WindowStyle="None" AllowsTransparency='True' 
        Topmost='False' Background="Transparent"  ShowInTaskbar='False' 
        SizeToContent="WidthAndHeight" WindowStartupLocation="Manual">
    <Border Name="MyBorder" 
            BorderBrush="Transparent"
            Background="Transparent"
            HorizontalAlignment="Left" 
            VerticalAlignment="Top"
            RenderTransformOrigin="0.5,0.5">
    </Border>
</Windows>

My c# code on Window_KeyDown:

# RotateTransform rt = new RotateTransform() is declared at class level.

if (e.Key == Key.I)
                {
                    if (rt.Angle + 1 < 360)
                    {
                        rt.Angle += 1;                    
                    }
                    else
                    {
                        rt.Angle = 0;                   
                    }    



                MyBorder.RenderTransform = rt;
            }
  • 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-06-05T12:14:33+00:00Added an answer on June 5, 2026 at 12:14 pm

    Use LayoutTransform instead of RenderTransform

    From MSDN: Transforms Overview

    • LayoutTransform – A transform that is applied before the layout pass. After the transform is applied, the layout system processes the
      transformed size and position of the element.

    • RenderTransform – A transform that modifies the appearance of the element but is applied after the layout pass is complete. By using the
      RenderTransform property instead of the LayoutTransform property, you
      can obtain performance benefits.

    Example

    <Border Name="MyBorder"  
            BorderBrush="Transparent" 
            Background="Transparent" 
            HorizontalAlignment="Left"  
            VerticalAlignment="Top" 
            RenderTransformOrigin="0.5,0.5">
        <Border.LayoutTransform>
            <RotateTransform Angle="90"/>
        </Border.LayoutTransform>
    </Border>
    

    So in your case

    RotateTransform rt = new RotateTransform(0.0, 0.5, 0.5);
    private void Window_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.I)
        {
            if (rt.Angle + 1 < 360)
            {
                rt.Angle += 1;
            }
            else
            {
                rt.Angle = 0;
            }
            MyBorder.LayoutTransform = rt;
        }
    }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIScrollView in which I've set the contentSize to the size of
I have an issue with a UILabel acting funny when I try to rotate
I try to work on a Force based 2D ship game. I have Forces,
I am working with large size images and when I try to rotate them
I have an image of a Pan Card and when I try to rotate
I have the following page where I try to rotate a YouTube video by
I have a big problem when I try to rotate my projectiles along with
I try to set the anchorPoint property, in order to rotate a view by
i try to rotate 3 imageViews (or better the Bitmaps behind them) every 10-100ms.
Try to see which cast is faster (not necessary better): new c++ case or

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.