I'm trying to develop a Xamarin.Forms application.
I have the following grid, displayed like a piano keyboard:
and, for example, this code, in xaml:
<Grid ColumnSpacing="2">
<Grid.RowDefinitions>
<RowDefinition Height="120" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Button
Grid.RowSpan="2"
Grid.Column="0"
BackgroundColor="White"
Text="C"
TextColor="Black"
WidthRequest="45" />
<Button
Grid.RowSpan="2"
Grid.Column="1"
BackgroundColor="White"
Text="D"
TextColor="Black"
WidthRequest="45" />
<Button
Grid.RowSpan="2"
Grid.Column="2"
BackgroundColor="White"
Text="E"
TextColor="Black"
WidthRequest="45" />
<Button
Grid.RowSpan="2"
Grid.Column="3"
BackgroundColor="White"
Text="F"
TextColor="Black"
WidthRequest="45" />
<Button
Grid.RowSpan="2"
Grid.Column="4"
BackgroundColor="White"
Text="G"
TextColor="Black"
WidthRequest="45" />
<Button
Grid.RowSpan="2"
Grid.Column="5"
BackgroundColor="White"
Text="A"
TextColor="Black"
WidthRequest="45" />
<Button
Grid.RowSpan="2"
Grid.Column="6"
BackgroundColor="White"
Text="B"
TextColor="Black"
WidthRequest="45" />
<Button
Grid.Column="0"
Grid.ColumnSpan="2"
BackgroundColor="Black"
HorizontalOptions="Center"
Text="C#"
TextColor="White"
WidthRequest="35" />
<Button
Grid.Column="1"
Grid.ColumnSpan="2"
BackgroundColor="Black"
HorizontalOptions="Center"
Text="D#"
TextColor="White"
WidthRequest="35" />
<Button
Grid.Column="3"
Grid.ColumnSpan="2"
BackgroundColor="Black"
HorizontalOptions="Center"
Text="F#"
TextColor="White"
WidthRequest="35" />
<Button
Grid.Column="4"
Grid.ColumnSpan="2"
BackgroundColor="Black"
HorizontalOptions="Center"
Text="G#"
TextColor="White"
WidthRequest="35" />
<Button
Grid.Column="5"
Grid.ColumnSpan="2"
BackgroundColor="Black"
HorizontalOptions="Center"
Text="A#"
TextColor="White"
WidthRequest="35" />
</Grid>
My issue is that when I click a white button (e.g. "A" button), this happens:
Do you happen to know how I can fix the position of the buttons, in order to avoid this overlapping?
I'm not sure if the grid is the best way to achieve what I want to display, but I assumed it would be a good choice. If you have a better container for this, please let me know.
Related
I am developing one android application using xamarin android. I am designing one page using xaml. in my screen i have 5 images. it is basically a login screen. but here entry(textbox) is not focused and also button press is not working. if i remove some images and stacklayouts then it is working fine.
below is my xaml
<StackLayout>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="745"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" Spacing="10" Grid.Column="0" >
<Grid Grid.Column="0" ColumnSpacing="80" RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
<RowDefinition Height="250"/>
</Grid.RowDefinitions>
<Image Source="image1.png" Margin="0" Grid.Row="0" Grid.Column="0" HorizontalOptions="StartAndExpand" HeightRequest="100" WidthRequest="200" />
<Image Source="image3.png" Margin="0" Grid.Row="0" Grid.Column="1" HorizontalOptions="StartAndExpand" HeightRequest="100" WidthRequest="200" />
<Label x:Name="lblTitle" FontSize="22" TextColor="Blue" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
FontAttributes="Bold" VerticalOptions="Center"
HorizontalTextAlignment="Center" Text="Title goes here"/>
<Image Source="image3.png" Grid.Row="2" Grid.Column="0" HorizontalOptions="StartAndExpand" HeightRequest="500" WidthRequest="500" />
<StackLayout Grid.Row="2" Grid.Column="1" InputTransparent="False" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="40"/>
<RowDefinition Height="30"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Label FontSize="15" TextColor="Blue" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"
FontAttributes="Bold" VerticalOptions="Center"
HorizontalTextAlignment="Start" Text="User Name"/>
<Frame BorderColor="DodgerBlue" CornerRadius="0" Padding="0" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2">
<Entry x:Name="txtUsername" FontFamily="{StaticResource UbuntuRegularFontFamily}" Placeholder="Enter Username" HorizontalOptions="FillAndExpand" Text="" FontSize="15"/>
</Frame>
<Label FontSize="15" TextColor="Blue" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2"
FontAttributes="Bold" VerticalOptions="Center"
HorizontalTextAlignment="Start" Text="Password"/>
<Frame BorderColor="DodgerBlue" CornerRadius="0" Padding="0" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2">
<Entry x:Name="txtPassword" FontFamily="{StaticResource UbuntuRegularFontFamily}" Placeholder="Enter Password" IsPassword="True" HorizontalOptions="FillAndExpand" Text="" FontSize="15"/>
</Frame>
<Button x:Name="btnlogin" Grid.Row="4" Grid.Column="0" Text="LOGIN" WidthRequest="100" HeightRequest="40" ></Button>
<Button x:Name="btnCancel" Grid.Row="4" Grid.Column="1" Text="CANCEL" WidthRequest="100" HeightRequest="40" ></Button>
</Grid>
</StackLayout>
</Grid>
</StackLayout>
<StackLayout Grid.Row="3" InputTransparent="True">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Source="image4.png" Margin="0" Grid.Row="1" Grid.Column="0" HorizontalOptions="StartAndExpand" HeightRequest="400" WidthRequest="250" />
<Label FontSize="25" TextColor="Black" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
FontAttributes="Bold" VerticalOptions="Center"
HorizontalTextAlignment="Center" Text="year "/>
<Label FontSize="25" TextColor="Black" Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2"
FontAttributes="Bold" VerticalOptions="Center"
HorizontalTextAlignment="Center" Text="company name goes here"/>
</Grid>
</StackLayout>
<StackLayout Grid.RowSpan="1" Grid.Column="1" InputTransparent="True">
<Image Source="image5.png" Margin="0"
/>
</StackLayout>
</Grid >
</StackLayout>
but here entry(textbox) is not focused and also button press is not working. if i remove some images and stacklayouts then it is working fine.
I test you code, and find you put the following code in wrong place.
<StackLayout Grid.Row="3">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Image
Grid.Row="1"
Grid.Column="0"
Margin="0"
HeightRequest="400"
HorizontalOptions="StartAndExpand"
Source="check.png"
WidthRequest="250" />
<Label
Grid.Row="1"
Grid.Column="1"
FontAttributes="Bold"
FontSize="25"
HorizontalTextAlignment="Center"
Text="year "
TextColor="Black"
VerticalOptions="Center" />
<Label
Grid.Row="1"
Grid.Column="2"
FontAttributes="Bold"
FontSize="25"
HorizontalTextAlignment="Center"
Text="company name goes here"
TextColor="Black"
VerticalOptions="Center" />
</Grid>
</StackLayout>
You just define 3 RowDefinitions, but you use Grid.Row="3" above code.
<StackLayout
Grid.Column="0"
HorizontalOptions="Center"
Orientation="Horizontal"
Spacing="10">
<Grid
Grid.Column="0"
ColumnSpacing="80"
RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="100" />
<RowDefinition Height="250" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
please take a look the following code, I use my image source.
<StackLayout>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackLayout
Grid.Column="0"
HorizontalOptions="Center"
Orientation="Horizontal"
Spacing="10">
<Grid
Grid.Column="0"
ColumnSpacing="80"
RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="100" />
<RowDefinition Height="250" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Image
Grid.Row="0"
Grid.Column="0"
Margin="0"
HeightRequest="100"
HorizontalOptions="StartAndExpand"
Source="c1.png"
WidthRequest="200" />
<Image
Grid.Row="0"
Grid.Column="1"
Margin="0"
HeightRequest="100"
HorizontalOptions="StartAndExpand"
Source="c10.png"
WidthRequest="200" />
<Label
x:Name="lblTitle"
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
FontAttributes="Bold"
FontSize="22"
HorizontalTextAlignment="Center"
Text="Title goes here"
TextColor="Blue"
VerticalOptions="Center" />
<Image
Grid.Row="2"
Grid.Column="0"
HeightRequest="500"
HorizontalOptions="StartAndExpand"
Source="c11.png"
WidthRequest="500" />
<StackLayout
Grid.Row="2"
Grid.Column="1"
InputTransparent="False">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="40" />
<RowDefinition Height="30" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
FontAttributes="Bold"
FontSize="15"
HorizontalTextAlignment="Start"
Text="User Name"
TextColor="Blue"
VerticalOptions="Center" />
<Frame
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
Padding="0"
BorderColor="DodgerBlue"
CornerRadius="0">
<Entry
x:Name="txtUsername"
FontSize="15"
HorizontalOptions="FillAndExpand"
Placeholder="Enter Username"
Text="" />
</Frame>
<Label
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2"
FontAttributes="Bold"
FontSize="15"
HorizontalTextAlignment="Start"
Text="Password"
TextColor="Blue"
VerticalOptions="Center" />
<Frame
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
Padding="0"
BorderColor="DodgerBlue"
CornerRadius="0">
<Entry
x:Name="txtPassword"
FontSize="15"
HorizontalOptions="FillAndExpand"
IsPassword="True"
Placeholder="Enter Password"
Text="" />
</Frame>
<Button
x:Name="btnlogin"
Grid.Row="4"
Grid.Column="0"
HeightRequest="40"
Text="LOGIN"
WidthRequest="100" />
<Button
x:Name="btnCancel"
Grid.Row="4"
Grid.Column="1"
HeightRequest="40"
Text="CANCEL"
WidthRequest="100" />
</Grid>
</StackLayout>
<StackLayout Grid.Row="3" InputTransparent="True">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image
Grid.Row="1"
Grid.Column="0"
Margin="0"
HeightRequest="400"
HorizontalOptions="StartAndExpand"
Source="check.png"
WidthRequest="250" />
<Label
Grid.Row="1"
Grid.Column="1"
Grid.ColumnSpan="2"
FontAttributes="Bold"
FontSize="25"
HorizontalTextAlignment="Center"
Text="year "
TextColor="Black"
VerticalOptions="Center" />
<Label
Grid.Row="1"
Grid.Column="2"
Grid.ColumnSpan="2"
FontAttributes="Bold"
FontSize="25"
HorizontalTextAlignment="Center"
Text="company name goes here"
TextColor="Black"
VerticalOptions="Center" />
</Grid>
</StackLayout>
</Grid>
</StackLayout>
<StackLayout
Grid.RowSpan="1"
Grid.Column="1"
InputTransparent="True">
<Image Margin="0" Source="image5.png" />
</StackLayout>
</Grid>
</StackLayout>
My listview when new items are added overlaps the buttons. The buttons seems to have same place on the center of application. I would love to have them at the bottom. From the other hand listview should expand to the buttons and then scroll should appear. Last thing is the listview itself overlaps top part of controls and there is need to make more space i suppose (i highlited it on black on the picture. How can i fix that? Below screnshoot how it looks at the moment and current code as well. Thanks.
Full 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"
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.OrderModifyPage"
Title="{Binding SelectedOrder.OrderId, StringFormat='Numer zamówienia: {0}'}">
<ContentPage.Content>
<StackLayout Orientation="Vertical">
<Grid ColumnSpacing="4" HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="{Binding SelectedOrder.OrderId, StringFormat='NUMER ZAMÓWIENIA: {0}'}" FontSize="16" TextColor="Gray" Grid.Column="0" Padding="30,1,1,1" FontAttributes="None" HorizontalOptions="FillAndExpand" VerticalOptions="Center"/>
<Label Text=" " Grid.Column="1" HorizontalOptions="FillAndExpand"/>
<Label Text="KLIENT:" FontSize="15" VerticalOptions="Center" Grid.Column="2" HorizontalOptions="Start"/>
<Label Text="{Binding SelectedClient.Value, StringFormat='{0}'}" FontSize="16" TextColor="Gray" Grid.Column="3"
Padding="5,1,1,1" FontAttributes="None" HorizontalOptions="FillAndExpand" VerticalOptions="Center"/>
<Label Text="NA DZIEŃ:" Grid.Column="4" HorizontalOptions="FillAndExpand" VerticalOptions="Center"/>
<DatePicker Date="{Binding SelectedTargetDate, Mode=TwoWay}" Format="dd.MM.yyyy"
Grid.Column="5" HorizontalOptions="FillAndExpand"/>
</Grid>
<Grid ColumnSpacing="4" HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="BUTLA:" FontSize="15" TextColor="Gray" Grid.Column="0" Padding="30,1,1,1" FontAttributes="None" HorizontalOptions="FillAndExpand" VerticalOptions="Center"/>
<Picker Title="BUTLA" ItemsSource="{Binding Bottles}" SelectedItem="{Binding SelectedBottle, Mode=TwoWay}" ItemDisplayBinding="{Binding Value}" SelectedIndex="{Binding Id}" FontSize="15" VerticalOptions="Center" Grid.Column="1" HorizontalOptions="FillAndExpand"/>
<Label Text=" " Grid.Column="2" HorizontalOptions="FillAndExpand"/>
<Label Text="ILOŚĆ:" FontSize="15" VerticalOptions="Center" Grid.Column="3" HorizontalOptions="Start"/>
<Entry Placeholder="Ilość" Text="{Binding SelectedAmount, Mode=TwoWay}" Keyboard="Numeric" MaxLength="5" Grid.Column="4" HorizontalOptions="Start"/>
</Grid>
<StackLayout Orientation="Vertical" VerticalOptions="Fill">
<Grid ColumnSpacing="0" RowSpacing="0" VerticalOptions="Fill">
<!--Listview section-->
<ListView ItemsSource="{Binding SelectedItems}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" VerticalScrollBarVisibility="Always">
<ListView.Header>
<Grid BackgroundColor="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Text="Nazwa butli" HorizontalOptions="Fill" Grid.Column="0" FontSize="Medium" FontAttributes="Bold" BackgroundColor="LightBlue" TextColor="White" HorizontalTextAlignment="Center" Margin="1"/>
<Label Text="Pełna?" HorizontalOptions="Fill" Grid.Column="1" FontSize="Medium" FontAttributes="Bold" BackgroundColor="LightBlue" TextColor="White" HorizontalTextAlignment="Center" Margin="1"/>
<Label Text="Ilość" HorizontalOptions="Fill" Grid.Column="2" FontSize="Medium" FontAttributes="Bold" BackgroundColor="LightBlue" TextColor="White" HorizontalTextAlignment="Center" Margin="1"/>
<Label Text="Kwota" HorizontalOptions="Fill" Grid.Column="3" FontSize="Medium" FontAttributes="Bold" BackgroundColor="LightBlue" TextColor="White" HorizontalTextAlignment="Center" Margin="1"/>
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid BackgroundColor="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text ="{Binding BottleTypeName}" BackgroundColor="WhiteSmoke" HorizontalOptions="Fill" HorizontalTextAlignment="Center"></Label>
<Label Grid.Column="1" Text ="{Binding BottleIsFilled}" BackgroundColor="WhiteSmoke" HorizontalOptions="Fill" HorizontalTextAlignment="Center"></Label>
<Label Grid.Column="2" Text ="{Binding Amount}" BackgroundColor="WhiteSmoke" HorizontalOptions="Fill" HorizontalTextAlignment="Center"></Label>
<Label Grid.Column="3" Text ="{Binding Price}" BackgroundColor="WhiteSmoke" HorizontalOptions="Fill" HorizontalTextAlignment="Center"></Label>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<!--Buttons section-->
<Grid ColumnSpacing="0" RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33.33*"/>
<ColumnDefinition Width="33.33*"/>
<ColumnDefinition Width="33.33*"/>
<ColumnDefinition Width="33.33*"/>
</Grid.ColumnDefinitions>
<Button Text="Dodaj butlę"
VerticalOptions="Center"
Margin="20"
BackgroundColor="DarkMagenta"
TextColor="White"
FontSize="20"
FontAttributes="Bold"
Command="{Binding SaveBottleCommand}" Grid.Column="0" HorizontalOptions="FillAndExpand"/>
<Button Text="Usuń butlę"
VerticalOptions="Center"
Margin="20"
BackgroundColor="MediumVioletRed"
TextColor="White"
FontSize="20"
FontAttributes="Bold"
Command="{Binding RemoveBottleCommand}" Grid.Column="1" HorizontalOptions="FillAndExpand"/>
<Button Text="Ok"
VerticalOptions="Center"
Margin="20"
BackgroundColor="Red"
TextColor="White"
FontSize="20"
FontAttributes="Bold"
Command="{Binding ClearFormCommand}" Grid.Column="2" HorizontalOptions="FillAndExpand"/>
<Button Text="Ok"
VerticalOptions="Center"
Margin="20"
BackgroundColor="OrangeRed"
TextColor="White"
FontSize="20"
FontAttributes="Bold"
Command="{Binding ClearFormCommand}" Grid.Column="3" HorizontalOptions="FillAndExpand"/>
</Grid>
</Grid>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
EDIT 1:
Current 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"
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.OrderModifyPage"
Title="{Binding SelectedOrder.OrderId, StringFormat='Numer zamówienia: {0}'}">
<ContentPage.Content>
<StackLayout>
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="Center">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!-- ********** COL 0 | ROW 0 ********** -->
<Grid Column="0" Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Text="{Binding SelectedOrder.OrderId, StringFormat='NUMER ZAMÓWIENIA: {0}'}" FontSize="16" TextColor="Gray"
Grid.Column="0" Padding="30,1,1,1" FontAttributes="None" VerticalOptions="Center"/>
<Label Text="KLIENT:" FontSize="15" VerticalOptions="Center" Grid.Column="1"/>
<Label Text="{Binding SelectedClient.Value, StringFormat='{0}'}" FontSize="16" TextColor="Gray" Grid.Column="2" FontAttributes="None" VerticalOptions="Center"/>
<Label Text="NA DZIEŃ:" Grid.Column="3" VerticalOptions="Center"/>
<DatePicker Date="{Binding SelectedTargetDate, Mode=TwoWay}" Format="dd.MM.yyyy" Grid.Column="4"/>
</Grid>
<!-- ********** COL 0 | ROW 1 ********** -->
<Grid Column="0" Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Text="BUTLA:" FontSize="15" TextColor="Gray" Grid.Column="0" Padding="30,1,1,1"
FontAttributes="None" HorizontalOptions="FillAndExpand" VerticalOptions="Center"/>
<Picker Title="BUTLA" ItemsSource="{Binding Bottles}" SelectedItem="{Binding SelectedBottle, Mode=TwoWay}"
ItemDisplayBinding="{Binding Value}" SelectedIndex="{Binding Id}" FontSize="15"
VerticalOptions="Center" Grid.Column="1" HorizontalOptions="FillAndExpand"/>
<Label Text=" " Grid.Column="2" HorizontalOptions="FillAndExpand"/>
<Label Text="ILOŚĆ:" FontSize="15" VerticalOptions="Center" Grid.Column="3" HorizontalOptions="Start"/>
<Entry Placeholder="Ilość" Text="{Binding SelectedAmount, Mode=TwoWay}" Keyboard="Numeric" MaxLength="5" Grid.Column="4" HorizontalOptions="Start"/>
</Grid>
<!-- ********** COL 0 | ROW 2 ********** -->
<Grid VerticalOptions="FillAndExpand" Column="0" Row="2">
<Grid.RowDefinitions>
<RowDefinition Grid.ColumnSpan="1" />
<RowDefinition Grid.ColumnSpan="1" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--Listview section-->
<ListView ItemsSource="{Binding SelectedItems}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" VerticalScrollBarVisibility="Always" Grid.Column="0" Grid.Row="0">
<ListView.Header>
<Grid BackgroundColor="White" Grid.Column="0" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Text="Nazwa butli" HorizontalOptions="Fill" Grid.Column="0" FontSize="Medium" FontAttributes="Bold" BackgroundColor="LightBlue" TextColor="White" HorizontalTextAlignment="Center" Margin="1"/>
<Label Text="Pełna?" HorizontalOptions="Fill" Grid.Column="1" FontSize="Medium" FontAttributes="Bold" BackgroundColor="LightBlue" TextColor="White" HorizontalTextAlignment="Center" Margin="1"/>
<Label Text="Ilość" HorizontalOptions="Fill" Grid.Column="2" FontSize="Medium" FontAttributes="Bold" BackgroundColor="LightBlue" TextColor="White" HorizontalTextAlignment="Center" Margin="1"/>
<Label Text="Kwota" HorizontalOptions="Fill" Grid.Column="3" FontSize="Medium" FontAttributes="Bold" BackgroundColor="LightBlue" TextColor="White" HorizontalTextAlignment="Center" Margin="1"/>
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid BackgroundColor="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text ="{Binding BottleTypeName}" BackgroundColor="WhiteSmoke" HorizontalOptions="Fill" HorizontalTextAlignment="Center"></Label>
<Label Grid.Column="1" Text ="{Binding BottleIsFilled}" BackgroundColor="WhiteSmoke" HorizontalOptions="Fill" HorizontalTextAlignment="Center"></Label>
<Label Grid.Column="2" Text ="{Binding Amount}" BackgroundColor="WhiteSmoke" HorizontalOptions="Fill" HorizontalTextAlignment="Center"></Label>
<Label Grid.Column="3" Text ="{Binding Price}" BackgroundColor="WhiteSmoke" HorizontalOptions="Fill" HorizontalTextAlignment="Center"></Label>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
<!-- ********** COL 0 | ROW 3 ********** -->
<Grid BackgroundColor="White" Grid.Column="0" Grid.Row="3">
<Button Text="Dodaj butlę" Grid.Row="1"
VerticalOptions="Center"
Margin="20"
BackgroundColor="DarkMagenta"
TextColor="White"
FontSize="20"
FontAttributes="Bold"
Command="{Binding SaveBottleCommand}" Grid.Column="0" HorizontalOptions="FillAndExpand"/>
<Button Text="Usuń butlę" Grid.Row="1"
VerticalOptions="Center"
Margin="20"
BackgroundColor="MediumVioletRed"
TextColor="White"
FontSize="20"
FontAttributes="Bold"
Command="{Binding RemoveBottleCommand}" Grid.Column="1" HorizontalOptions="FillAndExpand"/>
<Button Text="Ok" Grid.Row="1"
VerticalOptions="Center"
Margin="20"
BackgroundColor="Red"
TextColor="White"
FontSize="20"
FontAttributes="Bold"
Command="{Binding ClearFormCommand}" Grid.Column="2" HorizontalOptions="FillAndExpand"/>
<Button Text="Ok" Grid.Row="1"
VerticalOptions="Center"
Margin="20"
BackgroundColor="OrangeRed"
TextColor="White"
FontSize="20"
FontAttributes="Bold"
Command="{Binding ClearFormCommand}" Grid.Column="3" HorizontalOptions="FillAndExpand"/>
</Grid>
</Grid>
</StackLayout>
</ContentPage.Content>
</ContentPage>
EDIT 3:
your ListView and buttons are both contained in a Grid with no RowDefintions, so both will occupy the same row and overlap. You need to place each one in its own row
I would love to have them at the bottom.
If you want to place button at the bottom , just set VerticalOptions="End" for Grid.
listview itself overlaps top part of controls and there is need to make more space.
You can use Margin to add space between control and ListView.
I modify your code, you can take a look:
<StackLayout Orientation="Vertical">
<Grid 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 SelectedOrder.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="FillAndExpand"
Text="NA DZIEŃ:"
VerticalOptions="Center" />
<DatePicker
Grid.Column="5"
Date="{Binding SelectedTargetDate, Mode=TwoWay}"
Format="dd.MM.yyyy"
HorizontalOptions="FillAndExpand" />
</Grid>
<Grid Margin="5" HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<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="BUTLA:"
TextColor="Gray"
VerticalOptions="Center" />
<Picker
Title="BUTLA"
Grid.Column="1"
FontSize="15"
HorizontalOptions="FillAndExpand"
ItemDisplayBinding="{Binding Value}"
ItemsSource="{Binding Bottles}"
SelectedIndex="{Binding Id}"
SelectedItem="{Binding SelectedBottle, Mode=TwoWay}"
VerticalOptions="Center" />
<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.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Listview section -->
<ListView
ItemsSource="{Binding SelectedItems}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
VerticalScrollBarVisibility="Always">
<ListView.Header>
<Grid BackgroundColor="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Margin="1"
BackgroundColor="LightBlue"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="Nazwa butli"
TextColor="White" />
<Label
Grid.Column="1"
Margin="1"
BackgroundColor="LightBlue"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="Pełna?"
TextColor="White" />
<Label
Grid.Column="2"
Margin="1"
BackgroundColor="LightBlue"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="Ilość"
TextColor="White" />
<Label
Grid.Column="3"
Margin="1"
BackgroundColor="LightBlue"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="Kwota"
TextColor="White" />
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid BackgroundColor="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
BackgroundColor="WhiteSmoke"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="{Binding BottleTypeName}" />
<Label
Grid.Column="1"
BackgroundColor="WhiteSmoke"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="{Binding BottleIsFilled}" />
<Label
Grid.Column="2"
BackgroundColor="WhiteSmoke"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="{Binding Amount}" />
<Label
Grid.Column="3"
BackgroundColor="WhiteSmoke"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="{Binding Price}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<!-- Buttons section -->
<Grid Grid.Row="1" VerticalOptions="End">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33.33*" />
<ColumnDefinition Width="33.33*" />
<ColumnDefinition Width="33.33*" />
<ColumnDefinition Width="33.33*" />
</Grid.ColumnDefinitions>
<Button
Grid.Column="0"
BackgroundColor="DarkMagenta"
Command="{Binding SaveBottleCommand}"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="FillAndExpand"
Text="Dodaj butlę"
TextColor="White"
VerticalOptions="Fill" />
<Button
Grid.Column="1"
BackgroundColor="MediumVioletRed"
Command="{Binding RemoveBottleCommand}"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="FillAndExpand"
Text="Usuń butlę"
TextColor="White"
VerticalOptions="Center" />
<Button
Grid.Column="2"
BackgroundColor="Red"
Command="{Binding ClearFormCommand}"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="FillAndExpand"
Text="Ok"
TextColor="White"
VerticalOptions="Center" />
<Button
Grid.Column="3"
BackgroundColor="OrangeRed"
Command="{Binding ClearFormCommand}"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="FillAndExpand"
Text="Ok"
TextColor="White"
VerticalOptions="Center" />
</Grid>
</Grid>
</StackLayout>
Update:
Those items are cutted how to make more space for those item's texts?
Setting Picker ColumnDefinitions width=80 or higher.
How to make this more to the left?
Try to set Label HorizontalOptions="StartAndExpand"
When i select item in listview i only see colored orange line - how to make full item select?
Delete ListView ViewCell grid and Lable BackgroundColor="WhiteSmoke"
<StackLayout Orientation="Vertical">
<Grid 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 SelectedOrder.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 Margin="5" HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="80" />
<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="BUTLA:"
TextColor="Gray"
VerticalOptions="Center" />
<Picker
Title="BUTLA"
Grid.Column="1"
FontSize="15"
HorizontalOptions="FillAndExpand"
ItemDisplayBinding="{Binding Value}"
ItemsSource="{Binding Bottles}"
SelectedIndex="{Binding Id}"
SelectedItem="{Binding SelectedBottle, Mode=TwoWay}"
VerticalOptions="Center" />
<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.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Listview section -->
<ListView
ItemsSource="{Binding bottles}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
VerticalScrollBarVisibility="Always">
<ListView.Header>
<Grid BackgroundColor="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Margin="1"
BackgroundColor="LightBlue"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="Nazwa butli"
TextColor="White" />
<Label
Grid.Column="1"
Margin="1"
BackgroundColor="LightBlue"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="Pełna?"
TextColor="White" />
<Label
Grid.Column="2"
Margin="1"
BackgroundColor="LightBlue"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="Ilość"
TextColor="White" />
<Label
Grid.Column="3"
Margin="1"
BackgroundColor="LightBlue"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="Kwota"
TextColor="White" />
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="{Binding BottleTypeName}" />
<Label
Grid.Column="1"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="{Binding BottleIsFilled}" />
<Label
Grid.Column="2"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="{Binding Amount}" />
<Label
Grid.Column="3"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="{Binding Price}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<!-- Buttons section -->
<Grid Grid.Row="1" VerticalOptions="End">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33.33*" />
<ColumnDefinition Width="33.33*" />
<ColumnDefinition Width="33.33*" />
<ColumnDefinition Width="33.33*" />
</Grid.ColumnDefinitions>
<Button
Grid.Column="0"
BackgroundColor="DarkMagenta"
Command="{Binding SaveBottleCommand}"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="FillAndExpand"
Text="Dodaj butlę"
TextColor="White"
VerticalOptions="Fill" />
<Button
Grid.Column="1"
BackgroundColor="MediumVioletRed"
Command="{Binding RemoveBottleCommand}"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="FillAndExpand"
Text="Usuń butlę"
TextColor="White"
VerticalOptions="Center" />
<Button
Grid.Column="2"
BackgroundColor="Red"
Command="{Binding ClearFormCommand}"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="FillAndExpand"
Text="Ok"
TextColor="White"
VerticalOptions="Center" />
<Button
Grid.Column="3"
BackgroundColor="OrangeRed"
Command="{Binding ClearFormCommand}"
FontAttributes="Bold"
FontSize="20"
HorizontalOptions="FillAndExpand"
Text="Ok"
TextColor="White"
VerticalOptions="Center" />
</Grid>
</Grid>
</StackLayout>
<ContentView>
<Grid InputTransparent="True">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackLayout Spacing="0"
Grid.Row="0"
VerticalOptions="Center">
<Label Text="Algebra"/>
<Label Text="number 1" />
</StackLayout>
<Switch IsToggled="True"
VerticalOptions="Center"
Grid.Row="1"
Grid.Column="1"
/>
<StackLayout Spacing="0"
Grid.Row="1"
VerticalOptions="Center">
<Label Text="Arithmetics" />
<Label Text="number 2" />
</StackLayout>
<Switch IsToggled="True"
VerticalOptions="Center"
Grid.Column="1"
/>
</Grid>
</ContentView>
I have two rows with each having 2 labels and a switch. How can I invoke two different Tap events, for each row. Something like this:
<ROW1?.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapped1" />
</ROW?.GestureRecognizers>
<ROW2?.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapped2" />
</ROW?.GestureRecognizers>
I'm new, but it seems Switch toggle doesn't work while in grid, which is strange.
UI image:
Since you can't simply apply a gesture to an entire grid row,
I decided to just use Switch built-in functionality for my UI.
And all I did was add two different methods for each Switch:
<Grid InputTransparent="True">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackLayout Spacing="0"
Grid.Row="0"
VerticalOptions="Center">
<Label Text="Algebra"/>
<Label Text="number 1" />
</StackLayout>
<Switch IsToggled="True"
Toggled="method2"
VerticalOptions="Center"
Grid.Row="1"
Grid.Column="1"
/>
<StackLayout Spacing="0"
Grid.Row="1"
VerticalOptions="Center">
<Label Text="Arithmetics" />
<Label Text="number 2" />
</StackLayout>
<Switch IsToggled="True"
Toggled="method2"
VerticalOptions="Center"
Grid.Column="1"
/>
</Grid>
I have 4 buttons in the bottom part of the screen as menus and I had used grid to show 4 buttons with same width and height and will occupy the whole screen. I have these codes but the result is not they way i wanted. It is not occupying the whole screen. Please help me how can I achieve it. Thanks.
<AbsoluteLayout BackgroundColor="#BC3022" MinimumHeightRequest="20" Padding="0,10,10,10" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<BoxView Grid.Row="0" Grid.Column="0"/>
<StackLayout Grid.Row="0" Grid.Column="0" Padding="10,2,10,2">
<Image Source="home.png" WidthRequest="40" HeightRequest="25"/>
<Label Text="" TextColor="White" FontSize="15" HorizontalOptions="Center">Home</Label>
</StackLayout>
<BoxView Grid.Row="0" Grid.Column="1"/>
<StackLayout Grid.Row="0" Grid.Column="1" Padding="10,2,10,2">
<Image Source="jobs.png" WidthRequest="40" HeightRequest="25">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnJobsGestureTap" NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="" TextColor="White" FontSize="15" HorizontalOptions="Center">Jobs</Label>
</StackLayout>
<BoxView Grid.Row="0" Grid.Column="2"/>
<StackLayout Grid.Row="0" Grid.Column="2" Padding="10,2,10,2">
<Image Source="sync.png" WidthRequest="40" HeightRequest="25"/>
<Label Text="" TextColor="White" FontSize="15" HorizontalOptions="Center">Sync</Label>
</StackLayout>
<BoxView Grid.Row="0" Grid.Column="3"/>
<StackLayout Grid.Row="0" Grid.Column="3" Padding="10,2,10,2">
<Image Source="logout.png" WidthRequest="40" HeightRequest="25">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnLogoutGestureTap" NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="" TextColor="White" FontSize="15" HorizontalOptions="Center">Signout</Label>
</StackLayout>
</Grid>
</AbsoluteLayout>
This is how it looks:
Try to replace your code with below code:
<StackLayout BackgroundColor="#BC3022" MinimumHeightRequest="20" Padding="10,10,10,10" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="25*" />
</Grid.ColumnDefinitions>
<BoxView Grid.Row="0" Grid.Column="0"/>
<StackLayout Grid.Row="0" Grid.Column="0" Padding="10,2,10,2">
<Image Source="home.png" WidthRequest="40" HeightRequest="25"/>
<Label Text="" TextColor="White" FontSize="15" HorizontalOptions="Center">Home</Label>
</StackLayout>
<BoxView Grid.Row="0" Grid.Column="1"/>
<StackLayout Grid.Row="0" Grid.Column="1" Padding="10,2,10,2">
<Image Source="jobs.png" WidthRequest="40" HeightRequest="25">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnJobsGestureTap" NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="" TextColor="White" FontSize="15" HorizontalOptions="Center">Jobs</Label>
</StackLayout>
<BoxView Grid.Row="0" Grid.Column="2"/>
<StackLayout Grid.Row="0" Grid.Column="2" Padding="10,2,10,2">
<Image Source="sync.png" WidthRequest="40" HeightRequest="25"/>
<Label Text="" TextColor="White" FontSize="15" HorizontalOptions="Center">Sync</Label>
</StackLayout>
<BoxView Grid.Row="0" Grid.Column="3"/>
<StackLayout Grid.Row="0" Grid.Column="3" Padding="10,2,10,2">
<Image Source="logout.png" WidthRequest="40" HeightRequest="25">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnLogoutGestureTap" NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="" TextColor="White" FontSize="15" HorizontalOptions="Center">Signout</Label>
</StackLayout>
</Grid>
</StackLayout>
I want in my content to have a 'StackLayout' fixed and floating where it will contain 4 'Button's.
My layout is assikm at the moment
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="teste">
<Grid>
<ScrollView BackgroundColor="#ffffff" Padding="15" Grid.Row="0">
<StackLayout HorizontalOptions="Fill" VerticalOptions="FillAndExpand">
<Label Text="{Binding Titulo}" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" TextColor="#38B6AB" FontSize="22" FontAttributes="Bold"/>
<Label Text="{Binding Data}" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" TextColor="#5a5a5a" FontSize="18" FontAttributes="Bold"/>
<Image x:Name="imagen1" Source="{Binding ImageSource}" Aspect="AspectFit">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnTapped" />
</Image.GestureRecognizers>
</Image>
</StackLayout>
</ScrollView>
</Grid>
//-----Floating button----- //
The Grid can float things on top of other things by placing the item in the same row and column, like the following. I will note that, depending on how you place the Buttons, it might be a usability issue to place Buttons where the user is suppose to be scrolling.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions> <!-- Multiple columns will allow even Button spacing, just set Grid.ColumnSpan on your ScrollView -->
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ScrollView BackgroundColor="#ffffff"
Padding="15"
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="4">
<StackLayout HorizontalOptions="Fill"
VerticalOptions="FillAndExpand">
....
</StackLayout>
</ScrollView>
<Button Text="One"
Grid.Row="0"
Grid.Column="0"/>
<Button Text="Two"
Grid.Row="0"
Grid.Column="1"/>
<Button Text="Three"
Grid.Row="0"
Grid.Column="2"/>
<Button Text="Four"
Grid.Row="0"
Grid.Column="3"/>
</Grid>