Xamarin ContentPage.ToolbarItems move to the bottom of page - xamarin.forms

The following is my code what I want to do is move the toolbar to the bottom of the page after the grid
<ContentPage.ToolbarItems>
<ToolbarItem Icon="heart.png" Command="{Binding GotoWishlistCommand}"/>
<ToolbarItem Icon="shoppingcart.png"
Command="{Binding GotoCartCommand}"/>
</ContentPage.ToolbarItems>
<ContentPage.Resources>
<ResourceDictionary>
<converter:SelectedToColorConverter x:Key="cnvInvert"/>
</ResourceDictionary>
</ContentPage.Resources>

Unfortunately, ToolbarItem is designed by default at the top of the page.
If want to move ToolbarItem to bottom of the page,this can be done by custom view.You can create a StackLayout , and it contains buttons like ToolbarItem in it.In addition,StackLayout can be setted below GridLayout.Then this seems like as a ToolbarItem on the bottom of the page.
Example Code as follow:
<StackLayout>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="Top Left" Grid.Row="0" Grid.Column="0" />
<Label Text="Top Right" Grid.Row="0" Grid.Column="1" />
<Label Text="Bottom Left" Grid.Row="1" Grid.Column="0" />
<Label Text="Bottom Right" Grid.Row="1" Grid.Column="1" />
</Grid>
<StackLayout BackgroundColor="BlueViolet" x:Name="CustomToolBarItem" Orientation="Horizontal" HorizontalOptions="EndAndExpand" WidthRequest="1000">
<ImageButton Source="heart.png" Command="{Binding GotoWishlistCommand}" HorizontalOptions="End" VerticalOptions="Center"/>
<ImageButton Source="shoppingcart.png" Command="{Binding GotoCartCommand}" HorizontalOptions="End" VerticalOptions="Center"/>
</StackLayout>
</StackLayout>

Add in the TabbedPage this lines if you are trying to put in the bottom for android. For iOS it's as default.
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
Finally, your page will be something like this:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
x:Class="SampleApp.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
xmlns:views="clr-namespace:SampleApp"
android:TabbedPage.ToolbarPlacement="Bottom">
<TabbedPage.Children>
<NavigationPage
Title="Browse"
BackgroundColor="White"
Icon="tab_feed.png">
<x:Arguments>
<views:ItemsPage />
</x:Arguments>
</NavigationPage>
<NavigationPage
Title="About"
BackgroundColor="White"
Icon="tab_about.png">
<x:Arguments>
<views:AboutPage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>

Related

scrollview doesn't scroll up enough to see the rest of views xamarin.forms

