maui
maui copied to clipboard
Setting entry text from binding before user interaction sets null on iOS
Description
I have a numeric Entry, I can type in it with no issues. Then I add some buttons which change the value, converting it from string to int then incrementing or decrementing. By debugging I can see that the binding setter is called, and onpropertychanged is called, but I see the value disappear on iOS as soon as I press one of the buttons. If I type in the entry and then press the buttons, no issue.
Steps to Reproduce
- Create numeric Entry
- Create buttons to change the value bound to the entry (via ViewModel)
- Press buttons before interacting with the entry
Expected result:
- Changed value should appear
Actual result:
- Text disappears in entry, and stays disappeared.
Link to public reproduction project repository
No response
Version with bug
8.0.7 SR2
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 15
Did you find any workaround?
I have written a workaround by using AppendToMapping:
(in Startup.cs)
EntryHandler.Mapper.AppendToMapping(nameof(Entry), EntryMapping.Map);
(EntryMapping.cs class)
public partial class EntryMapping
{
public static void Map(IEntryHandler handler, IEntry view)
{
handler.PlatformView.BackgroundColor = UIKit.UIColor.Clear;
handler.PlatformView.BorderStyle = UIKit.UITextBorderStyle.None;
if (view is Entry entry)
{
entry.PropertyChanged += (sender, args) =>
{
if (args.PropertyName == nameof(entry.Text))
{
handler.PlatformView.Text = entry.Text;
}
};
}
}
}
This resolves the issue, but I would prefer not to have this additional complexity.
Relevant log output
No response
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Open similar issues:
- Entry fields do not work correctly if bound to a numeric property from a ViewModel (#15846), similarity score: 0.76
Closed similar issues:
- Binding of Entry control seems to break after entering text in Entry (#16859), similarity score: 0.79
-
iOS
Entry
Control IgnoresTextColor
Property Upon Binding Update (#21430), similarity score: 0.77 - net8 Maui iOS/Android Entry isn't cleared after set bound property value to null (#17321), similarity score: 0.77
- [regression/8.0.0-preview.1.7762] TwoWay Binding does not work when value is changed from the source ViewModel (#16849), similarity score: 0.75
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Verified on 17.11.0 Preview 1.1 (8.0.40&8.0.21&8.0.7&8.0.3). Can not repro this issue. MauiApp3.zip
Hi @benOnside. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.
You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.