-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Labels
Description
Describe the bug
When trying to filter or change the text inside of a TextBox when the user types new characters the TextBox ignores the real text in the ViewModel. Similar behavior as #3603.
To Reproduce
Create a new MVVM Application
ViewModel:
public partial class MainWindowViewModel : ViewModelBase
{
private string _greeting = "HELLO HOW ARE YALL";
public string Greeting
{
get => _greeting;
set => SetProperty(ref _greeting, value.Replace("L", "K"));
}
}MainWindow:
<Window .... >
<TextBox
Name="Test"
Text="{Binding Greeting}"/>
</Window>For logging MainWindow.axaml.cs:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Test.PropertyChanged += (_, args) =>
{
if (args.Property.Name == "Text")
{
Console.WriteLine($"old: {args.OldValue}, new: {args.NewValue}");
}
};
}
}Output:
// first set of the property no change
old: , new: HELLO HOW ARE YALL
// third set from the ViewModel replacing L by K
old: HELLO HOW ARE YALLB, new: HEKKO HOW ARE YAKKB
// second set from TextBox adding the Input
old: HELLO HOW ARE YALL, new: HELLO HOW ARE YALLB
// fourth set overwrites the correct text - I could not figure out from where
old: HEKKO HOW ARE YAKKB, new: HELLO HOW ARE YALLB
When using Backspace or delete the fourth set does not occur and therefore this works fine in those cases.
Expected behavior
It should not have fired the fourth set to achieve text filtration and with that following output:
// first set of the property no change
old: , new: HELLO HOW ARE YALL
// third set from the ViewModel replacing L by K
old: HELLO HOW ARE YALLB, new: HEKKO HOW ARE YAKKB
// second set from TextBox adding the Input
old: HELLO HOW ARE YALL, new: HELLO HOW ARE YALLB
Avalonia version
11.3.9
OS
Linux
Additional context
No response