i wrote this code for a registration page. in some phones, the screen doesn't fit for all the views so i used a scrollview so that the user could scroll down through them. the problem i'm facing is that the scrollview doesn't scroll enough upwards. the button at the end doesn't appear. here is my xaml code:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ALNahrainAlphaApp.RegisterPage"
xmlns:controls="clr-namespace:ALNahrainAlphaApp;assembly=ALNahrainAlphaApp"
>
<ContentPage.Content>
<ScrollView Orientation="Vertical">
<ScrollView.Background>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="#0d98ba"
Offset="0.2" />
<GradientStop Color="White"
Offset="1" />
</LinearGradientBrush>
</ScrollView.Background>
<StackLayout>
<Grid>
<StackLayout>
<Frame CornerRadius="50" BorderColor="White" BackgroundColor="Transparent" Margin="20,50">
<Grid Padding="1" ColumnSpacing="1" RowSpacing="0" Margin="0,160">
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*" />
</Grid.ColumnDefinitions>
<Frame CornerRadius="20" Margin="0,5" />
<controls:CustomEntry
Grid.Row="0"
x:Name="id"
HorizontalOptions="FillAndExpand"
Margin="10,5"
TextColor="Black"
Placeholder="ID"
FontSize="16"
PlaceholderColor="Gray"
/>
<Frame CornerRadius="20" Grid.Row="1" Margin="0,5"/>
<controls:CustomEntry
Grid.Row="1"
x:Name="firstname"
HorizontalOptions="Fill"
Margin="10,5"
TextColor="Black"
FontSize="16"
Placeholder="First Name"
PlaceholderColor="Gray"
/>
<Frame CornerRadius="20" Grid.Row="2" Margin="0,5"/>
<controls:CustomEntry
Grid.Row="2"
x:Name="lastname"
HorizontalOptions="Fill"
Margin="10,5"
TextColor="Black"
Placeholder="Last Name"
PlaceholderColor="Gray"
FontSize="16"
/>
<Frame CornerRadius="20" Grid.Row="3" Margin="0,5"/>
<controls:CustomEntry
FontSize="16"
Grid.Row="3"
x:Name="role"
HorizontalOptions="Fill"
Margin="10,5"
TextColor="Black"
Placeholder="Role"
PlaceholderColor="Gray"
/>
<Frame CornerRadius="20" Grid.Row="4" Margin="0,5"/>
<controls:CustomEntry
FontSize="16"
Grid.Row="4"
x:Name="user_name"
HorizontalOptions="Fill"
Margin="10,5"
TextColor="Black"
Placeholder="Username"
PlaceholderColor="Gray"
/>
<Frame CornerRadius="20" Grid.Row="5" Margin="0,5"/>
<controls:CustomEntry
FontSize="16"
Grid.Row="5"
x:Name="password"
HorizontalOptions="Fill"
Margin="10,5"
TextColor="Black"
Placeholder="Password"
PlaceholderColor="Gray"
/>
<StackLayout Orientation="Horizontal" Grid.Row="6">
<Label Text="Allow Access" TextColor="Black" FontSize="16" HorizontalOptions="Center" VerticalOptions="Center" Margin="15,5"/>
<Switch
ThumbColor="Black"
OnColor="White"
x:Name="appaccess"
HorizontalOptions="Center"
VerticalOptions="Center"
Margin="40,0"
/>
</StackLayout>
</Grid>
</Frame>
<Button CornerRadius="50" Text="Submit" FontSize="Medium" BackgroundColor="White" TextColor="Black" FontFamily="audiofont" x:Name="save" HeightRequest="60" WidthRequest="140" HorizontalOptions="Center" VerticalOptions="Center" Margin="0,-85" Clicked="save_Clicked"/>
</StackLayout>
<Frame CornerRadius="50" HeightRequest="100" WidthRequest="100" HorizontalOptions="Center" VerticalOptions="Start" Padding="-2" BorderColor="White" Margin="20,5,20,0">
<Image HeightRequest="150" WidthRequest="150" x:Name="userprofile" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</Frame>
</Grid>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
i tried different things, i put the scrollview inside a contentview but i didn't work. what am i doing wrong?
You can try to add property RowDefinitions and define two row for the outer grid.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<!--other code-->
<Grid>
You can refer to the following code:
<ContentPage.Content>
<ScrollView Orientation="Vertical">
<ScrollView.Background>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="#0d98ba"
Offset="0.2" />
<GradientStop Color="White"
Offset="1" />
</LinearGradientBrush>
</ScrollView.Background>
<StackLayout>
<Grid>
<!--add two row here-->
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<StackLayout>
<Frame CornerRadius="50" BorderColor="White" BackgroundColor="Transparent" Margin="20,50">
<Grid Padding="1" ColumnSpacing="1" RowSpacing="0" Margin="0,160">
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*" />
</Grid.ColumnDefinitions>
<Frame CornerRadius="20" Margin="0,5" />
<Entry
Grid.Row="0"
x:Name="id"
HorizontalOptions="FillAndExpand"
Margin="10,5"
TextColor="Black"
Placeholder="ID"
FontSize="16"
PlaceholderColor="Gray"
/>
<Frame CornerRadius="20" Grid.Row="1" Margin="0,5"/>
<Entry
Grid.Row="1"
x:Name="firstname"
HorizontalOptions="Fill"
Margin="10,5"
TextColor="Black"
FontSize="16"
Placeholder="First Name"
PlaceholderColor="Gray"
/>
<Frame CornerRadius="20" Grid.Row="2" Margin="0,5"/>
<Entry
Grid.Row="2"
x:Name="lastname"
HorizontalOptions="Fill"
Margin="10,5"
TextColor="Black"
Placeholder="Last Name"
PlaceholderColor="Gray"
FontSize="16"
/>
<Frame CornerRadius="20" Grid.Row="3" Margin="0,5"/>
<Entry
FontSize="16"
Grid.Row="3"
x:Name="role"
HorizontalOptions="Fill"
Margin="10,5"
TextColor="Black"
Placeholder="Role"
PlaceholderColor="Gray"
/>
<Frame CornerRadius="20" Grid.Row="4" Margin="0,5"/>
<Entry
FontSize="16"
Grid.Row="4"
x:Name="user_name"
HorizontalOptions="Fill"
Margin="10,5"
TextColor="Black"
Placeholder="Username"
PlaceholderColor="Gray"
/>
<Frame CornerRadius="20" Grid.Row="5" Margin="0,5"/>
<Entry
FontSize="16"
Grid.Row="5"
x:Name="password"
HorizontalOptions="Fill"
Margin="10,5"
TextColor="Black"
Placeholder="Password"
PlaceholderColor="Gray"
/>
<StackLayout Orientation="Horizontal" Grid.Row="6">
<Label Text="Allow Access" TextColor="Black" FontSize="16" HorizontalOptions="Center" VerticalOptions="Center" Margin="15,5"/>
<Switch
ThumbColor="Black"
OnColor="White"
x:Name="appaccess"
HorizontalOptions="Center"
VerticalOptions="Center"
Margin="40,0"
/>
</StackLayout>
</Grid>
</Frame>
<Button CornerRadius="50" Text="Submit" FontSize="Medium" BackgroundColor="White" TextColor="Black" FontFamily="audiofont" x:Name="save" HeightRequest="60" WidthRequest="140" HorizontalOptions="Center" Margin="0,-85" />
</StackLayout>
<Frame CornerRadius="50" HeightRequest="100" WidthRequest="100" HorizontalOptions="Center" VerticalOptions="Start" Padding="-2" BorderColor="White" Margin="20,5,20,0">
<Image HeightRequest="150" WidthRequest="150" x:Name="userprofile" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Source="grass.png"/>
</Frame>
</Grid>
</StackLayout>
</ScrollView>
</ContentPage.Content>
Change the Margin
<Frame CornerRadius="50" BorderColor="White" BackgroundColor="Transparent" Margin="20,50">
<Grid Padding="1" ColumnSpacing="1" RowSpacing="0" Margin="0,90">

