Code Inspection and Quick-Fixes in XAML
The key features of JetBrains Rider's code analysis are also supported in XAML. You can find the detailed information on these features in the corresponding topics of the Code analysis section. In the main topic of the section, you can also find the feature matrix and check what exactly is supported in XAML.
In this topic, you can find some examples of using code analysis features in XAML.
Code Inspection
JetBrains Rider detects various problems in XAML files, such as unresolved symbols, incorrect document structure, unused import directives, and so on. Whenever a problem is encountered, JetBrains Rider highlights it and displays some description in a tooltip. In the example below, JetBrains Rider warns that the namespace alias is not used inside the current file and highlights it in grey:
![JetBrains Rider: XAML code highlighting JetBrains Rider: XAML code highlighting](https://resources.jetbrains.com.cn/help/img/rider/2024.2/ReSharper_by_Language__XAML__Code_Highlighting_01.png)
In the following example, JetBrains Rider highlights a problem with resolving a method inside an event subscription:
![JetBrains Rider: XAML code highlighting JetBrains Rider: XAML code highlighting](https://resources.jetbrains.com.cn/help/img/rider/2024.2/ReSharper_by_Language__XAML__Code_Highlighting_02.png)
The analysis is performed by applying code inspections to the current document or in any specified scope.
To look through the list of available inspections for XAML, open the XAML node.
page of JetBrains Rider settings Ctrl+Alt+S, and then expand theSolution-Wide Analysis
JetBrains Rider does not only analyze errors in the current XAML file, but also inspects all files in the whole solution and shows the results of the analysis in the All Solution Files tab of the Problems window Alt+6. It takes dependencies between files into account and updates the results when you change code.
![JetBrains Rider: XAML errors in solution JetBrains Rider: XAML errors in solution](https://resources.jetbrains.com.cn/help/img/rider/2024.2/XAML__Errors_in_Solution.png)
For more information, refer to Solution-wide analysis.
Examples of Quick-Fixes
Make field private
To change visibility of a field declared in XAML, use the appropriate quick-fix.
![JetBrains Rider: Make field private quick-fix in XAML JetBrains Rider: Make field private quick-fix in XAML](https://resources.jetbrains.com.cn/help/img/rider/2024.2/ReSharper_by_Language__XAML__Context_Actions__make_private_01.png)
After applying the quick-fix, the value of FieldModifier
is changed to private
.
![JetBrains Rider: Make field private quick-fix in XAML JetBrains Rider: Make field private quick-fix in XAML](https://resources.jetbrains.com.cn/help/img/rider/2024.2/ReSharper_by_Language__XAML__Context_Actions__make_private_02.png)
Remove redundant namespace alias
To remove a redundant namespace alias, use the appropriate quick-fix.
![JetBrains Rider: Remove redundant namespace alias quick-fix in XAML JetBrains Rider: Remove redundant namespace alias quick-fix in XAML](https://resources.jetbrains.com.cn/help/img/rider/2024.2/ReSharper_by_Language__XAML__Quick-Fixes__remove_redundant_01.png)
After applying the quick-fix, the namespace alias directive is removed.
![JetBrains Rider: Remove redundant namespace alias quick-fix in XAML JetBrains Rider: Remove redundant namespace alias quick-fix in XAML](https://resources.jetbrains.com.cn/help/img/rider/2024.2/ReSharper_by_Language__XAML__Quick-Fixes__remove_redundant_02.png)
Remove type qualifier
When the type, to which the style should be applied, is specified in the TargetType
attribute, there is no need to add a qualifier for each property of the Button
class. JetBrains Rider detects such cases and offers the quick-fix.
![JetBrains Rider: Remove type qualifier quick-fix in XAML JetBrains Rider: Remove type qualifier quick-fix in XAML](https://resources.jetbrains.com.cn/help/img/rider/2024.2/ReSharper_by_Language__XAML__Quick-Fixes__remove_type_qualifier_01.png)