Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 9, 2026

Summary

Fixed an issue where static x:Bind expressions in DataTemplates failed to compile without an x:DataType specified.

Changes Made

  • Explored repository structure and understood x:Bind compilation
  • Identified error locations in XamlFileGenerator.cs
  • Modified BuildXBindProperties to detect fully static bindings
  • Modified event binding code to allow static methods without DataType
  • Created comprehensive test cases
  • Fixed build errors and formatting issues
  • Added unit tests to verify the fix
  • Addressed code review feedback with comments
  • Fixed CI build error: empty path bindings incorrectly classified as static
  • Passed security checks

Technical Details

Property Bindings

  • Pre-parse binding to detect if all properties are static (start with "global::")
  • Fixed: Empty path bindings (e.g., {x:Bind}) bind to DataContext itself, not static members
  • If fully static (has path and all properties start with "global::"), skip DataType requirement
  • If not fully static, require x:DataType as before

Event Bindings

  • Detect static method paths (contain ':' type qualifier)
  • Skip DataType requirement for static methods
  • Use page type as placeholder (not used for resolution)

Build Fix

The build error The name '___tctx' does not exist in the current context was caused by:

  1. Empty path bindings (e.g., {x:Bind} with just a Converter) were incorrectly classified as "fully static"
  2. These bindings were taking the static code path instead of the normal DataTemplate path
  3. Fixed by explicitly checking for non-empty path before considering a binding as static

Compatibility

✅ Fully backward compatible
✅ Aligns with WinAppSDK behavior
✅ No breaking changes
✅ Existing bindings unaffected

Original prompt

This section details on the original issue you should resolve

<issue_title>Static x:Bind in DataTemplate fails without a DataType</issue_title>
<issue_description>### Current behavior 🐛

If you have a <DataTemplate> without a DataType specified with only static x:Bind in it then it fails to compile with:

error UXAML0001: Unable to find x:DataType in enclosing DataTemplate

Expected behavior 🎯

Should allow you to do x:Bind to static members without needing a DataType. Works in WinAppSdk.

How to reproduce it (as minimally and precisely as possible) 🔬

Put a static x:Bind in a data template with no DataType, for example:

<cwuc:DataGridTemplateColumn>
  <cwuc:DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
      <FontIcon Glyph="{x:Bind d:FontIcons.Role}" />
    </DataTemplate>
  </cwuc:DataGridTemplateColumn.CellTemplate>
</cwuc:DataGridTemplateColumn>

Notice the build fails with the error above.

Workaround 🛠️

No response

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

All platforms 🌍 (Except WinAppSdk)

Uno.Sdk version (and other relevant versions) 📦

6.5.0-dev.100

IDE version 🧑‍💻

No response

Anything else we need to know? 💬

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: MartinZikmund <1075116+MartinZikmund@users.noreply.github.com>
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 2 commits January 9, 2026 16:07
Co-authored-by: MartinZikmund <1075116+MartinZikmund@users.noreply.github.com>
Co-authored-by: MartinZikmund <1075116+MartinZikmund@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix static x:Bind in DataTemplate without DataType fix: Allow static x:Bind in DataTemplate without x:DataType Jan 9, 2026
Copilot AI requested a review from MartinZikmund January 9, 2026 16:11
@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-22324/docs/index.html

@github-actions github-actions bot added area/code-generation Categorizes an issue or PR as relevant to code generation area/automation Categorizes an issue or PR as relevant to project automation labels Jan 9, 2026
@MartinZikmund
Copy link
Member

@copilot Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator/BindingExpression_With_Converter_07e5b85741c18e42ed743478c0cd3c9b.cs(723,180): error CS0103: The name '___tctx' does not exist in the current context [/agent/_work/1/s/src/Uno.UI.RuntimeTests/Uno.UI.RuntimeTests.Skia.csproj::TargetFramework=net10.0]

Co-authored-by: MartinZikmund <1075116+MartinZikmund@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 9, 2026

@copilot Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator/BindingExpression_With_Converter_07e5b85741c18e42ed743478c0cd3c9b.cs(723,180): error CS0103: The name '___tctx' does not exist in the c...

Fixed in commit 545ed8f. The issue was that empty path bindings (e.g., {x:Bind Converter={StaticResource ...}}) were incorrectly classified as "fully static" because they have an empty Properties array. These bindings actually bind to the DataContext itself and should use the normal DataTemplate code path with x:DataType. The fix explicitly checks for non-empty paths before considering a binding as static.

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-22324/docs/index.html

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22324/wasm-skia-net9/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/code-generation Categorizes an issue or PR as relevant to code generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static x:Bind in DataTemplate fails without a DataType

4 participants