Skip to content

Commit 3c3abe4

Browse files
authored
Merge pull request #352 from w-ahmad/fix/native-aot
fix: Refactor filter UI and command wiring for AOT compatibility
2 parents 53a5872 + 66c043e commit 3c3abe4

34 files changed

Lines changed: 1287 additions & 603 deletions

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ public class Item : INotifyPropertyChanged
169169

170170
Build and run your application. You should see the `TableView` populated with the rows and cells from your `ViewModel`.
171171

172+
## Native AOT Compatibility
173+
174+
TableView relies heavily on runtime bindings and dynamic value resolution, which are not fully compatible with IL trimming and Native AOT by default.
175+
176+
To use TableView in Native AOT applications, bound types should be decorated with the `WinRT.GeneratedBindableCustomProperty` attribute to preserve the required binding metadata.
177+
```cs
178+
[WinRT.GeneratedBindableCustomProperty]
179+
public partial class Person
180+
{
181+
public string Name { get; set; }
182+
183+
public int Age { get; set; }
184+
}
185+
```
186+
172187
## Customization
173188

174189
You can customize the appearance and behavior of the `TableView` by modifying its properties, templates, and styles. For example:

WinUI.TableView.slnx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<Solution>
22
<Folder Name="/samples/">
3+
<Project Path="samples/AotTestApp/AotTestApp.csproj">
4+
<Platform Project="x64" />
5+
<Deploy />
6+
</Project>
37
<Project Path="samples/WinUI.TableView.SampleApp.Uno/WinUI.TableView.SampleApp.Uno.csproj" />
48
<Project Path="samples/WinUI.TableView.SampleApp/WinUI.TableView.SampleApp.csproj">
59
<Platform Project="x64" />
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>WinExe</OutputType>
4+
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
5+
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
6+
<RootNamespace>AotTestApp</RootNamespace>
7+
<ApplicationManifest>app.manifest</ApplicationManifest>
8+
<Platforms>x86;x64;ARM64</Platforms>
9+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
10+
<UseWinUI>true</UseWinUI>
11+
<WinUISDKReferences>false</WinUISDKReferences>
12+
<EnableMsixTooling>true</EnableMsixTooling>
13+
<Nullable>enable</Nullable>
14+
<PublishAot>true</PublishAot>
15+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
16+
<CsWinRTAotWarningLevel>2</CsWinRTAotWarningLevel>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<Content Include="Assets\SplashScreen.scale-200.png" />
21+
<Content Include="Assets\LockScreenLogo.scale-200.png" />
22+
<Content Include="Assets\Square150x150Logo.scale-200.png" />
23+
<Content Include="Assets\Square44x44Logo.scale-200.png" />
24+
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
25+
<Content Include="Assets\StoreLogo.png" />
26+
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<Manifest Include="$(ApplicationManifest)" />
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<AdditionalFiles Include="**\*.xaml" Exclude="bin\**\*;obj\**\*" />
35+
</ItemGroup>
36+
37+
<!--
38+
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
39+
Tools extension to be activated for this project even if the Windows App SDK Nuget
40+
package has not yet been restored.
41+
-->
42+
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
43+
<ProjectCapability Include="Msix" />
44+
</ItemGroup>
45+
46+
<ItemGroup>
47+
<PackageReference Include="CommunityToolkit.Mvvm" />
48+
<PackageReference Include="Microsoft.WindowsAppSDK" />
49+
</ItemGroup>
50+
51+
<ItemGroup>
52+
<ProjectReference Include="..\..\src\WinUI.TableView.csproj" />
53+
</ItemGroup>
54+
55+
<!--
56+
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
57+
Explorer "Package and Publish" context menu entry to be enabled for this project even if
58+
the Windows App SDK Nuget package has not yet been restored.
59+
-->
60+
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
61+
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
62+
</PropertyGroup>
63+
64+
<!-- Publish Properties -->
65+
<PropertyGroup>
66+
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
67+
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
68+
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
69+
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
70+
</PropertyGroup>
71+
</Project>

samples/AotTestApp/App.xaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Application
3+
x:Class="AotTestApp.App"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:AotTestApp">
7+
<Application.Resources>
8+
<ResourceDictionary>
9+
<ResourceDictionary.MergedDictionaries>
10+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
11+
<!-- Other merged dictionaries here -->
12+
</ResourceDictionary.MergedDictionaries>
13+
<!-- Other app resources here -->
14+
</ResourceDictionary>
15+
</Application.Resources>
16+
</Application>

samples/AotTestApp/App.xaml.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
using Microsoft.UI.Xaml.Controls.Primitives;
4+
using Microsoft.UI.Xaml.Data;
5+
using Microsoft.UI.Xaml.Input;
6+
using Microsoft.UI.Xaml.Media;
7+
using Microsoft.UI.Xaml.Navigation;
8+
using Microsoft.UI.Xaml.Shapes;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.IO;
12+
using System.Linq;
13+
using System.Runtime.InteropServices.WindowsRuntime;
14+
using Windows.ApplicationModel;
15+
using Windows.ApplicationModel.Activation;
16+
using Windows.Foundation;
17+
using Windows.Foundation.Collections;
18+
19+
// To learn more about WinUI, the WinUI project structure,
20+
// and more about our project templates, see: http://aka.ms/winui-project-info.
21+
22+
namespace AotTestApp;
23+
/// <summary>
24+
/// Provides application-specific behavior to supplement the default Application class.
25+
/// </summary>
26+
public partial class App : Application
27+
{
28+
private Window? _window;
29+
30+
/// <summary>
31+
/// Initializes the singleton application object. This is the first line of authored code
32+
/// executed, and as such is the logical equivalent of main() or WinMain().
33+
/// </summary>
34+
public App()
35+
{
36+
InitializeComponent();
37+
}
38+
39+
/// <summary>
40+
/// Invoked when the application is launched.
41+
/// </summary>
42+
/// <param name="args">Details about the launch request and process.</param>
43+
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
44+
{
45+
_window = new MainWindow();
46+
_window.Activate();
47+
}
48+
}
432 Bytes
Loading
5.25 KB
Loading
1.71 KB
Loading
637 Bytes
Loading
283 Bytes
Loading

0 commit comments

Comments
 (0)