Xamarin Community Toolkit TabView badge does not work with ControlTemplate

I am using the Xamarin Community Toolkit TabView with a ControlTemplate in the TabViewItem, it works well. I tried adding a Badge to the TabViewItem and nothing happens. When I remove the ControlTemplate the Badge works perfectly. As a sanity test, I pulled the XCT sample code and tried adding a control template to a working TabView badge example and got the same results, no badge.
I am hoping that I am just missing something simple, but I have a feeling that the ControlTemplate and Badge are not compatible...
Does anyone have any examples of and XCT TabViewItem using a ControlTemplate and a badge?
Here is the sample xaml from the CustomTabsPage.xaml in the XCT Samples. I modified it by adding a Badge to the first tab, but it does not show the badge.
<pages:BasePage>
<pages:BasePage.Resources>
<ResourceDictionary>
<ControlTemplate
x:Key="TabItemTemplate">
<Grid
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image
Grid.Row="0"
VerticalOptions="Center"
HorizontalOptions="Center"
WidthRequest="24"
HeightRequest="24"
Margin="6"
Source="{TemplateBinding CurrentIcon}" />
<Label
Grid.Row="1"
HorizontalOptions="Center"
FontSize="{TemplateBinding FontSize}"
Text="Test"
TextColor="{TemplateBinding CurrentTextColor}" />
</Grid>
</ControlTemplate>
<ControlTemplate
x:Key="FabTabItemTemplate">
<Grid>
<ImageButton
InputTransparent="True"
Source="{TemplateBinding CurrentIcon}"
Padding="10"
HorizontalOptions="Center"
BackgroundColor="#FF0000"
HeightRequest="60"
WidthRequest="60"
Margin="6">
<ImageButton.CornerRadius>
<OnPlatform x:TypeArguments="x:Int32">
<On Platform="iOS" Value="30"/>
<On Platform="Android" Value="60"/>
<On Platform="UWP" Value="36"/>
</OnPlatform>
</ImageButton.CornerRadius>
<ImageButton.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean">
<On Platform="Android, iOS, UWP">True</On>
<On Platform="macOS">False</On>
</OnPlatform>
</ImageButton.IsVisible>
</ImageButton>
<BoxView
InputTransparent="True"
HorizontalOptions="Center"
CornerRadius="30"
BackgroundColor="#FF0000"
HeightRequest="60"
WidthRequest="60"
Margin="6">
<BoxView.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean">
<On Platform="Android, iOS, UWP">False</On>
<On Platform="macOS">True</On>
</OnPlatform>
</BoxView.IsVisible>
</BoxView>
</Grid>
</ControlTemplate>
<Style
x:Key="TabItemStyle"
TargetType="xct:TabViewItem">
<Setter
Property="FontSize"
Value="12" />
<Setter
Property="TextColor"
Value="#979797" />
<Setter
Property="TextColorSelected"
Value="#FF0000" />
</Style>
<Style
x:Key="CustomTabStyle"
TargetType="xct:TabView">
<Setter
Property="IsTabTransitionEnabled"
Value="True" />
<Setter
Property="TabStripHeight"
Value="48" />
<Setter
Property="TabContentBackgroundColor"
Value="#484848" />
<Setter
Property="TabStripPlacement"
Value="Bottom" />
</Style>
</ResourceDictionary>
</pages:BasePage.Resources>
<pages:BasePage.Content>
<Grid>
<xct:TabView
Style="{StaticResource CustomTabStyle}">
<xct:TabView.TabStripBackgroundView>
<BoxView
Color="#484848"
CornerRadius="36, 36, 0, 0"/>
</xct:TabView.TabStripBackgroundView>
<xct:TabViewItem
Text="Tab 1"
Icon="triangle.png"
ControlTemplate="{StaticResource TabItemTemplate}"
BadgeText="Test"
BadgeBackgroundColor="Pink"
BadgeBackgroundColorSelected="Red"
BadgeTextColor="White"
Style="{StaticResource TabItemStyle}">
<Grid
BackgroundColor="LawnGreen">
<Label
HorizontalOptions="Center"
VerticalOptions="Center"
Text="TabContent1" />
</Grid>
</xct:TabViewItem>
<xct:TabViewItem
Text="Tab 2"
Icon="circle.png"
ControlTemplate="{StaticResource FabTabItemTemplate}"
Style="{StaticResource TabItemStyle}"
TabTapped="OnFabTabTapped" />
<xct:TabViewItem
Text="Tab 3"
Icon="square.png"
ControlTemplate="{StaticResource TabItemTemplate}"
Style="{StaticResource TabItemStyle}">
<Grid
BackgroundColor="LightCoral">
<Label
HorizontalOptions="Center"
VerticalOptions="Center"
Text="TabContent3" />
</Grid>
</xct:TabViewItem>
</xct:TabView>
</Grid>
</pages:BasePage.Content>
</pages:BasePage>
You could add a BageView in your ControlTemplate like below and then remove the Badge properties in TabViewItem.
Also please slightly adjust the position of the badge where you want to place it.
<ControlTemplate
x:Key="TabItemTemplate">
<Grid
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image
Grid.Row="0"
VerticalOptions="Center"
HorizontalOptions="Center"
WidthRequest="24"
HeightRequest="24"
Margin="6"
Source="{TemplateBinding CurrentIcon}" />
<Label
Grid.Row="1"
HorizontalOptions="Center"
FontSize="{TemplateBinding FontSize}"
Text="Test"
TextColor="{TemplateBinding CurrentTextColor}" />
<xct:BadgeView
Grid.Row="0" Grid.Column="1"
BackgroundColor="Pink"
TextColor="White"
Text="123"
/>
</Grid>
</ControlTemplate>
Reference link:
https://learn.microsoft.com/en-us/xamarin/community-toolkit/views/badgeview

BottomBar with customizations

I wish I could create a BottomBar that would allow me to have a graphic like this, with a button bigger than all the others. I tried with a TabbedPage but it doesn't allow me this customization. I tried with a TabView but it doesn't allow me to insert ContentPage pages by pressing buttons. I would like a BottomBar that would allow me to have this graphic and to be able to use pages as button content.
Example
You could use TabView With Action Button from the Xamarin Community Toolkit linked below. By not assigning any content and instead assigning an event to the TabTapped property, you will display a button instead of another tab.
Install from NuGet: https://www.nuget.org/packages/Xamarin.CommunityToolkit/
Add xct:
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
Xaml:
<ContentPage.Resources>
<ResourceDictionary>
<ControlTemplate
x:Key="TabItemTemplate">
<Grid
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image
Grid.Row="0"
VerticalOptions="Center"
HorizontalOptions="Center"
WidthRequest="24"
HeightRequest="24"
Margin="6"
Source="{TemplateBinding CurrentIcon}" />
<Label
Grid.Row="1"
HorizontalOptions="Center"
FontSize="{TemplateBinding FontSize}"
Text="{TemplateBinding Text}"
TextColor="{TemplateBinding CurrentTextColor}" />
</Grid>
</ControlTemplate>
<ControlTemplate
x:Key="FabTabItemTemplate">
<Grid>
<ImageButton
InputTransparent="True"
Source="circle.png"
Padding="10"
HorizontalOptions="Center"
BackgroundColor="#FF0000"
HeightRequest="60"
WidthRequest="60"
Margin="6">
<ImageButton.CornerRadius>
<OnPlatform x:TypeArguments="x:Int32">
<On Platform="iOS" Value="30"/>
<On Platform="Android" Value="60"/>
<On Platform="UWP" Value="36"/>
</OnPlatform>
</ImageButton.CornerRadius>
<ImageButton.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean">
<On Platform="Android, iOS, UWP">True</On>
<On Platform="macOS">False</On>
</OnPlatform>
</ImageButton.IsVisible>
</ImageButton>
<BoxView
InputTransparent="True"
HorizontalOptions="Center"
CornerRadius="30"
BackgroundColor="#FF0000"
HeightRequest="60"
WidthRequest="60"
Margin="6">
<BoxView.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean">
<On Platform="Android, iOS, UWP">False</On>
<On Platform="macOS">True</On>
</OnPlatform>
</BoxView.IsVisible>
</BoxView>
</Grid>
</ControlTemplate>
<Style
x:Key="TabItemStyle"
TargetType="xct:TabViewItem">
<Setter
Property="FontSize"
Value="12" />
<Setter
Property="TextColor"
Value="#979797" />
<Setter
Property="TextColorSelected"
Value="#FF0000" />
</Style>
<Style
x:Key="CustomTabStyle"
TargetType="xct:TabView">
<Setter
Property="IsTabTransitionEnabled"
Value="True" />
<Setter
Property="TabStripHeight"
Value="48" />
<Setter
Property="TabContentBackgroundColor"
Value="#484848" />
<Setter
Property="TabStripPlacement"
Value="Bottom" />
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<Grid>
<xct:TabView
Style="{StaticResource CustomTabStyle}">
<xct:TabView.TabStripBackgroundView>
<BoxView
Color="#484848"
CornerRadius="36, 36, 0, 0"/>
</xct:TabView.TabStripBackgroundView>
<xct:TabViewItem
Text="Tab 1"
Icon="triangle.png"
ControlTemplate="{StaticResource TabItemTemplate}"
Style="{StaticResource TabItemStyle}">
<Grid
BackgroundColor="LawnGreen">
<Label
HorizontalOptions="Center"
VerticalOptions="Center"
Text="TabContent1" />
</Grid>
</xct:TabViewItem>
<xct:TabViewItem
Text="Tab 2"
Icon="circle.png"
ControlTemplate="{StaticResource FabTabItemTemplate}"
Style="{StaticResource TabItemStyle}"
TabTapped="OnFabTabTapped" />
<xct:TabViewItem
Text="Tab 3"
Icon="square.png"
ControlTemplate="{StaticResource TabItemTemplate}"
Style="{StaticResource TabItemStyle}">
<Grid
BackgroundColor="LightCoral">
<Label
HorizontalOptions="Center"
VerticalOptions="Center"
Text="TabContent3" />
</Grid>
</xct:TabViewItem>
</xct:TabView>
</Grid>
Update:
Do I have the possibility to insert a ContentPage by pressing on in TabViewItem and keep the TabVIew
You could set the page as contentview.
<?xml version="1.0" encoding="utf-8" ?>
<ContentView
x:Class="App9.Page1"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ContentView.Content>
<StackLayout>
<Label
HorizontalOptions="CenterAndExpand"
Text="Welcome to Page1!"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentView.Content>
</ContentView>
public partial class Page1 : ContentView
{
public Page1()
{
InitializeComponent();
}
}
And then load in the TabViewItem.
<xct:TabViewItem
ControlTemplate="{StaticResource TabItemTemplate}"
Icon="square.png"
Style="{StaticResource TabItemStyle}"
Text="Tab 3">
<!--<Grid
BackgroundColor="LightCoral">
<Label
HorizontalOptions="Center"
VerticalOptions="Center"
Text="TabContent3" />
</Grid>-->
<local:Page1 />
</xct:TabViewItem>

