Synchronize button disabled at the same time of form

Hello,

I have a problem with a button on Xamarin.Forms. The button is a synchronize button what should enable a login form. By default login form is disabled but my synchronize button is also disabled while I don't want.

I searched on this forum and I tried differents methods like

        <Button Text="Test" Command="{Binding SynchronizeButton}" IsEnabled="True"/>

instead of

        <Button Text="Test" IsEnabled="True" Command="{Binding SynchronizeButton}"/>

My Login Form in Xaml

                <Label Text="Id" IsEnabled="{Binding ActiveField, Mode=TwoWay}"/>
                <Entry IsEnabled="{Binding ActiveField, Mode=TwoWay}"/>
                <Label Text="Pass" IsEnabled="{Binding ActiveField, Mode=TwoWay}"/>
                <Entry IsEnabled="{Binding ActiveField, Mode=TwoWay}"/>

My View Model (I'm using Prism)

public class MainPageViewModel : BindableBase
{
    // Attributes
    private INavigationService _navigationService;

        private bool _activeField; (false by default)

        public bool ActiveField
        {
            get { return _activeField; }
            set
            {
                SetProperty(ref _activeField, value);
                SynchronizeButton.RaiseCanExecuteChanged();
            }
        }

    public DelegateCommand SynchronizeButton { get; private set; }


    // Constructor
        public MainPageViewModel()
        {
            SynchronizeButton = new DelegateCommand(Synchronize, CanSynchronize).ObservesProperty(() => ActiveField);
        }

    // Methods
    private bool CanSynchronize()
        {
            return ActiveField;
        }

        private async void Synchronize()
        {
            ActiveField= true;
            await _navigationService.NavigateAsync("MainPage");
        }
}

Thanks for your help

Sign In or Register to comment.