Skip to content

Commit

Permalink
Using internal xaml loader code
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebaltazar committed Nov 1, 2024
1 parent 7a09f57 commit ba9cf84
Show file tree
Hide file tree
Showing 9 changed files with 817 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Maui.ServerDrivenUI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Itens de Solução", "Itens
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Maui.Controls.DeviceTests", "Microsoft.Maui.Core.DeviceTests\Microsoft.Maui.Controls.DeviceTests.csproj", "{28109973-FDEC-4CA8-9E37-D16AE77F9B4C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -26,6 +28,10 @@ Global
{E67A0AF3-8CB0-4E40-99A0-6C2001D7E0D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E67A0AF3-8CB0-4E40-99A0-6C2001D7E0D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E67A0AF3-8CB0-4E40-99A0-6C2001D7E0D1}.Release|Any CPU.Build.0 = Release|Any CPU
{28109973-FDEC-4CA8-9E37-D16AE77F9B4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28109973-FDEC-4CA8-9E37-D16AE77F9B4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28109973-FDEC-4CA8-9E37-D16AE77F9B4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28109973-FDEC-4CA8-9E37-D16AE77F9B4C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 5 additions & 0 deletions Maui.ServerDrivenUI/Maui.ServerDrivenUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@
<ItemGroup>
<None Include="build\*.targets" Pack="True" PackagePath="buildTransitive" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Maui.Core.DeviceTests\Microsoft.Maui.Controls.DeviceTests.csproj" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion Maui.ServerDrivenUI/Views/ServerDrivenVisualElement.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Maui.ServerDrivenUI.Models.Exceptions;
using Maui.ServerDrivenUI.Services;
using Maui.ServerDrivenUI.Xaml;

namespace Maui.ServerDrivenUI.Views;

Expand Down Expand Up @@ -35,7 +36,7 @@ internal static async Task InitializeComponentAsync(IServerDrivenVisualElement e

try
{
visualElement?.LoadFromXaml(xaml);
visualElement?.LoadXaml(xaml);
errorMessage = string.Empty;

if (XamlConverterService.LabelsSpans.Any())
Expand Down
24 changes: 24 additions & 0 deletions Microsoft.Maui.Core.DeviceTests/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Reflection;

namespace Maui.ServerDrivenUI.Xaml;

public static class Extensions
{
public static TXaml LoadXaml<TXaml>(this TXaml view, Type callingType)
{
XamlLoader.Load(view, callingType);

Check warning on line 9 in Microsoft.Maui.Core.DeviceTests/Extensions.cs

View workflow job for this annotation

GitHub Actions / Build and publish package

Possible null reference argument for parameter 'view' in 'void XamlLoader.Load(object view, Type callingType)'.

Check warning on line 9 in Microsoft.Maui.Core.DeviceTests/Extensions.cs

View workflow job for this annotation

GitHub Actions / Build and publish package

Possible null reference argument for parameter 'view' in 'void XamlLoader.Load(object view, Type callingType)'.

Check warning on line 9 in Microsoft.Maui.Core.DeviceTests/Extensions.cs

View workflow job for this annotation

GitHub Actions / Build and publish package

Possible null reference argument for parameter 'view' in 'void XamlLoader.Load(object view, Type callingType)'.

Check warning on line 9 in Microsoft.Maui.Core.DeviceTests/Extensions.cs

View workflow job for this annotation

GitHub Actions / Build and publish package

Possible null reference argument for parameter 'view' in 'void XamlLoader.Load(object view, Type callingType)'.
return view;
}

public static TXaml LoadXaml<TXaml>(this TXaml view, string xaml)
{
XamlLoader.Load(view, xaml);

Check warning on line 15 in Microsoft.Maui.Core.DeviceTests/Extensions.cs

View workflow job for this annotation

GitHub Actions / Build and publish package

Possible null reference argument for parameter 'view' in 'void XamlLoader.Load(object view, string xaml)'.

Check warning on line 15 in Microsoft.Maui.Core.DeviceTests/Extensions.cs

View workflow job for this annotation

GitHub Actions / Build and publish package

Possible null reference argument for parameter 'view' in 'void XamlLoader.Load(object view, string xaml)'.

Check warning on line 15 in Microsoft.Maui.Core.DeviceTests/Extensions.cs

View workflow job for this annotation

GitHub Actions / Build and publish package

Possible null reference argument for parameter 'view' in 'void XamlLoader.Load(object view, string xaml)'.
return view;
}

internal static TXaml LoadXaml<TXaml>(this TXaml view, string xaml, Assembly rootAssembly)
{
XamlLoader.Load(view, xaml, rootAssembly);

Check warning on line 21 in Microsoft.Maui.Core.DeviceTests/Extensions.cs

View workflow job for this annotation

GitHub Actions / Build and publish package

Possible null reference argument for parameter 'view' in 'void XamlLoader.Load(object view, string xaml, Assembly rootAssembly)'.

Check warning on line 21 in Microsoft.Maui.Core.DeviceTests/Extensions.cs

View workflow job for this annotation

GitHub Actions / Build and publish package

Possible null reference argument for parameter 'view' in 'void XamlLoader.Load(object view, string xaml, Assembly rootAssembly)'.

Check warning on line 21 in Microsoft.Maui.Core.DeviceTests/Extensions.cs

View workflow job for this annotation

GitHub Actions / Build and publish package

Possible null reference argument for parameter 'view' in 'void XamlLoader.Load(object view, string xaml, Assembly rootAssembly)'.
return view;
}
}
1 change: 1 addition & 0 deletions Microsoft.Maui.Core.DeviceTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.Maui.Controls.Internals;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios17;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseMaui>true</UseMaui>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.3" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.3" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>
</Project>
Loading

0 comments on commit ba9cf84

Please sign in to comment.