Move buttons on the bottom and give more space for editor

I am struggling with two things in xamarin forms layout. As shown on the picture i need to make more space for edidor control (highlited as 1) as this will be the place for user's comment. I would like to extend it to the right (max width). Second thing is i need to move buttons to the bottom which i thought i could solve that by settiung VerticalOptions="End" in the <Grid Grid.Row ="4" (higlighted as 2). How can i solve both things up? Below also full xaml code.
Xaml:
<?xml version="1.0" encoding="utf-8" ?>
<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="MobileAppXamarinForms.Views.Order.OrderHatModifyPage"
Title="{Binding SelectedHatOrder.OrderId, StringFormat='Numer zamówienia: {0}'}">
<ContentPage.Content>
<StackLayout Orientation="Vertical">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row ="0" HorizontalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Padding="30,1,1,1"
FontAttributes="None"
FontSize="16"
HorizontalOptions="FillAndExpand"
Text="{Binding SelectedHatOrder.OrderId, StringFormat='NUMER ZAMÓWIENIA: {0}'}"
TextColor="Gray"
VerticalOptions="Center" />
<Label
Grid.Column="1"
HorizontalOptions="FillAndExpand"
Text=" " />
<Label
Grid.Column="2"
FontSize="15"
HorizontalOptions="Start"
Text="KLIENT:"
VerticalOptions="Center" />
<Label
Grid.Column="3"
Padding="5,1,1,1"
FontAttributes="None"
FontSize="16"
HorizontalOptions="FillAndExpand"
Text="{Binding SelectedClient.Value, StringFormat='{0}'}"
TextColor="Gray"
VerticalOptions="Center" />
<Label
Grid.Column="4"
HorizontalOptions="StartAndExpand"
Text="NA DZIEŃ:"
VerticalOptions="Center" />
<DatePicker
Grid.Column="5"
Date="{Binding SelectedTargetDate, Mode=TwoWay}"
Format="dd.MM.yyyy"
HorizontalOptions="StartAndExpand" />
</Grid>
<Grid Grid.Row ="1" Margin="5" HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
<!--szerokosc, aby zmiescila sie nazwa butli-->
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label
Grid.Column="0"
Padding="30,1,1,1"
FontAttributes="None"
FontSize="15"
HorizontalOptions="FillAndExpand"
Text="KWOTA:"
TextColor="Gray"
VerticalOptions="Center" />
<Entry
Grid.Column="1"
HorizontalOptions="Start"
Keyboard="Numeric"
MaxLength="5"
Placeholder="Kwota"
Text="{Binding SelectedPrice, Mode=TwoWay}" />
<Label
Grid.Column="2"
HorizontalOptions="FillAndExpand"
Text=" " />
<Label
Grid.Column="3"
FontSize="15"
HorizontalOptions="Start"
Text="ILOŚĆ:"
VerticalOptions="Center" />
<Entry
Grid.Column="4"
HorizontalOptions="Start"
Keyboard="Numeric"
MaxLength="5"
Placeholder="Ilość"
Text="{Binding SelectedAmount, Mode=TwoWay}" />
</Grid>
<Grid Grid.Row ="2" >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" VerticalOptions="Start">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Padding="30,1,1,1"
FontAttributes="None"
FontSize="15"
HorizontalOptions="FillAndExpand"
Text="Komentarz:"
TextColor="Gray"
VerticalOptions="Center" />
<Editor
Grid.Column="1"
HorizontalOptions="CenterAndExpand"
Keyboard="Text"
MaxLength="3000"
Placeholder="Komentarz"
Text="{Binding SelectedComment, Mode=TwoWay}" />
</Grid>
</Grid>
<Grid Grid.Row ="3" VerticalOptions="StartAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Padding="30,1,1,1"
FontAttributes="None"
FontSize="15"
HorizontalOptions="FillAndExpand"
Text="Typ płatności:"
TextColor="Gray"
VerticalOptions="Center" />
<Picker
Grid.Column="1"
Title="Typ płatności"
FontSize="15"
HorizontalOptions="FillAndExpand"
ItemDisplayBinding="{Binding Value}"
ItemsSource="{Binding PaymentTypes}"
SelectedIndex="{Binding Id}"
SelectedItem="{Binding SelectedPaymentType, Mode=TwoWay}"
VerticalOptions="Center" />
<Label
Grid.Column="2"
Padding="30,1,1,1"
FontAttributes="None"
FontSize="15"
HorizontalOptions="FillAndExpand"
Text="Ilość dni:"
TextColor="Gray"
IsVisible="{Binding IsDaysCountVisible, Mode=TwoWay}"
VerticalOptions="Center" />
<Entry
Grid.Column="3"
HorizontalOptions="Start"
Keyboard="Numeric"
MaxLength="5"
Placeholder="Ilość dni"
IsVisible="{Binding IsDaysCountVisible, Mode=TwoWay}"
Text="{Binding SelectedDaysCount, Mode=TwoWay}" />
</Grid>
<!-- Buttons section -->
<Grid Grid.Row ="4" VerticalOptions="End">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*" />
<ColumnDefinition Width="50*" />
</Grid.ColumnDefinitions>
<Button
Grid.Column="0"
BackgroundColor="DarkMagenta"
Command="{Binding SaveOrderCommand}"
FontAttributes="Bold"
FontSize="20"
Text="Zatwierdz"
TextColor="White"
HorizontalOptions="FillAndExpand" />
<Button
Grid.Column="1"
BackgroundColor="MediumVioletRed"
Command="{Binding ExitCommand}"
FontAttributes="Bold"
FontSize="20"
Text="Anuluj"
TextColor="White"
HorizontalOptions="FillAndExpand" />
</Grid>
</Grid>
</StackLayout>
</ContentPage.Content>
</ContentPage>
So, as #Jason said in the comments, you have to remove the <StackLayout /> because it prevents the Grid to fill the page.
Thus, for your other issue, I tried to reproduce it.
I've found that if you change the HorizontalOptions of your <Editor /> from CenterAndExpand to FillAndExpand this solves the issue (you can also remove the HorizontalOptions altogether).
So, instead of:
<Editor
Grid.Column="1"
HorizontalOptions="CenterAndExpand"
Keyboard="Text"
MaxLength="3000"
Placeholder="Komentarz"
Text="{Binding SelectedComment, Mode=TwoWay}" />
Try:
<Editor
Grid.Column="1"
HorizontalOptions="FillAndExpand"
Keyboard="Text"
MaxLength="3000"
Placeholder="Komentarz"
Text="{Binding SelectedComment, Mode=TwoWay}" />
Or:
<Editor Grid.Column="1"
Keyboard="Text"
MaxLength="3000"
Placeholder="Komentarz"
Text="{Binding SelectedComment, Mode=TwoWay}" />
For more about this: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/layout-options
For good measure, you can also remove Keyboard="Text" since Keyboard's default value is already Text 😉
I hope this solved your issue.
However, if you've got any concerns with my Answer please let me know 🙂

