VS2022 - Arrow keys automatically insert alignment properties in XAML designer

Simon Gaudin 0 Reputation points
2023-02-10T15:13:03.6+00:00

I recently upgraded to Visual Studio Professional 2022, and I have an issue I did not encounter with Visual 2019.

For the record, I'm using Visual Studio Professional 2022 Version 17.4.4.

When using the XAML Designer, if I happen to move a control whithin a Canvas with the arrow keys on my keyboard, "Horizontal Alignment" and "VerticalAlignment" properties get automatically added to the code of the control, in the XAML Editor. This concerns every control inside a Canvas (I tested with as many controls as I could, and it happened every time).

I found that the Left Arrow and Right Arrow keys add this to the control :

HorizontalAlignment="Left" VerticalAlignment="Center"

And that the Up Arrow and Down Arrow keys add this to the control :

HorizontalAlignment="Center" VerticalAlignment="Top"

This problem also occurs in Blend 2022, with the exact same context.

I've searched everywhere in the XAML Designer Settings, the keyboard shortcuts, the elements' properties, but I found nothing that could explain such an issue.

It is particularly annoying, because these automatically inserted properties get on every control I move with the arrow keys, flooding the code with useless properties.

I hope my explanation was clear, and I will be happy to provide extra examples and information if needed.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,780 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,136 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
811 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 54,401 Reputation points
    2023-02-10T15:21:59.4+00:00

    I'm not sure if that is by design or not. There have been issues reported over the years in the XAML editor related to it auto-setting properties. I recommend you use Report a Problem in VS and record the problem so the XAML team can look at the issue.


  2. Hui Liu-MSFT 48,541 Reputation points Microsoft Vendor
    2023-02-21T08:21:34.6+00:00

    Hi,@Simon Gaudin. Welcome Microsoft Q&A.

    Not sure if it's the design.

    There are properties FrameworkElement.VerticalAlignment Property and FrameworkElement.HorizontalAlignment Property in FrameworkElement.

    Canvas inherits from the FrameworkElement, so it will have both properties as well.

    User's image

    But Canvas has its own characteristics, as you pointed out.

    Canvas does not use VerticalAlignment when composing layout, because Canvas is based on absolute positioning.

    It is recommended that you write the code manually instead of just dragging it.


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.