Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding failed on DependencyProperty of nullable types #4937

Closed
AlexanderEgorov opened this issue Apr 30, 2021 · 5 comments
Closed

Binding failed on DependencyProperty of nullable types #4937

AlexanderEgorov opened this issue Apr 30, 2021 · 5 comments
Labels
no-issue-activity product-winui3 WinUI 3 issues team-Controls Issue for the Controls team v0.5 Issues introduced in the Project Reunion 0.5 prerelease

Comments

@AlexanderEgorov
Copy link

Describe the bug
See the attached sample.
The following property cannot be bound with a two-way binding.

        public bool? IsChecked { get { return (bool?)GetValue(IsCheckedProperty); } set { SetValue(IsCheckedProperty, value); } }
        public static readonly DependencyProperty IsCheckedProperty =
            DependencyProperty.Register("IsChecked", typeof(bool?), typeof(MyControl), 
                new PropertyMetadata(null, (d, e) => ((MyControl)d).OnIsCheckedChanged()));
        void OnIsCheckedChanged() {
        }

Steps to reproduce the bug

  1. Run the attached sample
  2. Click on a button
  3. Check an error in output: "Error: Converter failed to convert value of type 'Windows.Foundation.IReference1<Boolean>' to type 'IReference1'; BindingExpression: Path='IsChecked' DataItem='App1.MyControl'; target element is 'Microsoft.UI.Xaml.Controls.Primitives.ToggleButton' (Name='null'); target property is 'IsChecked' (type 'Boolean')."

Expected behavior
The binding should work without errors.

Version Info
[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
@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Apr 30, 2021
@StephenLPeters
Copy link
Contributor

@teaP and @MikeHillberg (or maybe @jevansaks) do you recall the issues/work around here? similar to the issues with NumberBox's value property.

@StephenLPeters StephenLPeters added v0.5 Issues introduced in the Project Reunion 0.5 prerelease team-Controls Issue for the Controls team product-winui3 WinUI 3 issues and removed needs-triage Issue needs to be triaged by the area owners labels Apr 30, 2021
@teaP
Copy link
Contributor

teaP commented May 3, 2021

@teaP and @MikeHillberg (or maybe @jevansaks) do you recall the issues/work around here? similar to the issues with NumberBox's value property.

This isn't the same -- NumberBox.Value isn't nullable, it uses NaN as the unset value (which definitely caused OTHER binding issues because NaN != NaN).

@MikeHillberg
Copy link
Contributor

But IIRC we wanted to use nullable for NumberBox, but couldn't because of this problem. I think there's an open Issue on this, that nullable isn't generally supported in binding and/or some markup scenarios, except for built-in WUX types.

We've worked around it for double types using NaN, int types using -1 or one of the infinities. I'm not sure how to work around it for a bool unfortunately; it doesn't have any magic values.

@AndrewKeepCoding
Copy link
Contributor

Is there any progress or workaround on this?

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-issue-activity product-winui3 WinUI 3 issues team-Controls Issue for the Controls team v0.5 Issues introduced in the Project Reunion 0.5 prerelease
Projects
None yet
Development

No branches or pull requests

5 participants