microsoft / microsoft/microsoft-ui-xaml
Can't use Function Binding with Converter
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
Just tried to combine a function binding method in x:Bind with a converter, but got a compiler error:
> XamlCompiler error WMC1121: Invalid binding assignment : Using a converter with function binding is not supported
I wanted to use the x:Bind function to do some logic to merge values and agree on state, and then the `SwitchConverter` from the Windows Community Toolkit to take the strongly-typed value and convert it to a view representation in XAML to separate a bit of the app logic from the specific view display.
### Why is this important?
Provides more ways for developers to hook things together between code and XAML.
### Steps to reproduce the bug
Try to assign a `SwitchConverter` from WCT to an x:Bind function:
```xml
```
Where `GetAppliedTheme` was returning an `ElementTheme` which the SwitchConverter would them convert to string from XAML:
```xml
```
### Actual behavior
Function result passed to converter before applied to property.
### Expected behavior
XAML Compiler error
### Screenshots
_No response_
### NuGet package version
WinUI 2 - Microsoft.UI.Xaml 2.8.7
### Windows version
Windows 11 (24H2): Build 26100
### Additional context
In my particular case I could rewrite my function to do both parts, but if I wanted to return XAML Theme resources instead that would react to the app theming, then this wouldn't work.
This does break strong typing a bit for AOT, but converters do that already with x:Bind without functions, so this is no different. That's beyond the scope of this issue.
Just realized I'm still on UWP in this project, but I assume this is still an issue in WinUI 3 today...
Contributor guide
Research direction
Start by reproducing the WMC1121 error with the provided x:Bind function and SwitchConverter XAML snippets, then trace the function-binding compiler path that rejects converters. Done means the binding compiles and the function result reaches the converter to produce the expected view representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100