Skip to content
Open
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
158 changes: 156 additions & 2 deletions src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,157 @@
<ContentPage x:Class="Maui.Controls.Sample.MainPage"
xmlns:local="clr-namespace:Maui.Controls.Sample">
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.MainPage"
xmlns:local="clr-namespace:Maui.Controls.Sample"
Title="XAML Incremental Hot Reload Sandbox"
BackgroundColor="White">

<ScrollView Padding="20">
<VerticalStackLayout Spacing="15">

<!-- Header -->
<Label Text="🔥 Incremental Hot Reload Sandbox"
FontSize="24"
FontAttributes="Bold"
HorizontalOptions="Center"
TextColor="DarkSlateBlue" />

<Label Text="Edit this XAML while the app is running to test incremental hot reload. Property changes (text, colors, sizes) should apply without a full page reload."
FontSize="14"
TextColor="Gray"
HorizontalOptions="Center"
HorizontalTextAlignment="Center" />

<BoxView HeightRequest="1" Color="LightGray" />

<!-- Section 1: Simple property changes -->
<Label Text="1. Simple Properties"
FontSize="18"
FontAttributes="Bold"
TextColor="DarkSlateBlue" />

<Label x:Name="TestLabel"
Text="Try changing this text!"
FontSize="20"
TextColor="CornflowerBlue"
HorizontalOptions="Center" />

<Button x:Name="TestButton"
Text="Button — change my text or color"
BackgroundColor="MediumSlateBlue"
TextColor="White"
FontSize="16"
CornerRadius="10"
Padding="15,10"
HorizontalOptions="Center"
Clicked="OnTestButtonClicked" />

<Label x:Name="ClickCountLabel"
Text="Clicks: 0"
FontSize="14"
TextColor="Gray"
HorizontalOptions="Center" />

<BoxView HeightRequest="1" Color="LightGray" />

<!-- Section 2: Numeric properties -->
<Label Text="2. Numeric Properties"
FontSize="18"
FontAttributes="Bold"
TextColor="DarkSlateBlue" />

<BoxView x:Name="ColorBox"
HeightRequest="60"
WidthRequest="200"
CornerRadius="12"
Color="Coral"
HorizontalOptions="Center" />

<ProgressBar x:Name="TestProgress"
Progress="0.65"
ProgressColor="MediumSlateBlue"
HorizontalOptions="Fill" />

<BoxView HeightRequest="1" Color="LightGray" />

<!-- Section 3: Layout with children -->
<Label Text="3. Layout Children"
FontSize="18"
FontAttributes="Bold"
TextColor="DarkSlateBlue" />

<HorizontalStackLayout x:Name="ChipContainer"
Spacing="8"
HorizontalOptions="Center">
<Border BackgroundColor="LightCoral" StrokeShape="RoundRectangle 15" Stroke="Transparent" Padding="10,5">
<Label Text="Chip A" TextColor="White" FontSize="12" />
</Border>
<Border BackgroundColor="CornflowerBlue" StrokeShape="RoundRectangle 15" Stroke="Transparent" Padding="10,5">
<Label Text="Chip B" TextColor="White" FontSize="12" />
</Border>
<Border BackgroundColor="MediumSeaGreen" StrokeShape="RoundRectangle 15" Stroke="Transparent" Padding="10,5">
<Label Text="Chip C" TextColor="White" FontSize="12" />
</Border>
</HorizontalStackLayout>

<Label Text="Try: add/remove/reorder chips above"
FontSize="12"
TextColor="Silver"
HorizontalTextAlignment="Center"
HorizontalOptions="Center" />

<BoxView HeightRequest="1" Color="LightGray" />

<!-- Section 4: Grid layout -->
<Label Text="4. Grid Layout"
FontSize="18"
FontAttributes="Bold"
TextColor="DarkSlateBlue" />

