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

Two Way binding for decimals causes System.AccessViolationException on property changed #9064

Closed
eric-vogt-pacesetter opened this issue Nov 9, 2023 · 5 comments
Labels
bug Something isn't working needs-author-feedback Asked author to supply more information. no-recent-activity team-Reach Issue for the Reach team

Comments

@eric-vogt-pacesetter
Copy link

Describe the bug

If you add x:Bind for a decimal property when you update the value of the decimal it causes System.AccessViolationException.

Steps to reproduce the bug

image
image
Try to update the value of the number box in the application
image

Expected behavior

Should not cause exception

Screenshots

See above

NuGet package version

WinUI 3 - Windows App SDK 1.4.2: 1.4.231008000

Windows version

No response

Additional context

Windows 10 version 22H2 (19045, 2022 Update)
Visual Studio 2022

@kmgallahan
Copy link
Contributor

kmgallahan commented Nov 10, 2023

You are trying to bind a decimal to a string, for which there is no built-in TwoWay converter.

On the initial get a string can be retrieved because:

If you bind a text control to a value that is not a string, the data binding engine will convert the value to a string. If the value is a reference type, the data binding engine will retrieve the string value by calling ICustomPropertyProvider.GetStringRepresentation or IStringable.ToString if available, and will otherwise call Object.ToString.

However, on set it will crash with the error The value cannot be converted to type Decimal. This occurs in native code and can be observed if you use mixed-mode debugging.

@eric-vogt-pacesetter
Copy link
Author

Thank you very much for the explanation! Value is a double type which can't be bound to a decimal so it seems like there is currently no solution to binding a decimal to a number box
image

@kmgallahan
Copy link
Contributor

kmgallahan commented Nov 10, 2023

That is correct, you must use a converter if you want to bind to a decimal instead of a double.

Alternatively, you can do the conversion at the point of processing in C# if that is convenient.

@bpulliam bpulliam added question and removed bug Something isn't working labels Nov 16, 2023
@duncanmacmichael duncanmacmichael added bug Something isn't working and removed question labels Nov 30, 2023
@ranjeshj ranjeshj added the team-Reach Issue for the Reach team label Dec 14, 2023
@Scottj1s
Copy link
Member

@eric-vogt-pacesetter Is the solution suggested by kmgallahan acceptable?

@Scottj1s Scottj1s added the needs-author-feedback Asked author to supply more information. label Dec 14, 2023
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-author-feedback Asked author to supply more information. no-recent-activity team-Reach Issue for the Reach team
Projects
None yet
Development

No branches or pull requests

6 participants