Repository navigation
Create DataTemplates in code with the new DataTemplate(DataTemplateElementFactory) constructor - #2258
Merged
Niels Laute (niels9001) merged 1 commit intoOct 7, 2026
Conversation
…ructor Replace XamlReader.Load in MenuItemTemplateSelector with DataTemplate(DataTemplateElementFactory) from Windows App SDK 2.5.4-experimental, exercise the header/separator templates in the NavigationView data binding sample, and add a 'Create a DataTemplate in code' example to the Templates page. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Marcel W. (marcelwgn)
approved these changes
Oct 7, 2026
Niels Laute (niels9001)
deleted the
niels9001-winappsdk-experimental-code-apis
branch
October 7, 2026 10:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adopts the experimental
DataTemplate(DataTemplateElementFactory)constructor added in Windows App SDK 2.5.4-experimental (the version the gallery already targets).MenuItemTemplateSelector: replaces theXamlReader.Loadstring templates withnew DataTemplate(() => ...)factories. This removes runtime XAML parsing.Separatorand aHeader("More categories") to the bound items. Before, the selector's header and separator templates were never used.Headeris now marked[WinRT.GeneratedBindableCustomProperty]so its{Binding Name}works under AOT. The shown C# snippet (NavigationViewDataBinding.txt) is updated to match.ItemTemplateis built in code-behind (FontIcon + bound TextBlock), with XAML/C# snippets inTemplatesCreateDatatemplateInCode.txt.DataTemplateElementFactorytag to the Templates entry inControlInfoData.jsonand regeneratescatalog/windows-samples.json.FrameworkElement.SetThemeResourceBinding, the other new API in this release, is covered in a separate PR.Motivation and Context
Before this release, a
DataTemplatecould only be created in code by building a XAML string and callingXamlReader.Load. The new constructor takes a factory delegate, which is type-safe and avoids parsing XAML. The gallery should show this pattern and use it itself.How Has This Been Tested?
msbuild WinUIGallery\WinUIGallery.csproj /restore /p:Configuration=Debug /p:Platform=x64 /m: succeeded (no new warnings).msbuild WinUIGallery\WinUIGallery.csproj /restore /p:Configuration=Debug-Unpackaged /p:Platform=x64 /m: succeeded.dotnet run --project tools/CatalogExporter -- generate: succeeded (125 controls, 342 samples).dotnet test tests\WinUIGallery.CatalogExporter.Tests: passed (159/159).Screenshots (if appropriate):
Types of changes