Skip to content

Can't use x:Bind with Converter in Window #4966

@alexdi220

Description

@alexdi220

Describe the bug
Hi, I've tried to use the x:Bind with IValueConverter. But the project doesn't compile - CS1503 Argument 1: cannot convert from 'TestApp.MainWindow' to 'Microsoft.UI.Xaml.FrameworkElement'. Please take a look at the following code. What I do wrong?

Steps to reproduce the bug

<Window
    x:Class="TestApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TestApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid RowDefinitions="Auto, *" x:Name="root">
        <Grid.Resources>
            <local:MyConverter x:Key="MyConverter"/>
        </Grid.Resources>
        <StackPanel Spacing="12"
                    Grid.Row="1">
            <TextBlock Text="{x:Bind MyProperty, Converter={StaticResource MyConverter}}"/>
        </StackPanel>
    </Grid>
</Window>
    public class MyConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter, string language) => value;
        public object ConvertBack(object value, Type targetType, object parameter, string language) => value;
    }

    public sealed partial class MainWindow : Window {
        public MainWindow() {
            this.InitializeComponent();            
        }
        public string MyProperty { get; } = "Test";

Expected behavior

Screenshots
image

Version Info

NuGet package version:

[WinUI 3 - Project Reunion 0.5: 0.5.6]

Windows app type:

UWP Win32
Yes
Windows 10 version Saw the problem?
Insider Build (xxxxx)
October 2020 Update (19042) Yes
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions