Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Can change enable state of ToolBarItem by Command.RaiseCanExecuteChanged at Xamarin.iOS?

$
0
0

I couldn't change enable state of ToolBarItem by Command.RaiseCanExecuteChanged at Xamarin.iOS.

Wrote XAML below.

  <ContentPage.ToolbarItems>
    <ToolbarItem Text="Basics" Command="{Binding SelectBasicsCommand}" />
    <ToolbarItem Text="Senseor" Command="{Binding SelectSensorsCommand}"/>
  </ContentPage.ToolbarItems>

And wrote ViewModel on the below.
※ I used Microsoft patterns & practices Prism Mvvm library. (https://pnpmvvm.codeplex.com/ )

public TopPageViewModel()
{
    this.SelectBasicsCommand = new DelegateCommand(this.SelectBasics, () => { return !this.ShowBasics; });
    this.SelectSensorsCommand = new DelegateCommand(this.SelectSensors, () => { return !this.ShowSensors; });
}

private bool showBasics = true;

public bool ShowBasics
{
    get { return this.showBasics; }
    set { this.SetProperty(ref this.showBasics, value); }
}

public ICommand SelectBasicsCommand { get; private set; }

private bool showSensors = false;

public bool ShowSensors
{
    get { return this.showSensors; }
    set { this.SetProperty(ref this.showSensors, value); }
}

public ICommand SelectSensorsCommand { get; private set; }

private void SelectBasics()
{
    this.ShowSensors = false;
    this.ShowBasics = true;

    ((DelegateCommand)this.SelectBasicsCommand).RaiseCanExecuteChanged();
    ((DelegateCommand)this.SelectSensorsCommand).RaiseCanExecuteChanged();
}

private void SelectSensors()
{
    this.ShowBasics = false;
    this.ShowSensors = true;

    ((DelegateCommand)this.SelectBasicsCommand).RaiseCanExecuteChanged();
    ((DelegateCommand)this.SelectSensorsCommand).RaiseCanExecuteChanged();
}

This code worked correctly at Android and Windows Runtime, but don't work at iOS.

ToolBarItem don't have 'IsEnabled' property, so I can't 'CanExecute' property divide from Command property.

Is the workaround of this problem exists?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>