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.
VS2022 - Arrow keys automatically insert alignment properties in XAML designer
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.
2 answers
Sort by: Most helpful
-
-
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.
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.