Skip to content

Can't use Function Binding with Converter #10927

@michael-hawker

Description

@michael-hawker

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:

<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}"
          FontSize="16"
          Glyph="{x:Bind GetAppliedTheme(ViewModel.Document.State.PreviewAreaTheme, PreviewArea.ActualTheme), Converter={StaticResource PreviewThemeSwitchConverter}, Mode=OneWay}" />

Where GetAppliedTheme was returning an ElementTheme which the SwitchConverter would them convert to string from XAML:

        <converters:SwitchConverter x:Key="PreviewThemeSwitchConverter"
                                    TargetType="xaml:ElementTheme">
            <controls:Case Value="Dark" Content="&#xE708;"/>
            <controls:Case Value="Light" Content="&#xE793;"/>
        </converters:SwitchConverter>

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...

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions