Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />
<Import Condition="'$(EnvironmentBuildPropsImported)' != 'True'" Project="$(MSBuildThisFileDirectory)eng\Environment.Build.props" />

<PropertyGroup>
<!--
Keep backward compatibility with XamlC, XamlCompilationAttribute, and xaml-comp processing instruction
When we're ready to turn this off, we can remove all code depending on this condition, and drop this property group
-->

<_MauiXamlSourceGenBackCompat>true</_MauiXamlSourceGenBackCompat>
<DefineConstants Condition=" '$(_MauiXamlSourceGenBackCompat)' == 'true' ">$(DefineConstants);_MAUIXAML_SOURCEGEN_BACKCOMPAT</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- Detailed trimmer warnings, if present -->
Expand Down
36 changes: 36 additions & 0 deletions docs/design/FeatureSwitches.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The following switches are toggled for applications running on Mono for `TrimMod

| MSBuild Property Name | AppContext Setting | Description |
|-|-|-|
| MauiXamlInflator | N/A | Controls how XAML files are processed. See [XAML Inflator](#mauixamlinflator) section below. |
| MauiEnableIVisualAssemblyScanning | Microsoft.Maui.RuntimeFeature.IsIVisualAssemblyScanningEnabled | When enabled, MAUI will scan assemblies for types implementing `IVisual` and for `[assembly: Visual(...)]` attributes and register these types. |
| MauiShellSearchResultsRendererDisplayMemberNameSupported | Microsoft.Maui.RuntimeFeature.IsShellSearchResultsRendererDisplayMemberNameSupported | When disabled, it is necessary to always set `ItemTemplate` of any `SearchHandler`. Displaying search results through `DisplayMemberName` will not work. |
| MauiQueryPropertyAttributeSupport | Microsoft.Maui.RuntimeFeature.IsQueryPropertyAttributeSupported | When disabled, the `[QueryProperty(...)]` attributes won't be used to set values to properties when navigating. |
Expand All @@ -18,6 +19,41 @@ The following switches are toggled for applications running on Mono for `TrimMod
| EnableMauiDiagnostics | Microsoft.Maui.RuntimeFeature.EnableMauiDiagnostics | Enables MAUI specific diagnostics, like VisualDiagnostics and BindingDiagnostics. Defaults to EnableDiagnostics |
| _EnableMauiAspire | Microsoft.Maui.RuntimeFeature.EnableMauiAspire | When enabled, MAUI Aspire integration features are available. **Warning**: Using Aspire outside of Debug configuration may introduce performance and security risks in production. |

## MauiXamlInflator

Controls how XAML files are processed and compiled. Starting with .NET 11, the default value is `SourceGen`.

**Available Values:**
- `SourceGen` (default) - XAML is compiled to C# at build time using a source generator. This provides the best performance and debugging experience, including full XAML Hot Reload support.
- `Runtime` - XAML is inflated at runtime. This has negative performance impact and is deprecated.
- `XamlC` - XAML is compiled using the XamlC IL weaver after compilation. This prevents some debugging capabilities like XAML Hot Reload and is deprecated.

**Example:**
```xml
<PropertyGroup>
<!-- Use default (SourceGen) - recommended -->
<!-- No need to specify MauiXamlInflator -->

<!-- Or explicitly set deprecated inflators (will produce warning MAUI1001) -->
<MauiXamlInflator>Runtime</MauiXamlInflator>
</PropertyGroup>
```

**Per-file override:**
You can override the inflator for individual XAML files using item metadata:
```xml
<ItemGroup>
<MauiXaml Update="MyPage.xaml" Inflator="Runtime" />
</ItemGroup>
```

**Changes in .NET 11:**
- The default inflator changed from configuration-based (Runtime in Debug, XamlC in Release) to `SourceGen` for all configurations.
- The `[XamlCompilation]` attribute is deprecated (produces warning) but still functional.

**Changes in .NET 12:**
- The `[XamlCompilation]` attribute will be obsolete with `error: true` and becomes a no-op. Use MSBuild properties or item metadata instead.

## MauiEnableIVisualAssemblyScanning

When this feature is not enabled, custom and third party `IVisual` types will not be automatically discovered and registered.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<Nullable>enable</Nullable>
<MauiEnablePlatformUsings>true</MauiEnablePlatformUsings>
<NoWarn>$(NoWarn);XC0022</NoWarn>
<!-- This sample has nullability mismatches - use Runtime inflation -->
<MauiXamlInflator>Runtime</MauiXamlInflator>

