Hello happy new year to everyone
I am trying to increase performance on my xaml
Since I updated to .Net 9, I got this warning
Binding was not compiled because it has an explicitly set Source property and compilation of bindings with Source is not enabled. Consider enabling this optimization by setting the <MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation> in your project file and make sure the correct x:DataType is specified for this binding. See https://zcusa.951200.xyz/dotnet/maui/fundamentals/data-binding/compiled-bindings for more information.
<Shell
x:Class="METROWIND.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:METROWIND.Controls"
xmlns:local="clr-namespace:METROWIND"
xmlns:popup="clr-namespace:Syncfusion.Maui.Popup;assembly=Syncfusion.Maui.Popup"
xmlns:rex="clr-namespace:METROWIND.Resources"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:views="clr-namespace:METROWIND.Views"
xmlns:vm="clr-namespace:METROWIND.ViewModel"
x:Name="shelly"
x:DataType="vm:AppShellViewModel"
Shell.FlyoutBehavior="{OnIdiom Desktop=Locked,
Phone=Disabled}">
<Shell.Behaviors>
<toolkit:EventToCommandBehavior
Command="{Binding AppearingCommand}"
CommandParameter="{Binding Source={x:Reference shelly}}"
EventName="Appearing" />
</Shell.Behaviors>
<Shell.FlyoutHeader>
<Grid>
<Image
x:Name="ConfigMenu"
Margin="10,10,0,15"
HeightRequest="48"
HorizontalOptions="Start"
Source="windmill.png"
WidthRequest="48">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding OpenMenuCommand}" />
</Image.GestureRecognizers>
</Image>
<popup:SfPopup
Padding="5"
AbsoluteY="5"
AutoSizeMode="Both"
IsOpen="{Binding IsMenuPopUpOpen}"
RelativePosition="AlignToRightOf"
RelativeView="{x:Reference ConfigMenu}"
ShowHeader="False"
ShowOverlayAlways="False">
<popup:SfPopup.PopupStyle>
<popup:PopupStyle CornerRadius="8" />
</popup:SfPopup.PopupStyle>
<popup:SfPopup.ContentTemplate>
<DataTemplate>
<HorizontalStackLayout
BackgroundColor="#908686"
WidthRequest="180">
<Label
Margin="10,0,0,0"
Text="{x:Static rex:AppResource.CompactMode}"
VerticalTextAlignment="Center" />
<controls:CustomSwitch
Margin="10,0,0,0"
IsToggled="{Binding IsCompactMode}"
OnColor="#4E2B75">
<Switch.Behaviors>
<toolkit:EventToCommandBehavior
Command="{Binding ToggleSwitchCommand}"
CommandParameter="{Binding IsCompactMode}"
EventName="Toggled" />
</Switch.Behaviors>
</controls:CustomSwitch>
</HorizontalStackLayout>
</DataTemplate>
</popup:SfPopup.ContentTemplate>
</popup:SfPopup>
</Grid>
</Shell.FlyoutHeader>
So, I did
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->
<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
<OutputType>Exe</OutputType>
<RootNamespace>METROWIND</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation>
Now I am getting an error, where _shell
public partial class AppShellViewModel: ObservableObject, IPinClickHandler
{
private void TurbineService_NoInternet()
{
_noInternetPopUp.Show();
}
private void InitializeCommand()
{
_commandHandler.SetPinClickedCommand(new Command<TurbinePin>(async (pin) =>
await PinMarkerClicked(pin)));
}
[RelayCommand]
async Task Appearing(AppShell appShell)
{
_shell = appShell;
try
{
if (TurbinePins.Count == 0 && !isInitializing)
{
isInitializing = true;
await _turbineService.InitializeAsync();
isInitializing = false;
}
}
catch (Exception ex)
{
Debug.WriteLine($"Initialization failed: {ex.Message}");
isInitializing = false;
}
}
private void Connectivity_ConnectivityChanged(object? sender, ConnectivityChangedEventArgs e)
{
HandleConnectivityChangeAsync();
}
private async void HandleConnectivityChangeAsync()
{
if (_connectivity.NetworkAccess == NetworkAccess.Internet)
{
_noInternetPopUp.IsOpen = false;
try
{
if (TurbinePins.Count == 0 && !isInitializing)
{
isInitializing = true;
await _turbineService.InitializeAsync();
isInitializing = false;
}
}
catch (Exception ex)
{
Debug.WriteLine($"Initialization failed: {ex.Message}");
isInitializing = false;
}
}
else
{
TurbineService_NoInternet();
}
}
[RelayCommand]
void OpenMenu()
{
IsMenuPopUpOpen = true;
}
[RelayCommand]
void ToggleSwitch()
{
if (IsCompactMode)
{
_shell!.FlyoutWidth = 65;
}
else
{
_shell!.FlyoutWidth = 300;
}
IsMenuPopUpOpen = false;
}