From fb5711817851ea44a3cb1bcacebed29117ecd22d Mon Sep 17 00:00:00 2001
From: Gordon Lam <73506701+yeelam-gordon@users.noreply.github.com>
Date: Sun, 15 Jun 2025 23:13:16 -0700
Subject: [PATCH] Fix Build Warning on Host (#40027)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## Summary of the Pull Request
Fixed build warnings WMC1510 in `HostsMainPage.xaml` that were
preventing proper AOT (Ahead-of-Time) compilation compatibility for XAML
data bindings.
### Problem
The Hosts module was generating multiple WMC1510 warnings during build:
```
src\modules\Hosts\HostsUILib\HostsMainPage.xaml(614,13): Warning WMC1510: Ensure the property path is trimming and AOT compatible by making use of 'Compiled Bindings (x:bind)' if possible or by specifying the 'x:DataType' directive...
```
These warnings occurred on 6 different binding expressions in the
EntryDialog ContentDialog that bound to properties of the `Entry` model
class.
### Solution
Applied the recommended fix by adding proper type information for the
XAML compiler:
1. **Added `x:DataType="models:Entry"`** to the ContentDialog element to
specify the binding context type
2. **Added `[Bindable]` attribute** to the Entry model class to ensure
WinRT compatibility
### Changes Made
- **HostsMainPage.xaml**: Added `x:DataType="models:Entry"` attribute to
the EntryDialog ContentDialog
- **Entry.cs**: Added `[Bindable]` attribute and `using
Microsoft.UI.Xaml.Data;` directive
## Detailed Description of the Pull Request / Additional comments
- ✅ Resolves all 6 WMC1510 warnings in the specified lines
- ✅ Ensures AOT compilation compatibility
- ✅ No functional changes to UI behavior
- ✅ Minimal code changes (3 lines total)
- ✅ Follows Microsoft's recommended approach for WinRT data binding
The fix enables proper trimming and AOT compilation while maintaining
all existing functionality.
## Validation Steps Performed
Try to build and run locally without problem.
---
.github/actions/spell-check/expect.txt | 1 +
src/modules/Hosts/Hosts.FuzzTests/Hosts.FuzzTests.csproj | 1 +
src/modules/Hosts/HostsUILib/HostsMainPage.xaml | 1 +
src/modules/Hosts/HostsUILib/Models/Entry.cs | 3 +++
4 files changed, 6 insertions(+)
diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt
index 68555a02f9..9f2ddfe382 100644
--- a/.github/actions/spell-check/expect.txt
+++ b/.github/actions/spell-check/expect.txt
@@ -1663,6 +1663,7 @@ TDefault
TDevice
telephon
templatenamespace
+TESTONLY
testprocess
TEXCOORD
TEXTBOXNEWLINE
diff --git a/src/modules/Hosts/Hosts.FuzzTests/Hosts.FuzzTests.csproj b/src/modules/Hosts/Hosts.FuzzTests/Hosts.FuzzTests.csproj
index 8c0f107395..667cfcc0ad 100644
--- a/src/modules/Hosts/Hosts.FuzzTests/Hosts.FuzzTests.csproj
+++ b/src/modules/Hosts/Hosts.FuzzTests/Hosts.FuzzTests.csproj
@@ -6,6 +6,7 @@
latest
enable
+ TESTONLY
diff --git a/src/modules/Hosts/HostsUILib/HostsMainPage.xaml b/src/modules/Hosts/HostsUILib/HostsMainPage.xaml
index f00eef9117..762b4264c9 100644
--- a/src/modules/Hosts/HostsUILib/HostsMainPage.xaml
+++ b/src/modules/Hosts/HostsUILib/HostsMainPage.xaml
@@ -611,6 +611,7 @@
diff --git a/src/modules/Hosts/HostsUILib/Models/Entry.cs b/src/modules/Hosts/HostsUILib/Models/Entry.cs
index 0c7c47efc1..02b02f6c63 100644
--- a/src/modules/Hosts/HostsUILib/Models/Entry.cs
+++ b/src/modules/Hosts/HostsUILib/Models/Entry.cs
@@ -11,6 +11,9 @@ using HostsUILib.Helpers;
namespace HostsUILib.Models
{
+#if !TESTONLY
+ [Microsoft.UI.Xaml.Data.Bindable]
+#endif
public partial class Entry : ObservableObject
{
private static readonly char[] _spaceCharacters = new char[] { ' ', '\t' };