Skip to content

Commit e63ef0e

Browse files
Fix XC0022 and XC0023 warnings by adding x:DataType for compiled bindings (#32444)
* Initial plan * Initial analysis: identified 12 XAML files with XC0022 warnings Co-authored-by: simonrozsival <[email protected]> * Fix XC0022 warnings - add x:DataType to XAML files for compiled bindings Co-authored-by: simonrozsival <[email protected]> * Fix Issue23868: Add x:DataType to ContentPage root element Co-authored-by: simonrozsival <[email protected]> * Address review feedback: use x:DataType in Binding markup, revert to original Monkey class, simplify bindings Co-authored-by: simonrozsival <[email protected]> * Keep x:DataType="{x:Null}" for Issue23868 Grid with ItemsSource.Count binding Co-authored-by: simonrozsival <[email protected]> * Move x:DataType to ContentPage root for Issues8845, simplify Issue23868 binding to use Items.Count Co-authored-by: simonrozsival <[email protected]> * Remove XC0023 from NoWarn list (no XC0023 warnings found in codebase) Co-authored-by: simonrozsival <[email protected]> * Fix Picker x:DataType * Revert changes to problems-report.html --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: simonrozsival <[email protected]> Co-authored-by: Simon Rozsival <[email protected]>
1 parent 6dce86f commit e63ef0e

File tree

14 files changed

+47
-31
lines changed

14 files changed

+47
-31
lines changed

src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
<_FastDeploymentDiagnosticLogging>True</_FastDeploymentDiagnosticLogging>
2424
<WindowsPackageType>None</WindowsPackageType>
2525
<!-- TODO: remove these obsolete nowarns and fix it in code -->
26-
<NoWarn>$(NoWarn);CS0618;CS0672;XC0618;XC0022;XC0023;IL2026;IL2091;IL2067;IL2072;IL2087;IL3050</NoWarn>
26+
<NoWarn>$(NoWarn);CS0618;CS0672;XC0618;IL2026;IL2091;IL2067;IL2072;IL2087;IL3050</NoWarn>
2727
</PropertyGroup>
2828

2929
<PropertyGroup Condition=" '$(_UseNativeAot)' == 'true' ">
3030
<PublishAot>true</PublishAot>
3131
<_IsPublishing>true</_IsPublishing>
3232
<IlcTreatWarningsAsErrors>false</IlcTreatWarningsAsErrors>
33-
<WarningsNotAsErrors>IL3050;XC0022</WarningsNotAsErrors>
33+
<WarningsNotAsErrors>IL3050</WarningsNotAsErrors>
3434
<DefineConstants>$(DefineConstants);NATIVE_AOT</DefineConstants>
3535
</PropertyGroup>
3636

src/Controls/tests/TestCases.HostApp/Issues/Issue19127.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
x:Class="Maui.Controls.Sample.Issues.Issue19127"
5-
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues">
5+
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues"
6+
x:DataType="ns:Issue19127Settings">
67
<VerticalStackLayout
78
VerticalOptions="Center">
89
<Button Text="{Binding IsCameraEnabled, StringFormat='Toggle Camera View ({0})'}"

src/Controls/tests/TestCases.HostApp/Issues/Issue19831.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<StackLayout>
1010
<ListView>
1111
<ListView.ItemTemplate>
12-
<DataTemplate>
12+
<DataTemplate x:DataType="x:String">
1313
<ViewCell>
1414
<ViewCell.ContextActions>
1515
<MenuItem Text="View"/>

src/Controls/tests/TestCases.HostApp/Issues/Issue22104.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
5-
x:Class="Maui.Controls.Sample.Issues.Issue22104">
5+
x:Class="Maui.Controls.Sample.Issues.Issue22104"
6+
x:DataType="local:Issue22104ViewModel">
67

78
<ContentPage.BindingContext>
89
<local:Issue22104ViewModel/>

src/Controls/tests/TestCases.HostApp/Issues/Issue22467.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
SelectionMode="Single">
2020

2121
<CollectionView.ItemTemplate>
22-
<DataTemplate>
22+
<DataTemplate x:DataType="x:String">
2323
<VerticalStackLayout>
2424

2525
<VisualStateManager.VisualStateGroups>

src/Controls/tests/TestCases.HostApp/Issues/Issue22674.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4-
x:Class="Maui.Controls.Sample.Issues.Issue22674">
4+
x:Class="Maui.Controls.Sample.Issues.Issue22674"
5+
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
6+
x:DataType="local:Issue22674">
57
<CollectionView
68
AutomationId="TestCollectionView"
79
SelectionMode="Single"
810
ItemsSource="{Binding ItemList}"
911
SelectionChanged="OnCollectionViewSelectionChanged">
1012
<CollectionView.ItemTemplate>
11-
<DataTemplate>
13+
<DataTemplate x:DataType="x:String">
1214
<Label
1315
Text="{Binding .}"
1416
HorizontalTextAlignment="Center" />

src/Controls/tests/TestCases.HostApp/Issues/Issue23868.xaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
x:Class="Maui.Controls.Sample.Issues.Issue23868"
55
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
66
x:Name="ThisMainPage"
7-
Title="Main Page">
7+
Title="Main Page"
8+
x:DataType="local:Issue23868">
89
<StackLayout>
910
<Label Text="Pull to refresh twice to replicate the issue"
1011
HorizontalOptions="Center"
@@ -17,7 +18,7 @@
1718
<CollectionView.Header>
1819
<Grid ColumnDefinitions="2*,*"
1920
HorizontalOptions="CenterAndExpand"
20-
IsVisible="{Binding Source={x:Reference collectionView}, Path=ItemsSource.Count, FallbackValue=False}">
21+
IsVisible="{Binding Items.Count, FallbackValue=False}">
2122
<Label Grid.Column="0"
2223
Text="Items Count:"
2324
VerticalTextAlignment="Center"
@@ -29,7 +30,7 @@
2930
</Grid>
3031
</CollectionView.Header>
3132
<CollectionView.ItemTemplate>
32-
<DataTemplate>
33+
<DataTemplate x:DataType="x:String">
3334
<Label Text="{Binding}" HorizontalOptions="Center" VerticalOptions="Center"/>
3435
</DataTemplate>
3536
</CollectionView.ItemTemplate>

src/Controls/tests/TestCases.HostApp/Issues/Issue25201.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
HeightRequest="100"
1515
Padding="20"
1616
Source="dotnet_bot"
17-
IsVisible="{Binding Source={x:Reference Switch1}, Path=IsToggled}"
17+
IsVisible="{Binding IsToggled, Source={x:Reference Switch1}, x:DataType=Switch}"
1818
/>
1919

2020
<!-- https://github.com/dotnet/maui/issues/16713 -->
@@ -35,7 +35,7 @@
3535
AbsoluteLayout.LayoutFlags="SizeProportional"
3636
AbsoluteLayout.LayoutBounds="0,0,1.0,1.0"
3737
BackgroundColor="#80FFFFFF"
38-
IsVisible="{Binding Source={x:Reference Switch2}, Path=IsToggled}"
38+
IsVisible="{Binding IsToggled, Source={x:Reference Switch2}, x:DataType=Switch}"
3939
/>
4040
</AbsoluteLayout>
4141
</VerticalStackLayout>

src/Controls/tests/TestCases.HostApp/Issues/Issue25224.xaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
x:Class="Maui.Controls.Sample.Issues.Issue25224"
55
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
66
x:Name="ThisMainPage"
7-
Title="Main Page">
7+
Title="Main Page"
8+
x:DataType="local:Issue25224+Issue25224ViewModel">
89

910
<ContentPage.Resources>
1011
<DataTemplate x:Key="AdvancedTemplate">
@@ -42,15 +43,15 @@
4243
x:Name="searchBar"
4344
AutomationId="SearchBar"
4445
SearchCommand="{Binding FilterCommand}"
45-
SearchCommandParameter="{Binding Source={x:Reference searchBar}, Path=Text}"
46+
SearchCommandParameter="{Binding Text, Source={x:Reference searchBar}, x:DataType=SearchBar}"
4647
Placeholder="Filter" />
4748
<CollectionView Grid.Row="2"
4849
x:Name="collectionView"
4950
AutomationId="Success"
5051
ItemsSource="{Binding Monkeys}"
51-
EmptyView="{Binding Source={x:Reference searchBar}, Path=Text}">
52+
EmptyView="{Binding Text, Source={x:Reference searchBar}, x:DataType=SearchBar}">
5253
<CollectionView.ItemTemplate>
53-
<DataTemplate>
54+
<DataTemplate x:DataType="local:Monkey">
5455
<Grid Padding="10">
5556
<Grid.RowDefinitions>
5657
<RowDefinition Height="Auto" />

src/Controls/tests/TestCases.HostApp/Issues/Issue25362.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
x:Class="Maui.Controls.Sample.Issues.Issue25362"
5+
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
56
x:Name="Self"
6-
Title="Issue25362">
7+
Title="Issue25362"
8+
x:DataType="local:Issue25362">
79
<Grid RowDefinitions="Auto,*">
810
<HorizontalStackLayout Grid.Row="0">
911
<Button
@@ -19,9 +21,9 @@
1921

2022
<CollectionView.Header>
2123
<VerticalStackLayout>
22-
<VerticalStackLayout BindableLayout.ItemsSource="{Binding BindingContext.ItemListHeader, Source={x:Reference Self}}">
24+
<VerticalStackLayout BindableLayout.ItemsSource="{Binding ItemListHeader}">
2325
<BindableLayout.ItemTemplate>
24-
<DataTemplate>
26+
<DataTemplate x:DataType="x:String">
2527
<Label Padding="10" Text="{Binding .}" />
2628
</DataTemplate>
2729
</BindableLayout.ItemTemplate>
@@ -34,7 +36,7 @@
3436
</CollectionView.Header>
3537

3638
<CollectionView.ItemTemplate>
37-
<DataTemplate>
39+
<DataTemplate x:DataType="x:String">
3840
<Label Padding="10" Text="{Binding .}" />
3941
</DataTemplate>
4042
</CollectionView.ItemTemplate>

0 commit comments

Comments
 (0)