Enable compiled XAML bindings and fix MAUI deprecation warnings

Add x:DataType to all pages and controls for compiled bindings, migrate
from deprecated Application.Current.MainPage to Windows[0].Page API,
suppress expected analyzer warnings (XC0023, CS0618, CA1422), and add
Newtonsoft.Json dependency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gerwin Kuijntjes
2026-04-06 09:32:26 +02:00
parent fb504a88c2
commit 14d755f8bb
22 changed files with 74 additions and 30 deletions

View File

@@ -38,7 +38,9 @@ namespace Xamarin.Neo4j.Android
var statusBarColor = isDark
? AColor.ParseColor("#0c0c0c")
: AColor.ParseColor("#f5f5f5");
#pragma warning disable CA1422
Window.SetStatusBarColor(statusBarColor);
#pragma warning restore CA1422
var controller = new WindowInsetsControllerCompat(Window, Window.DecorView);
controller.AppearanceLightStatusBars = !isDark;
@@ -58,7 +60,7 @@ namespace Xamarin.Neo4j.Android
// MAUI creates its toolbar programmatically so theme-based tinting doesn't reach
// the overflow icon. Walk the view tree and apply the tint directly.
private static void TintToolbarIcons(ViewGroup? parent)
private static void TintToolbarIcons(ViewGroup parent)
{
if (parent == null) return;
for (var i = 0; i < parent.ChildCount; i++)

View File

@@ -22,11 +22,11 @@ namespace Xamarin.Neo4j.Android.Services
{
var context = global::Android.App.Application.Context;
var info = context.PackageManager.GetPackageInfo(context.PackageName, 0);
#pragma warning disable CS0618
#pragma warning disable CS0618, CA1416, CA1422
return Build.VERSION.SdkInt >= BuildVersionCodes.P
? info.LongVersionCode.ToString()
: info.VersionCode.ToString();
#pragma warning restore CS0618
#pragma warning restore CS0618, CA1416, CA1422
}
}
}

View File