<!-- Display name -->
<ApplicationTitle>.NET MAUI Embedding</ApplicationTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<IsPackable>false</IsPackable>
<EmitCompilerGeneratedFiles Condition="'$(Configuration)' == 'Debug'">true</EmitCompilerGeneratedFiles>
<NoWarn>$(NoWarn);XC0022</NoWarn>
<!-- This sample uses deprecated APIs - use Runtime inflation -->
<MauiXamlInflator>Runtime</MauiXamlInflator>
<!-- Disable multi-RID builds to workaround a parallel build issue -->
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst'))">maccatalyst-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst')) and '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'arm64'">maccatalyst-arm64</RuntimeIdentifier>
Expand Down
3 changes: 0 additions & 3 deletions src/Controls/samples/Controls.Sample.Profiling/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Microsoft.Maui;
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Hosting;

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]

namespace Maui.Controls.Sample.Profiling
{
public static class MauiProgram
Expand Down
49 changes: 49 additions & 0 deletions src/Controls/samples/Controls.Sample/Maui.Controls.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,53 @@

<Import Project="$(MauiSrcDirectory)Maui.InTree.props" Condition=" '$(UseMaui)' != 'true' " />

<!-- These XAML files have XSG parsing issues, use Runtime inflator until fixed -->
<!-- Must be after Maui.InTree.props to properly override the globbed items -->
<ItemGroup>
<MauiXaml Remove="Pages/Controls/SwipeViewGalleries/*.xaml;Pages/Others/StyleSheetsPage.xaml;Pages/Others/TwoPaneViewPage.xaml;Pages/Controls/ButtonPage.xaml;Pages/Controls/RadioButtonGalleries/RadioButtonContentGallery.xaml" />
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long semicolon-separated list of paths is difficult to maintain. Consider using separate <MauiXaml Remove> elements for each path or pattern for better readability.

Suggested change
<MauiXaml Remove="Pages/Controls/SwipeViewGalleries/*.xaml;Pages/Others/StyleSheetsPage.xaml;Pages/Others/TwoPaneViewPage.xaml;Pages/Controls/ButtonPage.xaml;Pages/Controls/RadioButtonGalleries/RadioButtonContentGallery.xaml" />
<MauiXaml Remove="Pages/Controls/SwipeViewGalleries/*.xaml" />
<MauiXaml Remove="Pages/Others/StyleSheetsPage.xaml" />
<MauiXaml Remove="Pages/Others/TwoPaneViewPage.xaml" />
<MauiXaml Remove="Pages/Controls/ButtonPage.xaml" />
<MauiXaml Remove="Pages/Controls/RadioButtonGalleries/RadioButtonContentGallery.xaml" />

Copilot uses AI. Check for mistakes.
<MauiXaml Include="Pages/Controls/SwipeViewGalleries/*.xaml" Inflator="Runtime" />
<MauiXaml Include="Pages/Others/StyleSheetsPage.xaml" Inflator="Runtime" />
<MauiXaml Include="Pages/Others/TwoPaneViewPage.xaml" Inflator="Runtime" />
<MauiXaml Include="Pages/Controls/ButtonPage.xaml" Inflator="Runtime" />
<MauiXaml Include="Pages/Controls/RadioButtonGalleries/RadioButtonContentGallery.xaml" Inflator="Runtime" />
</ItemGroup>

<!-- These XAML files use obsolete APIs (Device, NamedSize) intentionally for demonstration -->
<ItemGroup>
<MauiXaml Update="AppResources.xaml" NoWarn="0612" />
<MauiXaml Update="Controls/CardView/CardView.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/AppShell.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Compatibility/ListViewPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/CompatibilityPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/CollectionViewGalleries/CarouselViewGalleries/CarouselViewPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/CollectionViewGalleries/SelectionGalleries/VisualStatesGallery.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/EditorPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/IndicatorPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/RadioButtonGalleries/ContentProperties.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/RadioButtonGalleries/RadioButtonGroupGalleryPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/ShapesGalleries/ClipCornerRadiusGallery.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/ShapesGalleries/ClipGallery.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/ShapesGalleries/InvalidateClipGallery.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/SliderPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Controls/StepperPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/ControlsPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Core/BorderGalleries/BorderLayout.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Core/DispatcherPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Core/GesturesPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Core/ShadowGalleries/ShadowPlaygroundPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/CorePage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Layouts/FlexLayoutPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Layouts/ScrollViewPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/Layouts/ScrollViewPages/ScrollToEndPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/LayoutsPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/MainPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/OthersPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/PlatformSpecifics/Windows/WindowsDragAndDropCustomization.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/PlatformSpecifics/iOS/iOSDragAndDropRequestFullSize.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/PlatformSpecificsPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/UserInterface/FontsPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/UserInterface/VisualStatesPage.xaml" NoWarn="0612" />
<MauiXaml Update="Pages/UserInterfacePage.xaml" NoWarn="0612" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public AppShell()

public string ShellTitle { get; set; } = "Welcome to Shell";

void OnChangeTabBarBackgroundColor(object sender, EventArgs e)
void OnChangeTabBarBackgroundColor(object? sender, EventArgs e)
{
var random = new Random();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public ListViewContextActions()
.ToList();
}

private void OnDetailClicked(object sender, EventArgs e)
private void OnDetailClicked(object? sender, EventArgs e)
{
var mi = ((MenuItem)sender);
var mi = ((MenuItem)sender!);
DisplayAlertAsync("Detail Action", $"Details for item {mi.CommandParameter}", "OK");
}

private void OnDeleteClicked(object sender, EventArgs e)
private void OnDeleteClicked(object? sender, EventArgs e)
{
var mi = ((MenuItem)sender);
var mi = ((MenuItem)sender!);
DisplayAlertAsync("Delete Action", $"Deleting item {mi.CommandParameter}!", "OK");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void SetNewMainPage(Page page)
Application.Current!.Windows[0].Page = page;
}

void OnTabbedPageAsRoot(object sender, EventArgs e)
void OnTabbedPageAsRoot(object? sender, EventArgs e)
{
var topTabs =
new TabbedPage()
Expand All @@ -37,7 +37,7 @@ void OnTabbedPageAsRoot(object sender, EventArgs e)
SetNewMainPage(topTabs);
}

void OnSetToBottomTabs(object sender, EventArgs e)
void OnSetToBottomTabs(object? sender, EventArgs e)
{
var bottomTabs = new TabbedPage()
{
Expand All @@ -53,60 +53,60 @@ void OnSetToBottomTabs(object sender, EventArgs e)
this.Window!.Page = bottomTabs;
}

void OnChangeTabIndex(object sender, EventArgs e)
void OnChangeTabIndex(object? sender, EventArgs e)
{
GetTabbedPage().CurrentPage = GetTabbedPage().Children[1];
}

void OnToggleTabBar(object sender, EventArgs e)
void OnToggleTabBar(object? sender, EventArgs e)
{
if ((GetTabbedPage().BarBackground as SolidColorBrush)?.Color == SolidColorBrush.Purple.Color)
GetTabbedPage().BarBackground = null;
else
GetTabbedPage().BarBackground = SolidColorBrush.Purple;
}

void OnToggleTabBarTextColor(object sender, EventArgs e)
void OnToggleTabBarTextColor(object? sender, EventArgs e)
{
if (GetTabbedPage().BarTextColor == Colors.Green)
GetTabbedPage().BarTextColor = null;
else
GetTabbedPage().BarTextColor = Colors.Green;
}

void OnToggleTabItemUnSelectedColor(object sender, EventArgs e)
void OnToggleTabItemUnSelectedColor(object? sender, EventArgs e)
{
if (GetTabbedPage().UnselectedTabColor == Colors.Blue)
GetTabbedPage().UnselectedTabColor = null;
else
GetTabbedPage().UnselectedTabColor = Colors.Blue;
}

void OnToggleTabItemSelectedColor(object sender, EventArgs e)
void OnToggleTabItemSelectedColor(object? sender, EventArgs e)
{
if (GetTabbedPage().SelectedTabColor == Colors.Pink)
GetTabbedPage().SelectedTabColor = null;
else
GetTabbedPage().SelectedTabColor = Colors.Pink;
}

void OnRemoveTab(object sender, EventArgs e)
void OnRemoveTab(object? sender, EventArgs e)
{
if (GetTabbedPage().Children.LastOrDefault() is TabbedPageGalleryMainPage mainPage)
{
GetTabbedPage().Children.Remove(mainPage);
}
}

void OnRemoveAllTabs(object sender, EventArgs e)
void OnRemoveAllTabs(object? sender, EventArgs e)
{
while (GetTabbedPage().Children.LastOrDefault() is TabbedPageGalleryMainPage mainPage)
{
GetTabbedPage().Children.Remove(mainPage);
}
}

void OnAddTab(object sender, EventArgs e)
void OnAddTab(object? sender, EventArgs e)
{
GetTabbedPage()
.Children
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public ButtonPage()
BindingContext = new ButtonPageViewModel();
}

void OnButtonClicked(object sender, System.EventArgs e)
void OnButtonClicked(object? sender, System.EventArgs e)
{
Debug.WriteLine("Clicked");
}

void Button_Clicked(System.Object sender, System.EventArgs e)
void Button_Clicked(System.Object? sender, System.EventArgs e)
{
if (ImageSourceButton.ImageSource is null)
{
Expand All @@ -36,7 +36,7 @@ void Button_Clicked(System.Object sender, System.EventArgs e)
}
}

void OnPositionChange(object sender, System.EventArgs e)
void OnPositionChange(object? sender, System.EventArgs e)
{
var newPosition = ((int)positionChange.ContentLayout.Position) + 1;

Expand All @@ -48,21 +48,21 @@ void OnPositionChange(object sender, System.EventArgs e)
positionChange.ContentLayout.Spacing);
}

void OnDecreaseSpacing(object sender, System.EventArgs e)
void OnDecreaseSpacing(object? sender, System.EventArgs e)
{
positionChange.ContentLayout =
new Button.ButtonContentLayout(positionChange.ContentLayout.Position,
positionChange.ContentLayout.Spacing - 1);
}

void OnIncreasingSpacing(object sender, System.EventArgs e)
void OnIncreasingSpacing(object? sender, System.EventArgs e)
{
positionChange.ContentLayout =
new Button.ButtonContentLayout(positionChange.ContentLayout.Position,
positionChange.ContentLayout.Spacing + 1);
}

void OnLineBreakModeButtonClicked(object sender, System.EventArgs e)
void OnLineBreakModeButtonClicked(object? sender, System.EventArgs e)
{
LineBreakModeButton.LineBreakMode = ImageLineBreakModeButton.LineBreakMode = SelectLineBreakMode();
}
Expand Down Expand Up @@ -90,13 +90,13 @@ LineBreakMode SelectLineBreakMode()

int _backgroundCount;

void OnBackgroundButtonClicked(object sender, System.EventArgs e)
void OnBackgroundButtonClicked(object? sender, System.EventArgs e)
{
BackgroundButton.Text = $"Background tapped {_backgroundCount} times";
_backgroundCount++;
}

void OnChangeBrushButtonClicked(System.Object sender, System.EventArgs e)
void OnChangeBrushButtonClicked(System.Object? sender, System.EventArgs e)
{
UpdateButtonBrush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public CheckBoxPage()
UpdateControls();
}

void OnChangeIsCheckedButtonClicked(object sender, EventArgs e)
void OnChangeIsCheckedButtonClicked(object? sender, EventArgs e)
{
_isGreen = !_isGreen;
UpdateControls();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public CarouselViewPage()
InitializeComponent();
}

async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
async void TapGestureRecognizer_Tapped(object? sender, EventArgs e)
{
await DisplayAlertAsync("Item", "Tapped", "Successfully");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public bool ShouldTriggerReset
set => SetValue(ref _shouldTriggerReset, value);
}

void Insert_OnClicked(object sender, EventArgs e)
void Insert_OnClicked(object? sender, EventArgs e)
{
if (!IsValid(out var index))
return;

Items.Insert(index, CreateDrink());
}

void Add_OnClicked(object sender, EventArgs e)
void Add_OnClicked(object? sender, EventArgs e)
{
if (!IsValid(out var _))
return;
Expand All @@ -89,7 +89,7 @@ void SetValue<T>(ref T backingField, in T value, [CallerMemberName] string calle
OnPropertyChanged(callerName);
}

void Remove_OnClicked(object sender, EventArgs e)
void Remove_OnClicked(object? sender, EventArgs e)
{
if (!IsValid(out var index))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public EmptyViewRTLGallery()
SearchBar.SearchCommand = new Command(() => _demoFilteredItemSource.FilterItems(SearchBar.Text));
}

void OnPickerSelectedIndexChanged(object sender, EventArgs e)
void OnPickerSelectedIndexChanged(object? sender, EventArgs e)
{
switch (Picker.SelectedIndex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public static DataTemplate GroupFooterTemplate()
});
}

static void More_Clicked(object sender, EventArgs e)
static void More_Clicked(object? sender, EventArgs e)
{
throw new NotImplementedException();
}
Expand Down
Loading
Loading