I want to add toolbar item to save the user input. I used the contentpage.toolbar items as shown in the code below:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="firstXamarin.HistoryPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Add"
Order="Primary"
Priority="0"
Clicked="Add_OnClicked" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout Margin="30,30">
<Entry x:Name="UsernameEntry" Placeholder="username" VerticalOptions="Center" Height="50" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
the toolbar item and the toolbar are missed. I followed these solutions but they do not work:
this my .cs file for the page:
public HistoryPage()
{
InitializeComponent();
}
private void Add_OnClicked(object sender, EventArgs e)
{
Post post = new Post()
{
Username = UsernameEntry.Text
};
SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
conn.CreateTable<Post>();
int rows = conn.Insert(post);
conn.Close();
if (rows > 0)
{
DisplayAlert("Success", "the data inserted successfully", "ok");
}
else
{
DisplayAlert("failure", "the data are not inserted ", "ok");
}
}
Note: I have read that i would use navigation page but I did not find xaml example for NavigationPage implementation
Below is the code of tabbed page :
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:firstXamarin;assembly=firstXamarin"
mc:Ignorable="d"
x:Class="firstXamarin.MainPage">
<TabbedPage.ToolbarItems></TabbedPage.ToolbarItems>
<local:ReportPage Title="Report" />
<local:HistoryPage Title="History"/>
</TabbedPage>
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainPage : TabbedPage
{
public MainPage()
{
InitializeComponent();
}
}
}
App Page Code :
<Application.Resources>
<Color x:Key="ButtonColor">CornflowerBlue</Color>
<Color x:Key="EntryColor">Gainsboro</Color>
<Style TargetType="Button">
<Setter Property="BackgroundColor" Value="{StaticResource ButtonColor}"/>
<Setter Property="TextColor" Value="{StaticResource EntryColor}"/>
</Style>
</Application.Resources>
</Application>
public partial class App : Application
{
public static string DatabaseLocation = string.Empty;
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
public App(string dblocation)
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
DatabaseLocation = dblocation;
}
protected override void OnStart()
{
}
protected override void OnSleep()
{
}
protected override void OnResume()
{
}
}