Position 1st StackLayout on page at the bottom Xamarin.Forms

I am new to Xamarin and I am trying to position my first stacklayout of the page at the bottom of the screen and then scroll to see the remaining content.
Also, I have an image as background for my content page and I am trying to use scrollview for rest of the page content. I tried other solutions on StackOverflow but they have StackLayouts VerticalOptions as Center and Start which I don’t. I want the first stacklayout to start from the bottom and no control/layout above that.
Also, this contentpage acts as a Detail page for a MasterDetailPage.
This is my contentpage so far -
<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="Excercise.Views.HomePage" Title="App"
NavigationPage.HasBackButton="False" BackgroundImageSource="image.jpg">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Option1"></ToolbarItem>
<ToolbarItem Text="Option2"></ToolbarItem>
</ContentPage.ToolbarItems>
<!--<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="tab_feed.png"/>
</OnPlatform>
</NavigationPage.Icon>-->
<ContentPage.Content>
<StackLayout Orientation="Horizontal" >
<ScrollView>
<StackLayout Orientation="Vertical" VerticalOptions="EndAndExpand">
<Frame BorderColor="Gray" CornerRadius="5" Padding="5" Margin="10" VerticalOptions="EndAndExpand">
<Grid VerticalOptions="EndAndExpand">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label x:Name="Label1" FontSize="Large" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" ></Label>
<Label x:Name="Label2" FontSize="Medium" Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2"></Label>
<BoxView BackgroundColor="Black" Grid.Row="1" Grid.ColumnSpan="6"></BoxView>
<Label x:Name="Label3" FontSize="Large" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="3"></Label>
<Label Text="Label4" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Grid.RowSpan="3"></Label>
<Label x:Name="Label5" Grid.Row="5" Grid.ColumnSpan="2"></Label>
<Label x:Name="Label6" Grid.Row="2" Grid.Column="3" Grid.ColumnSpan="2"></Label>
<Label x:Name="Label7" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="2"></Label>
<Label x:Name="Label8" Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2"></Label>
<Label x:Name="Label9" Grid.Row="5" Grid.Column="3" Grid.ColumnSpan="2"></Label>
<CollectionView x:Name="collecview1" WidthRequest="100" Grid.Row="6" Grid.RowSpan="3" Grid.ColumnSpan="6" ItemsLayout="HorizontalList" >
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Vertical" Padding="5,25,30,25" VerticalOptions="Center">
<Label Text="{Binding Text}"></Label>
<Image Source="{Binding Text}"></Image>
<Label Text="{Binding Text}" HorizontalTextAlignment="Center"></Label>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</Frame>
<Frame BorderColor="Gray" CornerRadius="5" Padding="5" Margin="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackLayout Grid.Row="0" Grid.Column="0">
<Label Text="Label10"></Label>
<BoxView BackgroundColor="Gray" HeightRequest="2"></BoxView>
<CollectionView x:Name="collecview2" ItemsLayout="VerticalList" ItemSizingStrategy="MeasureAllItems">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding Text}" Grid.Column="0" HorizontalTextAlignment="End" ></Label>
<Label Text="Image" Grid.Column="1"></Label>
<!--<Image Source="{Binding IconSource}" Grid.Column="1"></Image>-->
<Label Text="{Binding Text}" FontAttributes="Bold" Grid.Column="2"></Label>
<Label Text="{Binding Text}" Grid.Column="3"></Label>
<Label Text="{Binding Text}" Grid.Column="4"></Label>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</Grid>
</Frame>
<Frame BorderColor="Gray" CornerRadius="5" Padding="5" Margin="10">
<StackLayout>
<Label Text="Label23"></Label>
<BoxView BackgroundColor="Black" HeightRequest="2"></BoxView>
</StackLayout>
</Frame>
</StackLayout>
</ScrollView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
MainPage.xaml.cs
[DesignTimeVisible(false)]
public partial class MainPage : MasterDetailPage
{
public MainPage()
{
InitializeComponent();
MasterBehavior = MasterBehavior.Split;
Detail = new HomePage();
}
public MainPage(string City, string lockey,string StateID)
{
InitializeComponent();
Detail = new HomePage(City,lockey,StateID);
}
}
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage 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"
xmlns:local="clr-namespace:Excercise.Views"
x:Class="Excercise.MainPage" Title="App" IsPresented="False">
<MasterDetailPage.Master>
<local:MenuPage Title="MenuPage" x:Name="menuPage"></local:MenuPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<local:HomePage Title="HomePage" x:Name="homePage" BackgroundImageSource="raleigh.jpg"></local:HomePage>
</MasterDetailPage.Detail>
</MasterDetailPage>
Is there anyway to achieve this? Any help is much appreciated!
Thank you so much!
I want the first stacklayout to start from the bottom and no
control/layout above that.
You can give your first stacklayout a top margin with screen height request so that it will start from the bottom.
In xaml, give a name to your StackLayout :
<StackLayout Orientation="Vertical" VerticalOptions="End" x:Name="firstStacklayout">
In code behind:
protected override void OnAppearing()
{
base.OnAppearing();
firstStacklayout.Margin = new Thickness(0, Application.Current.MainPage.Height, 0, 0);
}

Resources