'How to toggle a line comment in XAML for C# WPF in Visual Studio 2019
I have Ctrl+Q set to toggle line comments globally in my C# project.
It does works when I'm editing .cs file.

However, it does not work when editing XAML files.

It does work if I press the comment and uncomment buttons

But not with the hotkey I set.
Is there a different command I should use for toggling the XAML comment wrapper with a single hotkey?
Solution 1:[1]
It seems that the XAML editor does not use the Editor.ToggleLineComment shortcut. Instead it is:
Editor.CommentSelectionfor commenting a line or selection in XAMLEditor.UncommentSelectionfor uncommenting a line or selection in XAML
When pressing the shortcut, the XAML line will be commented out, if the cursor is placed anywhere in the line (no selection) or the selected characters are commented out, if you select a range of text.
Solution 2:[2]
@John.
You can install Toggle Comment to make Editor.ToggleLineComment work in XAMl code. Below is the Step:
- Download and install Toggle Comment from here
- Restart VS.
- Go to "Tools>Options...>Environment>Keyboard" and search for "ToggleLineComment" then bind it to your favorite key
- Open XAML code page, "Edit" -> "Advances" -> "Toggle Comment" to make the Menu Placement.
Update:
The result of the fourth step is shown in the picture below: (What we need to note here is that the fifth step is executed in the XAML page)
Solution 3:[3]
For anyone still looking for the answer, I found the solution (Working with VS 2022)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | thatguy |
| Solution 2 | |
| Solution 3 | tayyab |