@@ -21,7 +21,9 @@ namespace Xamarin.Neo4j
SetTheme(Current.RequestedTheme);
RequestedThemeChanged += (s, e) => SetTheme(e.RequestedTheme);
#pragma warning disable CS0618
MainPage = new NavigationPage(new ConnectionsPage());
#pragma warning restore CS0618
// SetTheme ran before MainPage was assigned, so apply bar colours now.
ApplyNavBarColors();
@@ -47,7 +49,7 @@ namespace Xamarin.Neo4j
// theme changes while the app is backgrounded are picked up on return.
public void ApplyNavBarColors()
{
if (MainPage is NavigationPage navPage)
if (Windows.Count > 0 && Windows[0].Page is NavigationPage navPage)
{
if (Resources.TryGetValue("NavigationBarColor", out var navColor) && navColor is Color color)
navPage.BarBackgroundColor = color;

View File

@@ -3,6 +3,8 @@
<ViewCell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:fonts="clr-namespace:Xamarin.Neo4j.Fonts;assembly=Xamarin.Neo4j"
xmlns:models="clr-namespace:Xamarin.Neo4j.Models;assembly=Xamarin.Neo4j"
x:DataType="models:Neo4jConnectionString"
x:Class="Xamarin.Neo4j.Controls.ConnectionCell">
<Grid Padding="15, 10">
<StackLayout Spacing="2">

View File

@@ -10,6 +10,7 @@ using Microsoft.Maui.Controls.Xaml;
namespace Xamarin.Neo4j.Controls
{
[XamlCompilation(XamlCompilationOptions.Compile)]
#pragma warning disable CS0618
public partial class ConnectionCell : ViewCell
{
public ConnectionCell()

View File

@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<ViewCell xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Xamarin.Neo4j.Controls.LicenseCell">
<ViewCell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:models="clr-namespace:Xamarin.Neo4j.Models;assembly=Xamarin.Neo4j"
x:DataType="models:License"
x:Class="Xamarin.Neo4j.Controls.LicenseCell">
<StackLayout Padding="15, 15, 15, 0">
<Label FontAttributes="Bold" TextColor="{DynamicResource Accent}" Text="{Binding Name}">
<Label.GestureRecognizers>

View File

@@ -10,6 +10,7 @@ using Microsoft.Maui.Controls.Xaml;
namespace Xamarin.Neo4j.Controls
{
[XamlCompilation(XamlCompilationOptions.Compile)]
#pragma warning disable CS0618
public partial class LicenseCell : ViewCell
{
public LicenseCell()

View File

@@ -2,12 +2,15 @@
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:models="clr-namespace:Xamarin.Neo4j.Models;assembly=Xamarin.Neo4j"
xmlns:controls="clr-namespace:Xamarin.Neo4j.Controls;assembly=Xamarin.Neo4j"
x:DataType="models:QueryResult"
x:Class="Xamarin.Neo4j.Controls.QueryResultView"
x:Name="self">
<Grid VerticalOptions="Start">
<!-- Graph WebView -->
<WebView x:Name="graphView"
<WebView x:Name="graphView" x:DataType="{x:Null}"
HorizontalOptions="FillAndExpand"
IsVisible="{Binding CanDisplayGraph}"
HeightRequest="{Binding GraphViewHeight, Source={x:Reference self}}" />

View File

@@ -666,7 +666,7 @@ namespace Xamarin.Neo4j.Fonts
public const string Divide = "\uf529";
public const string DoorClosed = "\uf52a";
public const string DoorOpen = "\uf52b";
public const string Equals = "\uf52c";
public new const string Equals = "\uf52c";
public const string Feather = "\uf52d";
public const string Frog = "\uf52e";
public const string GasPump = "\uf52f";

View File

@@ -18,5 +18,7 @@ namespace Xamarin.Neo4j.Models
public bool Default { get; set; }
public string DisplayName => Name + (Default ? " 🏠" : string.Empty);
public override string ToString() => DisplayName;
}
}

View File

@@ -3,6 +3,8 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:fonts="clr-namespace:Xamarin.Neo4j.Fonts;assembly=Xamarin.Neo4j"
xmlns:vm="clr-namespace:Xamarin.Neo4j.ViewModels;assembly=Xamarin.Neo4j"
x:DataType="vm:AddConnectionViewModel"
Title="Add Connection"
x:Class="Xamarin.Neo4j.Pages.AddConnectionPage">
<ContentPage.Content>

View File

@@ -3,6 +3,9 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:fonts="clr-namespace:Xamarin.Neo4j.Fonts;assembly=Xamarin.Neo4j"
xmlns:vm="clr-namespace:Xamarin.Neo4j.ViewModels;assembly=Xamarin.Neo4j"
xmlns:models="clr-namespace:Xamarin.Neo4j.Models;assembly=Xamarin.Neo4j"
x:DataType="vm:ConnectionsViewModel"
x:Class="Xamarin.Neo4j.Pages.ConnectionsPage"
x:Name="connectionsPage"
Title=" ">
@@ -33,7 +36,7 @@
<StackLayout BindableLayout.ItemsSource="{Binding ConnectionStrings}"
Spacing="0" Padding="0,16,0,80">
<BindableLayout.ItemTemplate>
<DataTemplate>
<DataTemplate x:DataType="models:Neo4jConnectionString">
<Border Margin="16,0,16,8"
BackgroundColor="{DynamicResource Extreme}"
Stroke="{DynamicResource QueryTextBorder}"
@@ -41,7 +44,7 @@
StrokeShape="RoundRectangle 10">
<Grid ColumnDefinitions="Auto,*,Auto" Padding="14,12">
<Grid.GestureRecognizers>
<TapGestureRecognizer
<TapGestureRecognizer x:DataType="{x:Null}"
Command="{Binding BindingContext.Commands[OpenConnection], Source={x:Reference connectionsPage}}"
CommandParameter="{Binding .}" />
</Grid.GestureRecognizers>
@@ -92,7 +95,7 @@
<!-- Edit / Delete -->
<StackLayout Grid.Column="2" Orientation="Horizontal" Spacing="0" VerticalOptions="Center">
<Button Text="{x:Static fonts:FontAwesomeSolid.PencilAlt}"
<Button x:DataType="{x:Null}" Text="{x:Static fonts:FontAwesomeSolid.PencilAlt}"
FontFamily="{StaticResource FontAwesomeSolid}"
FontSize="14"
WidthRequest="38" HeightRequest="38"
@@ -101,7 +104,7 @@
Padding="0"
Command="{Binding BindingContext.Commands[EditConnectionString], Source={x:Reference connectionsPage}}"
CommandParameter="{Binding .}" />
<Button Text="{x:Static fonts:FontAwesomeSolid.TrashAlt}"
<Button x:DataType="{x:Null}" Text="{x:Static fonts:FontAwesomeSolid.TrashAlt}"
FontFamily="{StaticResource FontAwesomeSolid}"
FontSize="14"
WidthRequest="38" HeightRequest="38"

View File

@@ -2,6 +2,8 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:vm="clr-namespace:Xamarin.Neo4j.ViewModels;assembly=Xamarin.Neo4j"
x:DataType="vm:GraphViewModel"
Title="Graph"
x:Class="Xamarin.Neo4j.Pages.GraphPage">
<ContentPage.Content>

View File

@@ -3,6 +3,8 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:Xamarin.Neo4j.Controls"
xmlns:vm="clr-namespace:Xamarin.Neo4j.ViewModels;assembly=Xamarin.Neo4j"
x:DataType="vm:LicensesViewModel"
Title="Software Licenses"
x:Class="Xamarin.Neo4j.Pages.LicensesPage">
<ContentPage.Content>

View File

@@ -3,6 +3,9 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:fonts="clr-namespace:Xamarin.Neo4j.Fonts;assembly=Xamarin.Neo4j"
xmlns:vm="clr-namespace:Xamarin.Neo4j.ViewModels;assembly=Xamarin.Neo4j"
xmlns:models="clr-namespace:Xamarin.Neo4j.Models;assembly=Xamarin.Neo4j"
x:DataType="vm:QueriesViewModel"
Title="Queries"
x:Name="queriesPage"
x:Class="Xamarin.Neo4j.Pages.QueriesPage">
@@ -17,10 +20,10 @@
<Grid>
<ListView ItemsSource="{Binding Queries}" ItemTapped="StartSessionWithQuery" IsVisible="{Binding HasItems}">
<ListView.ItemTemplate>
<DataTemplate>
<DataTemplate x:DataType="models:Query">
<TextCell Text="{Binding Name}" Detail="{Binding QueryText}">
<TextCell.ContextActions>
<MenuItem Text="Delete" Command="{Binding BindingContext.Commands[DeleteQuery], Source={x:Reference queriesPage} }" CommandParameter="{Binding .}" IsDestructive="true" />
<MenuItem x:DataType="{x:Null}" Text="Delete" Command="{Binding BindingContext.Commands[DeleteQuery], Source={x:Reference queriesPage} }" CommandParameter="{Binding .}" IsDestructive="true" />
</TextCell.ContextActions>
</TextCell>
</DataTemplate>

View File

@@ -4,6 +4,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:fonts="clr-namespace:Xamarin.Neo4j.Fonts;assembly=Xamarin.Neo4j"
xmlns:controls="clr-namespace:Xamarin.Neo4j.Controls;assembly=Xamarin.Neo4j"
xmlns:vm="clr-namespace:Xamarin.Neo4j.ViewModels;assembly=Xamarin.Neo4j"
xmlns:models="clr-namespace:Xamarin.Neo4j.Models;assembly=Xamarin.Neo4j"
x:DataType="vm:SessionViewModel"
x:Class="Xamarin.Neo4j.Pages.SessionPage"
x:Name="sessionPage">
<NavigationPage.TitleView>
@@ -21,7 +24,7 @@
</Label.FormattedText>
</Label>
<Picker x:Name="databasePicker" ItemsSource="{Binding AvailableDatabases}" ItemDisplayBinding="{Binding DisplayName}" SelectedItem="{Binding CurrentDatabase}" IsVisible="False" />
<Picker x:Name="databasePicker" ItemsSource="{Binding AvailableDatabases}" SelectedItem="{Binding CurrentDatabase}" IsVisible="False" />
</StackLayout>
</NavigationPage.TitleView>
@@ -82,11 +85,11 @@
IsVisible="{Binding HasSavedQueries}"
Spacing="0">
<BindableLayout.ItemTemplate>
<DataTemplate>
<DataTemplate x:DataType="models:Query">
<Grid ColumnDefinitions="*,Auto" Padding="0,10">
<StackLayout Grid.Column="0" Spacing="2">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
<TapGestureRecognizer x:DataType="{x:Null}"
Command="{Binding BindingContext.Commands[LoadQuery], Source={x:Reference sessionPage}}"
CommandParameter="{Binding .}" />
</StackLayout.GestureRecognizers>
@@ -97,7 +100,7 @@
MaxLines="1"
LineBreakMode="TailTruncation" />
</StackLayout>
<Button Grid.Column="1"
<Button Grid.Column="1" x:DataType="{x:Null}"
Text="{x:Static fonts:FontAwesomeSolid.TrashAlt}"
FontFamily="{StaticResource FontAwesomeSolid}"
FontSize="16"
@@ -144,7 +147,7 @@
<StackLayout BindableLayout.ItemsSource="{Binding QueryResults}" Spacing="0">
<BindableLayout.ItemTemplate>
<DataTemplate>
<DataTemplate x:DataType="models:QueryResult">
<Border Margin="12,0,12,6"
BackgroundColor="{DynamicResource Extreme}"
Stroke="{DynamicResource QueryTextBorder}"
@@ -152,7 +155,7 @@
StrokeShape="RoundRectangle 4">
<StackLayout Spacing="0">
<!-- Action row -->
<Grid ColumnDefinitions="*,*,*,*,Auto" Padding="4,0">
<Grid ColumnDefinitions="*,*,*,*,Auto" Padding="4,0" x:DataType="{x:Null}">
<Button Grid.Column="0"
Text="{x:Static fonts:FontAwesomeSolid.Star}"
FontFamily="{StaticResource FontAwesomeSolid}" FontSize="13"
@@ -204,14 +207,14 @@
LineBreakMode="TailTruncation"
MaxLines="1">
<Label.GestureRecognizers>
<TapGestureRecognizer
<TapGestureRecognizer x:DataType="{x:Null}"
Command="{Binding BindingContext.Commands[LoadResultQuery], Source={x:Reference sessionPage}}"
CommandParameter="{Binding .}" />
</Label.GestureRecognizers>
</Label>
<!-- Result content -->
<controls:QueryResultView
<controls:QueryResultView x:DataType="{x:Null}"
GraphViewHeight="{Binding BindingContext.GraphViewHeight, Source={x:Reference sessionPage}}" />
</StackLayout>
</Border>

View File

@@ -3,6 +3,8 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:fonts="clr-namespace:Xamarin.Neo4j.Fonts;assembly=Xamarin.Neo4j"
xmlns:vm="clr-namespace:Xamarin.Neo4j.ViewModels;assembly=Xamarin.Neo4j"
x:DataType="vm:SettingsViewModel"
Title="Settings"
x:Class="Xamarin.Neo4j.Pages.SettingsPage">
<ContentPage.IconImageSource>

View File

@@ -48,7 +48,7 @@ namespace Xamarin.Neo4j.ViewModels
var (_, message) = await _neo4jService.EstablishConnection(connectionString);
await Application.Current.MainPage.DisplayAlert("", message, "OK");
await Application.Current.Windows[0].Page.DisplayAlertAsync("", message, "OK");
}));
Commands.Add("Save", new Command(async () =>
@@ -76,7 +76,7 @@ namespace Xamarin.Neo4j.ViewModels
await Navigation.PushAsync(new SessionPage(connectionString));
else
await Application.Current.MainPage.DisplayAlert("", message, "OK");
await Application.Current.Windows[0].Page.DisplayAlertAsync("", message, "OK");
}));
}

