Fix Build Warning on Host (#40027)

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## 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

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## 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.

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
Try to build and run locally without problem.
This commit is contained in:
Gordon Lam
2025-06-15 23:13:16 -07:00
committed by GitHub
parent 3afaa18343
commit ecfc9e9ab2
4 changed files with 6 additions and 0 deletions

View File

@@ -1663,6 +1663,7 @@ TDefault
TDevice
telephon
templatenamespace
TESTONLY
testprocess
TEXCOORD
TEXTBOXNEWLINE

View File

@@ -6,6 +6,7 @@
<PropertyGroup>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<DefineConstants>TESTONLY</DefineConstants>
</PropertyGroup>
<PropertyGroup>

View File

@@ -611,6 +611,7 @@
<ContentDialog
x:Name="EntryDialog"
x:Uid="EntryDialog"
x:DataType="models:Entry"
IsPrimaryButtonEnabled="{Binding Valid, Mode=OneWay}"
Loaded="ContentDialog_Loaded_ApplyMargin"
PrimaryButtonStyle="{StaticResource AccentButtonStyle}">

View File

@@ -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' };