<Grid ColumnDefinitions="*,*"
RowDefinitions="Auto,Auto"
ColumnSpacing="10"
RowSpacing="10">
<Border BackgroundColor="#F0F4FF" StrokeShape="RoundRectangle 8" Stroke="Transparent" Padding="15">
<VerticalStackLayout Spacing="5">
<Label Text="📊" FontSize="28" HorizontalOptions="Center" />
<Label Text="Card 1" FontAttributes="Bold" HorizontalTextAlignment="Center" />
<Label Text="Change my text" FontSize="12" TextColor="Gray" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
<Border Grid.Column="1" BackgroundColor="#FFF4F0" StrokeShape="RoundRectangle 8" Stroke="Transparent" Padding="15">
<VerticalStackLayout Spacing="5">
<Label Text="🎨" FontSize="28" HorizontalOptions="Center" />
<Label Text="Card 2" FontAttributes="Bold" HorizontalTextAlignment="Center" />
<Label Text="Change my color" FontSize="12" TextColor="Gray" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
<Border Grid.Row="1" BackgroundColor="#F0FFF4" StrokeShape="RoundRectangle 8" Stroke="Transparent" Padding="15">
<VerticalStackLayout Spacing="5">
<Label Text="🚀" FontSize="28" HorizontalOptions="Center" />
<Label Text="Card 3" FontAttributes="Bold" HorizontalTextAlignment="Center" />
<Label Text="Change my emoji" FontSize="12" TextColor="Gray" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
<Border Grid.Row="1" Grid.Column="1" BackgroundColor="#FFF0FF" StrokeShape="RoundRectangle 8" Stroke="Transparent" Padding="15">
<VerticalStackLayout Spacing="5">
<Label Text="⚡" FontSize="28" HorizontalOptions="Center" />
<Label Text="Card 4" FontAttributes="Bold" HorizontalTextAlignment="Center" />
<Label Text="Add more cards!" FontSize="12" TextColor="Gray" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
</Grid>

<BoxView HeightRequest="1" Color="LightGray" />

<!-- Section 5: Version info -->
<Label x:Name="VersionLabel"
Text="Version info will appear here"
FontSize="12"
TextColor="Silver"
HorizontalOptions="Center"
HorizontalTextAlignment="Center" />

</VerticalStackLayout>
</ScrollView>

</ContentPage>
36 changes: 35 additions & 1 deletion src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
namespace Maui.Controls.Sample;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample;

public partial class MainPage : ContentPage
{
int _clickCount;

public MainPage()
{
InitializeComponent();
UpdateVersionInfo();
}

void OnTestButtonClicked(object? sender, EventArgs e)
{
_clickCount++;
ClickCountLabel.Text = $"Clicks: {_clickCount}";
}

void UpdateVersionInfo()
{
// Show whether incremental hot reload infrastructure is active
var registryType = typeof(XamlComponentRegistry);
var hasRegistry = registryType != null;

// Check if __version field exists (generated when EnableMauiIncrementalHotReload=true)
var versionField = GetType().GetField("__version",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var hasVersionField = versionField != null;
var currentVersion = hasVersionField ? versionField!.GetValue(this) : "N/A";

// Check if UpdateComponent method exists
var ucMethod = GetType().GetMethod("UpdateComponent",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance,
null, Type.EmptyTypes, null);
var hasUC = ucMethod != null;

VersionLabel.Text = $"Registry: {(hasRegistry ? "✅" : "❌")} | " +
$"__version field: {(hasVersionField ? "✅" : "❌")} (={currentVersion}) | " +
$"UpdateComponent: {(hasUC ? "✅" : "❌")}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<!-- NOTE: By default the UseMaterial3 flag value is false. If you change the UseMaterial3 flag, you MUST delete the artifacts folder
and rebuild the entire codebase using: dotnet build ./Microsoft.Maui.BuildTasks.slnf -->
<UseMaterial3>false</UseMaterial3>
<!-- Enable XAML Incremental Hot Reload via source generator -->
<EnableMauiIncrementalHotReload>true</EnableMauiIncrementalHotReload>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@
<CompilerVisibleProperty Include="EnablePreviewFeatures" />
<CompilerVisibleProperty Include="MauiXamlLazyRD" />
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="LazyRD" />
<CompilerVisibleProperty Include="EnableMauiIncrementalHotReload" />
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="EnableIncrementalHotReload" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@
Condition="'$(UseMaterial3)' != ''"
Value="$(UseMaterial3)"
Trim="true" />
<RuntimeHostConfigurationOption Include="Microsoft.Maui.RuntimeFeature.IsIncrementalHotReloadEnabled"
Condition="'$(EnableMauiIncrementalHotReload)' != ''"
Value="$(EnableMauiIncrementalHotReload)"
Trim="true" />
</ItemGroup>
</Target>

Expand Down
5 changes: 4 additions & 1 deletion src/Controls/src/SourceGen/CSharpExpressionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,15 @@ public static (string? prefix, string name) ParseBareIdentifier(string value)
"FontImage",
};

static bool IsKnownMarkupExtension(string name)
internal static bool IsKnownMarkupExtensionName(string name)
{
return KnownMarkupExtensions.Contains(name)
|| KnownMarkupExtensions.Contains(name + "Extension");
}

// Keep backward compat for existing callers
static bool IsKnownMarkupExtension(string name) => IsKnownMarkupExtensionName(name);

/// <summary>
/// Extracts the C# code from an expression value and transforms quotes.
/// Single-quoted strings are always transformed to double-quoted strings since C# doesn't support single-quoted strings.
Expand Down
Loading
Loading