Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Binding to a toolbar button not working

$
0
0

Hi there,

i have a problem with a toolbar button and its binding.

First, I have created some entries and a button to save the users input.

Class AddReportPage

    <Button Text="OK" Command="{Binding SaveCommand}"></Button>

The button is working as expected.

But I want to save the data by hitting a button in the toolbar instead. So I put a toolbar item into my CustomPage, which includes the basic layout for all my pages.

Class AddSystemPage : CustomPage

XAML:

    <local:CustomPage.ToolbarItems>
        <ToolbarItem x:Name="btnOk" Text="OK" Command="{Binding SaveCommand}"/>
    </local:CustomPage.ToolbarItems>

For any reason, the binding of the SaveCommand to the toolbar item is not working.
I tried to do the binding in the ViewModel like this:

Class AddReportViewModel : BindableBase, INavigationAware, INotifyPropertyChanged

    public AddReportViewModel()
    {
        SaveCommand = new Command(Save, CanSave);
    }


public Command SaveCommand { get; set; }

    private void Save()
    {
        var item = new ReportItem()
        {
            subject = Title,
            description = Body,
            created = DateTime.Now

        };

    // save the item to database ...

    }

    private bool CanSave()
    {
        return !string.IsNullOrEmpty(Title) && !string.IsNullOrEmpty(Body);
    }

The toolbar item is definitely existing - but the command will not be executed.
Can anyone help me please?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



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