my text dont changing when im using setter #438
-
|
I tried to use Dispatcher.UIThread.Post, it starts working, but if you enter the first character a letter or 0 (as I have in the condition is forbidden), the converter for some reason does not work, well, and no error is not given. this problem began with version 11.1.0, and before everything was normal. using System;
using System.Linq;
using System.Reactive;
using Avalonia.Media.TextFormatting.Unicode;
using Avalonia.Threading;
using ReactiveUI;
namespace test.ViewModels;
public class MainWindowViewModel : ViewModelBase
{
private string? _input = "";
public string? Input
{
get => _input;
set => if (value != null) this.RaiseAndSetIfChanged(ref _input, Converter(value));
}
private string Converter(string val)
{
if (val.StartsWith("0") || !val!.All(Char.IsDigit))
{
return string.Empty;
}
bool suc = Int32.TryParse(val, out var finalAuto);
if (suc)
{
if (finalAuto > 10000)
{
return string.Empty;
}
}
else
{
return string.Empty;
}
return val;
}
public MainWindowViewModel()
{
}
}<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:test.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="test.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
xmlns:local="clr-namespace:test"
Icon="/Assets/avalonia-logo.ico"
Title="test">
<Design.DataContext>
<vm:MainWindowViewModel />
</Design.DataContext>
<StackPanel>
<TextBox Text="{Binding Input}" />
</StackPanel>
</Window> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
Hello. First of all, this is not related to Material.Avalonia, you should report it to Avalonia repo. As for problem, you can't change value inside of setter, any changes in setter doesn't appear in control, this is binding specific "feature". You should delay value setter (by calling dispatcher/task delay) or coerce your value other way, like in code behind for example. Or instead of changing value you can validate value. Or the preferred way - use the NumericUpDown instead or regular TextBox for numbers inputting and limiting. |
Beta Was this translation helpful? Give feedback.
Hello. First of all, this is not related to Material.Avalonia, you should report it to Avalonia repo.
As for problem, you can't change value inside of setter, any changes in setter doesn't appear in control, this is binding specific "feature". You should delay value setter (by calling dispatcher/task delay) or coerce your value other way, like in code behind for example. Or instead of changing value you can validate value. Or the preferred way - use the NumericUpDown instead or regular TextBox for numbers inputting and limiting.