Maui Button.IsEnabled not disabled

Viewed 50

I have an application on MAUI with the MVVM template, in which the given field where the phone number is entered, if it is empty, then when you click on the Convert button, the Call button should not be available. But the usual binding IsEnabled = {Binding ...} does not want to work. In the code, when you put the position true/false, it remains forever and does not change. Help with this problem, please

MainPage.xaml

<ScrollView>
    <VerticalStackLayout
        Spacing="15"
        Padding="20">

        <Label Text="Enter the phone number"
               FontSize="20"/>
        <Entry x:Name="PhoneNumber"
               Text="{Binding PhoneNumber}"/>
        <Button x:Name="ConvertButton"
                Text="{Binding ConvertButton}"
                Command="{Binding ConvertCommand}"
                />
        <Button x:Name="CallButton"
                Text="{Binding CallButton}"
                Command="{Binding CallCommand}"
                IsEnabled="{Binding IsReady}"/>

    </VerticalStackLayout>
</ScrollView>

MainViewModel.cs

    public string convertNumber;
    [ObservableProperty]
    public string phoneNumber = "+7-888-777-77-77";
    [ObservableProperty]
    public string convertButton = "Convert";
    [ObservableProperty]
    public string callButton = "Call";
    [ObservableProperty]
    public bool isReady;


    [RelayCommand]
     void Convert()
     {
        convertNumber = Task2.ToNumber(phoneNumber);
        if (!string.IsNullOrEmpty(convertButton))
        {
            isReady = true;
            callButton = $"Call {convertNumber}"; 
        }
        else
        {
            isReady = true;
            callButton = "Call: ";
        }
        
     }

In the model, when you install the field isReady=true does not change when you press the button

1 Answers

You can change the value of property IsEnable in C#.

void Convert()
{
    convertNumber = Task2.ToNumber(phoneNumber);
    if (!string.IsNullOrEmpty(convertButton))
    {
        callButton.IsEnable = false;
        callButton = $"Call {convertNumber}"; 
    }
    else
    {
        callButton.IsEnable = true;
        callButton = "Call: ";
    }     
}

If you use Bind, the UI will change only if the reference of bind property has changed.(This statement may be wrong)

Related