View File

@@ -42,7 +42,7 @@ namespace Xamarin.Neo4j.ViewModels
{
if (ConnectionStringManager.ActiveConnectionString == null)
{
await Application.Current.MainPage.DisplayAlert("", "Please select a connection before starting a session.", "OK");
await Application.Current.Windows[0].Page.DisplayAlertAsync("", "Please select a connection before starting a session.", "OK");
return;
}

View File

@@ -82,7 +82,7 @@ namespace Xamarin.Neo4j.ViewModels
if (!(o is Query query))
return;
var confirmed = await Application.Current.MainPage.DisplayAlert(
var confirmed = await Application.Current.Windows[0].Page.DisplayAlertAsync(
"Delete Query",
$"Delete \"{query.Name}\"?",
"Delete", "Cancel");
@@ -115,7 +115,7 @@ namespace Xamarin.Neo4j.ViewModels
Commands.Add("SaveQuery", new Command(async (o) =>
{
if (!(o is QueryResult result)) return;
var name = await Application.Current.MainPage.DisplayPromptAsync(
var name = await Application.Current.Windows[0].Page.DisplayPromptAsync(
"Save Query", "What would you like to call this query?");
if (!string.IsNullOrWhiteSpace(name))
{
@@ -163,7 +163,7 @@ namespace Xamarin.Neo4j.ViewModels
if (!isConnected)
{
await Application.Current.MainPage.DisplayAlert("", message, "OK");
await Application.Current.Windows[0].Page.DisplayAlertAsync("", message, "OK");
return;
}

View File

@@ -77,7 +77,7 @@ namespace Xamarin.Neo4j.ViewModels
if (!Email.Default.IsComposeSupported)
{
await Application.Current.MainPage.DisplayAlert(
await Application.Current.Windows[0].Page.DisplayAlertAsync(
"No Email App", "No email client is configured on this device.", "OK");
return;
}
@@ -96,7 +96,7 @@ namespace Xamarin.Neo4j.ViewModels
Commands.Add("ClearConnections", new Command(async () =>
{
var clear = await Application.Current.MainPage.DisplayAlert(
var clear = await Application.Current.Windows[0].Page.DisplayAlertAsync(
"Clear Connections",
"Are you sure you want to remove all saved connections?",
"Clear", "Cancel");
@@ -109,7 +109,7 @@ namespace Xamarin.Neo4j.ViewModels
Commands.Add("ClearQueries", new Command(async () =>
{
var clear = await Application.Current.MainPage.DisplayAlert(
var clear = await Application.Current.Windows[0].Page.DisplayAlertAsync(
"Clear Saved Queries",
"Are you sure you want to remove all saved queries?",
"Clear", "Cancel");

View File

@@ -5,6 +5,15 @@
<UseMaui>true</UseMaui>
<LangVersion>latest</LangVersion>
<Nullable>disable</Nullable>
<MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation>
<!-- XC0023: elements inside DataTemplates that bind to both the item model and the parent
page ViewModel via Source={x:Reference} cannot share a single compiled DataType.
x:DataType="{x:Null}" on those elements is intentional; suppress the hint. -->
<NoWarn>$(NoWarn);XC0023</NoWarn>
<!-- CS0618: ViewCell is deprecated but converting ListView to CollectionView is a larger
refactor. The MAUI XAML source generator emits this on the generated partial class
for ConnectionCell/LicenseCell which we cannot annotate directly. -->
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -15,6 +24,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="10.0.20" />
<PackageReference Include="Neo4jClient" Version="4.1.18" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>