i have a button that removes and adds stuff. If I press it once it will change stuff and that works fine but if i press it again and want my labels to change back the way they were before i get an exception.
here is my xaml
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="btnChangePositions" Priority="0" Clicked="ExchangeEnglishAndCzechVersion"/>
<ToolbarItem Clicked="DictionaryInfo_Clicked">
<ToolbarItem.IconImageSource >
<FontImageSource Glyph="{ x:Static local:GrialIconsFont.HelpCircle}"
Size="20"
FontFamily="{StaticResource GrialIconsFill}"/>
</ToolbarItem.IconImageSource>
</ToolbarItem>
<ToolbarItem Clicked="Listening_Clicked">
<ToolbarItem.IconImageSource >
<FontImageSource Glyph="{ x:Static local:GrialIconsFont.Headphones}"
Size="20"
FontFamily="{StaticResource GrialIconsFill}"
/>
</ToolbarItem.IconImageSource>
</ToolbarItem>
<ToolbarItem Clicked="Lock_Clicked">
<ToolbarItem.IconImageSource >
<FontImageSource Glyph="{ x:Static local:MaterialCommunityIconsFont.Lock}"
x:Name="lockScreenWithFrame"
FontFamily="{StaticResource MaterialCommunityIcons}"
Size="20"/>
</ToolbarItem.IconImageSource>
</ToolbarItem>
</ContentPage.ToolbarItems>
<Grid HorizontalOptions="Fill" VerticalOptions="FillAndExpand" Padding="0" x:Name="mainGrid">
<Grid BackgroundColor="{ DynamicResource MainWrapperBackgroundColor }"
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition
Height="27*" />
<RowDefinition
Height="27*" />
<RowDefinition
Height="12*" />
<RowDefinition
Height="Auto" />
<!--<RowDefinition
Height="7*" />-->
</Grid.RowDefinitions>
<Grid Grid.Row="0" Padding="5" x:Name="defaultEnglishGrid" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid ><!--Margin="5"-->
<!-- CARD ONE -->
<grial:CardView x:Name="CardViewNameENg"
Style="{ StaticResource ResponsiveLandscapeMarginStyle }"
VerticalOptions="FillAndExpand"
CornerRadius="10"
Padding="5">
<!-- Text -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="*" />
<ColumnDefinition
Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="150" />
</Grid.RowDefinitions>
<Grid Grid.Column="0" HeightRequest="150" Grid.Row="0">
<ScrollView>
<controls:ExtendedWebView x:Name="nameEng" Opacity="1" IsVisible="True" HeightRequest="150"/>
</ScrollView>
</Grid>
<!-- Column button Play-->
<Grid Padding ="5,0,0,0"
Grid.Row="0"
Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="0.5*"></RowDefinition>
<RowDefinition Height="0.5*"></RowDefinition>
</Grid.RowDefinitions>
<Label x:Name="buttonPlay"
VerticalTextAlignment="Start"
HorizontalTextAlignment="End"
Text="{ x:Static local:GrialIconsFont.Volume2 }"
FontFamily="{ StaticResource IconsFontFamily }"
TextColor="{ DynamicResource AccentColor }">
<Label.GestureRecognizers >
<TapGestureRecognizer
Tapped="StartOrStopPlaying">
</TapGestureRecognizer>
</Label.GestureRecognizers>
<Label.FontSize>
<OnIdiom
x:TypeArguments="x:Double"
Phone="25"
Tablet="30" />
</Label.FontSize>
</Label>
<Label x:Name="buttonPause"
VerticalTextAlignment="Start"
HorizontalTextAlignment="End" IsVisible="False"
Text="{ x:Static local:GrialIconsFont.AudioPause }"
FontFamily="{ StaticResource IconsFontFamily }"
TextColor="{ DynamicResource AccentColor }">
<Label.GestureRecognizers >
<TapGestureRecognizer
Tapped="StartOrStopPlaying">
</TapGestureRecognizer>
</Label.GestureRecognizers>
<Label.FontSize>
<OnIdiom
x:TypeArguments="x:Double"
Phone="25"
Tablet="30" />
</Label.FontSize>
</Label>
</Grid>
<!-- Column Button Plus -->
<Grid Padding ="5,0,0,0"
Grid.Row="0"
Grid.Column="1"
VerticalOptions="End">
<Label x:Name="btnMakeLargerName"
VerticalTextAlignment="End"
HorizontalTextAlignment="End"
Text="{ x:Static local:GrialIconsFont.ZoomIn }"
FontFamily="{ StaticResource IconsFontFamily }"
TextColor="{ DynamicResource AccentColor }">
<Label.FontSize>
<OnIdiom
x:TypeArguments="x:Double"
Phone="25"
Tablet="30" />
</Label.FontSize>
</Label>
</Grid>
</Grid>
</grial:CardView>
</Grid>
</Grid>
<Grid Grid.Row="1" Padding="5" x:Name="parentOfDefaultCzechGrid" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid x:Name="defaultCzechGrid" >
<!--Margin="5"-->
<!-- CARD TWO -->
<grial:CardView x:Name="CardViewCzech"
Style="{ StaticResource ResponsiveLandscapeMarginStyle }"
CornerRadius="10" VerticalOptions="FillAndExpand"
Padding="0" >
<!-- Text -->
<Grid RowSpacing ="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.8*"></ColumnDefinition>
<ColumnDefinition Width="0.2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="150" />
</Grid.RowDefinitions>
<ScrollView>
<controls:ExtendedWebView x:Name="explanation" VerticalOptions="Start" HorizontalOptions="Start" Opacity="1" HeightRequest="150"/>
</ScrollView>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="0.5*"></RowDefinition>
<RowDefinition Height="0.5*"></RowDefinition>
<RowDefinition Height="0.1*"></RowDefinition>
<RowDefinition Height="0.5*"></RowDefinition>
</Grid.RowDefinitions>
<!-- Column button Eye-->
<Label x:Name="btnVisual"
Grid.Row="0"
VerticalTextAlignment="Start"
HorizontalTextAlignment="End"
Text="{ x:Static local:GrialIconsFont.Eye }"
FontFamily="{ StaticResource IconsFontFamily }"
TextColor="{ DynamicResource AccentColor }">
<Label.GestureRecognizers >
<TapGestureRecognizer
Tapped="HideLabels">
</TapGestureRecognizer>
</Label.GestureRecognizers>
<Label.FontSize>
<OnIdiom
x:TypeArguments="x:Double"
Phone="25"
Tablet="30" />
</Label.FontSize>
</Label>
<!-- Column Button Trash -->
<Label x:Name="btnBin" Grid.Row="1"
VerticalTextAlignment="Center"
HorizontalTextAlignment="End"
Text="{ x:Static local:IoniconsFont.IosTrash }"
FontFamily="{ StaticResource Ionicons }"
TextColor="{ DynamicResource AccentColor }">
<Label.GestureRecognizers >
<TapGestureRecognizer
Tapped="RemoveWordFromUserDictionary">
</TapGestureRecognizer>
</Label.GestureRecognizers>
<Label.FontSize>
<OnIdiom
x:TypeArguments="x:Double"
Phone="25"
Tablet="30" />
</Label.FontSize>
</Label>
<!-- Column Button Plus -->
<Label Grid.Row="3" x:Name="btnMakeLarger"
VerticalTextAlignment="End"
HorizontalTextAlignment="End"
Text="{ x:Static local:GrialIconsFont.ZoomIn }"
FontFamily="{ StaticResource IconsFontFamily }"
TextColor="{ DynamicResource AccentColor }">
<Label.FontSize>
<OnIdiom
x:TypeArguments="x:Double"
Phone="25"
Tablet="30" />
</Label.FontSize>
</Label>
</Grid>
</Grid>
</grial:CardView>
</Grid>
</Grid>
<!-- CARD Three -->
<Grid Grid.Row="2" Padding="5,0,5,0" RowSpacing="10" x:Name="gridButtons" >
<Grid>
<grial:CardView
Style="{ StaticResource ResponsiveLandscapeMarginStyle }"
HeightRequest="100" HorizontalOptions="Fill"
CornerRadius="10"
Padding="0,0,0,3">
<Grid Padding="0"
VerticalOptions="Start"
HorizontalOptions="CenterAndExpand">
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<!-- BUTTONS GRID -->
<Grid Margin="0"
ColumnSpacing="10"
HorizontalOptions="CenterAndExpand"
VerticalOptions="StartAndExpand">
<!-- Rating Button Grid -->
<Grid Grid.Row="0" ColumnSpacing="15" Padding="0,2,0,0">
<!-- One -->
<Button x:Name="firstRateBtn" Grid.Column="0" HorizontalOptions="Center" Text="1" Style="{ StaticResource CircleActionButtonFlatStyle }" VerticalOptions="Start" HeightRequest="50" CornerRadius="25" WidthRequest="50" Clicked="RateOneAndShowOtherword"/>
<!-- Two -->
<Button x:Name="secondRateBtn" Grid.Column="1" HorizontalOptions="Center" Text="2" Style="{ StaticResource CircleActionButtonFlatStyle }" VerticalOptions="Start" HeightRequest="50" CornerRadius="25" WidthRequest="50" Clicked="RateTwoAndShowOtherword" />
<!-- Three-->
<Button x:Name="thirdRateBtn" Grid.Column="2" HorizontalOptions="Center" Text="3" Style="{ StaticResource CircleActionButtonFlatStyle }" VerticalOptions="Start" HeightRequest="50" CornerRadius="25" WidthRequest="50" Clicked="RateThreeAndShowOtherword" />
<!-- Four -->
<Button x:Name="fourthRateBtn" Grid.Column="3" HorizontalOptions="Center" Text="4" Style="{ StaticResource CircleActionButtonFlatStyle }" VerticalOptions="Start" HeightRequest="50" CornerRadius="25" WidthRequest="50" Clicked="RateFourAndShowOtherword"/>
<!-- Five -->
<Button x:Name="fifthRateBtn" Grid.Column="4" HorizontalOptions="Center" Text="5" Style="{ StaticResource CircleActionButtonFlatStyle }" VerticalOptions="Start" HeightRequest="50" CornerRadius="25" WidthRequest="50" Clicked="RateFiveAndShowOtherword" />
</Grid>
</Grid>
<!-- Labels -->
<Grid Grid.Row="1" HorizontalOptions="FillAndExpand" VerticalOptions="EndAndExpand" Padding="0,2,0,0">
<!--Text Wrong-->
<Label Text="{ grial:Translate A_LabelCorrectWrong }" FontSize="14" Style="{ StaticResource LabelBoldStyle }" TextColor="{ DynamicResource CircleActionButtonFlatTextColor }" VerticalOptions="End" HorizontalOptions="Start"
IsVisible="{grial:OnOrientationBool
Default='true',
LandscapePhone='false'}" />
</Grid>
</Grid>
</grial:CardView>
</Grid>
</Grid>
<!-- CARD Four -->
<Grid Grid.Row="3" Padding="5,5,5,5" x:Name="gridDailyAmount">
<Grid >
<grial:CardView
Style="{ StaticResource ResponsiveLandscapeMarginStyle }"
VerticalOptions="Fill"
CornerRadius="10"
Padding="0">
<Grid Margin="0"
ColumnSpacing="0"
Padding="{ grial:OnOrientationThickness Default='20', LandscapePhone='20,8'
}">
<Grid.RowDefinitions>
<RowDefinition
Height="*" />
<RowDefinition
Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--Text Daily dose-->
<Label Grid.Row="0" Margin="0" Grid.Column ="0" Text="Dnešní dávka" FontSize="15" TextColor="{ DynamicResource CircleActionButtonFlatTextColor }" VerticalOptions="Start" HorizontalOptions="Start"
IsVisible="{grial:OnOrientationBool
Default='true',
LandscapePhone='false'}" />
<Label Grid.Row="0" Margin="0" Grid.Column ="1" x:Name="amountOfWordForToday" FontSize="15" TextColor="{ DynamicResource CircleActionButtonFlatTextColor }" VerticalOptions="Start" HorizontalOptions="End"
IsVisible="{grial:OnOrientationBool
Default='true',
LandscapePhone='false'}" />
<!--Text Amount of words-->
<Label Grid.Row="1" Grid.Column="0" Margin="0" Text="Slovíček ve slovníku" FontSize="15" TextColor="{ DynamicResource CircleActionButtonFlatTextColor }" VerticalOptions="End" HorizontalOptions="StartAndExpand"
IsVisible="{grial:OnOrientationBool
Default='true',
LandscapePhone='false'}" />
<Label Grid.Row="1" Margin="0" Grid.Column="1" x:Name="amountOfWordsInDictionary" FontSize="15" TextColor="{ DynamicResource CircleActionButtonFlatTextColor }" VerticalOptions="End" HorizontalOptions="End"
IsVisible="{grial:OnOrientationBool
Default='true',
LandscapePhone='false'}" />
</Grid>
</grial:CardView>
</Grid>
</Grid>
</Grid>
</Grid>
</ContentPage>
private void ExchangeEnglishAndCzechVersion(object sender, EventArgs e)
{
CardViewCzech.Children.Remove(explanation);
CardViewCzech.Children.Add(nameEng);
CardViewNameENg.Children.Remove(nameEng);
CardViewNameENg.Children.Add(explanation);
CardViewCzech.Children.Add(btnVisual);
CardViewCzech.Children.Add(btnMakeLarger);
CardViewCzech.Children.Add(btnBin);
CardViewNameENg.Children.Add(buttonPlay);
CardViewNameENg.Children.Add(btnMakeLargerName);
btnChangePositions.Text = "EN/CZ";
}
The label on the button changes and once i press it again i need the content to go back to the way ot wa before. But i get an exception right on the secons line after trying to go back
System.InvalidOperationException: Cannot change ObservableCollection during a CollectionChanged event.
Related
I've been trying to put border on these text and the only way i can is taking off grid on every row so now it has borders but then the grid frame is off. I can't differentiate which part is from row1 or the beginning of list.
<StackLayout>
<Label Text="rain Log" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,50,0,0" />
<ListView x:Name="postListView" >
<ListView.ItemTemplate>
<!-- from the post.cs -->
<DataTemplate>
<ViewCell >
<Grid BackgroundColor="Black" HorizontalOptions="CenterAndExpand" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions > <!-- 8 rows -->
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<!-- Row 1 -->
<Label Grid.Row="1" FontSize="Medium" Grid.Column="0" Text="right tst:" HorizontalTextAlignment="Start" BackgroundColor="cornflowerblue" />
<Label Grid.Column="1" Grid.Row="1" Text="{Binding drain1vol}" BackgroundColor="cornflowerblue"/>
<!-- endrow1 -->
<!-- rain1 Row 1 -->
<Label Grid.Row="2" Grid.Column="0" Text="nothing" BackgroundColor="Yellow"/>
<Label Grid.Row="2" Grid.Column="1" Text="{Binding drain2vol}"
HorizontalTextAlignment="Center" BackgroundColor="Yellow" />
<!-- endrow1 -->
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
what i want
If you want to separate out your item as like group than you can use SeparatorColor and its visibility.
Instead of 2 boxview you can also use one grid as wrapper and using ColumnSpacing and RowSpacing.
<ListView x:Name="postListView" SeparatorVisibility="Default" HasUnevenRows="True" ItemsSource="{Binding Items}" SeparatorColor="White">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid BackgroundColor="Black" HorizontalOptions="CenterAndExpand"
VerticalOptions="FillAndExpand" Padding="1,2,1,0">
<Grid HorizontalOptions="CenterAndExpand"
VerticalOptions="FillAndExpand" ColumnSpacing="1" RowSpacing="1">
<Grid.RowDefinitions >
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" FontSize="Medium" Grid.Column="0" Text="right tst:" HorizontalTextAlignment="Start" BackgroundColor="cornflowerblue" />
<Label Grid.Column="1" Grid.Row="0" Text="{Binding drain1vol}" HorizontalTextAlignment="Center" BackgroundColor="cornflowerblue"/>
<Label Grid.Row="1" Grid.Column="0" Text="nothing" BackgroundColor="Yellow"/>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding drain2vol}" HorizontalTextAlignment="Center" BackgroundColor="Yellow" />
</Grid>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Yes, you can use BoxView to achieve this function, try the following code :
<StackLayout>
<Label Text="rain Log" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,50,0,0" />
<ListView x:Name="postListView" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell >
<Grid HorizontalOptions="CenterAndExpand" VerticalOptions="FillAndExpand" ColumnSpacing="2" RowSpacing="0" BackgroundColor="Black">
<Grid.RowDefinitions >
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" FontSize="Medium" Grid.Column="0" Text="right tst:" HorizontalTextAlignment="Start" BackgroundColor="cornflowerblue" />
<Label Grid.Column="1" Grid.Row="0" Text="{Binding drain1vol}" HorizontalTextAlignment="Center" BackgroundColor="cornflowerblue"/>
<!-- thin separator -->
<BoxView Color="Black" Grid.Row="0" Grid.ColumnSpan="2" HeightRequest="2" VerticalOptions="End" HorizontalOptions="FillAndExpand" />
<Label Grid.Row="1" Grid.Column="0" Text="nothing" BackgroundColor="Yellow"/>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding drain2vol}" HorizontalTextAlignment="Center" BackgroundColor="Yellow" />
<!-- thick separator -->
<BoxView Color="Black" Grid.Row="3" Grid.ColumnSpan="2" HeightRequest="5" VerticalOptions="End" HorizontalOptions="FillAndExpand" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
The effect is as follows:
use a BoxView overlaid on your Grid to simulate a separator
<Grid HorizontalOptions="CenterAndExpand" VerticalOptions="FillAndExpand">
<!-- Row 1 -->
<Label Grid.Row="1" FontSize="Medium" Grid.Column="0" Text="right tst:" HorizontalTextAlignment="Start" BackgroundColor="cornflowerblue" />
<Label Grid.Column="1" Grid.Row="1" Text="{Binding drain1vol}" BackgroundColor="cornflowerblue"/>
<! thin separator -->
<BoxView Color="Black" Grid.Row="1" Grid.ColumnSpan="2" HeightRequest="2" VerticalOptions="End" HorizontalOptions="FillAndExpand" />
<!-- rain1 Row 1 -->
<Label Grid.Row="2" Grid.Column="0" Text="nothing" BackgroundColor="Yellow"/>
<Label Grid.Row="2" Grid.Column="1" Text="{Binding drain2vol}"
HorizontalTextAlignment="Center" BackgroundColor="Yellow" />
<! thick separator -->
<BoxView Color="Black" Grid.Row="2" Grid.ColumnSpan="2" HeightRequest="5" VerticalOptions="End" HorizontalOptions="FillAndExpand" />
</Grid>
I have a GridLayout in my Xamarin.Forms App. But my App I used BoxView. So in here I want to reduse size in that boxview. in my app when I clicked exixting user its working nicely but when I click new radio button getting crashing. in my app, but in my code its not like that. And I would like each element in the grid as shown here:
Click me and help me
Existing and help me
<ContentPage.Content>
<ScrollView>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Padding="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="20" />
<RowDefinition Height="40" />
<RowDefinition x:Name="addressBoxViewRow" />
</Grid.RowDefinitions>
<Label Text="Care of User - Address" Grid.Row="0" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
<Label Text="Enter the details of the person that the connection will be in care of." TextColor="#757575" Grid.Row="1" FontSize="Small" />
<FlexLayout Grid.Row="2" AlignItems="Center" JustifyContent="Start" Direction="Row">
<Label Text="Address status" FontSize="Small" FontAttributes="Bold" VerticalTextAlignment="Center" TextColor="Black" />
<input:RadioButtonGroupView Margin="20,0,0,0" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" x:Name="addressStatus" VerticalOptions="CenterAndExpand">
<input:RadioButton Text="New" TextFontSize="14" x:Name="newRadioButton" Clicked="NewRadioButton_Clicked" />
<input:RadioButton Text="Existing" IsChecked="true" TextFontSize="14" x:Name="existingRadioButton" Clicked="ExistingRadioButton_Clicked" />
</input:RadioButtonGroupView>
</FlexLayout>
<BoxView Grid.Row="3" BackgroundColor="White" CornerRadius="5">
<BoxView.Effects>
<effects:ShadowEffect />
</BoxView.Effects>
</BoxView>
<!--This appears when Existing selected-->
<Grid Grid.Row="3" Padding="20" x:Name="existingAddressForm">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Text="Billing address" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
<Label Text="Address line 1" Grid.Row="1" TextColor="#757575" FontSize="Small" />
<Label Grid.Row="2" x:Name="lblAddressLine1" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Address line 2" Grid.Row="3" TextColor="#757575" FontSize="Small" />
<Label Grid.Row="4" x:Name="lblAddressLine2" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Address line 3" Grid.Row="5" TextColor="#757575" FontSize="Small" />
<Label Grid.Row="6" x:Name="lblAddressLine3" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Postal code" Grid.Row="7" TextColor="#757575" FontSize="Small" />
<Label Grid.Row="8" x:Name="lblPostalCode" FontAttributes="Bold" FontSize="Medium" />
</Grid>
<!--This appears when New selected-->
<Grid Grid.Row="3" Padding="20" x:Name="newAddressForm">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Text="Billing address" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
<Label Text="Address line 1" Grid.Row="1" TextColor="#757575" FontSize="Small" />
<Entry Grid.Row="2" x:Name="addressLine1" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Address line 2" Grid.Row="3" TextColor="#757575" FontSize="Small" />
<Entry Grid.Row="4" x:Name="addressLine2" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Address line 3" Grid.Row="5" TextColor="#757575" FontSize="Small" />
<Entry Grid.Row="6" x:Name="addressLine3" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Postal code" Grid.Row="7" TextColor="#757575" FontSize="Small" />
<Picker Grid.Row="8" TextColor="Black" FontSize="Small" x:Name="postalCodeSelector1" ItemDisplayBinding="{Binding PostalDescription}" WidthRequest="100">
<Picker.Effects>
<effects:DropdownEffect />
</Picker.Effects>
</Picker>
</Grid>
</Grid>
<StackLayout Grid.Row="1" Orientation="Horizontal" VerticalOptions="End">
<Button Text="Clear" Style="{x:StaticResource GrayButton}" HorizontalOptions="FillAndExpand" Clicked="ClearBtn_Clicked"/>
<Button Text="Proceed" HorizontalOptions="FillAndExpand" Clicked="Handle_Clicked" x:Name="proceedBtn" />
</StackLayout>
<!--<StackLayout Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" IsVisible="{Binding IsBusy}" BackgroundColor="White" Opacity="1" Orientation="Vertical">
<StackLayout Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="CenterAndExpand">
<ActivityIndicator Color="#2B428E" IsRunning="true" />
<Label x:Name="progressname" Text="Please wait ..." TextColor="#2B428E" VerticalOptions="Center" />
</StackLayout>
</StackLayout>-->
</Grid>
</ScrollView>
</ContentPage.Content>
Try this
<ScrollView>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Padding="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="20" />
<RowDefinition Height="40" />
<RowDefinition x:Name="addressBoxViewRow" />
</Grid.RowDefinitions>
<Label Text="Care of User - Address" Grid.Row="0" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
<Label Text="Enter the details of the person that the connection will be in care of." TextColor="#757575" Grid.Row="1" FontSize="Small" />
<FlexLayout Grid.Row="2" AlignItems="Center" JustifyContent="Start" Direction="Row">
<Label Text="Address status" FontSize="Small" FontAttributes="Bold" VerticalTextAlignment="Center" TextColor="Black" />
<input:RadioButtonGroupView Margin="20,0,0,0" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" x:Name="addressStatus" VerticalOptions="CenterAndExpand">
<input:RadioButton Text="New" TextFontSize="14" x:Name="newRadioButton" Clicked="NewRadioButton_Clicked" />
<input:RadioButton Text="Existing" IsChecked="true" TextFontSize="14" x:Name="existingRadioButton" Clicked="ExistingRadioButton_Clicked" />
</input:RadioButtonGroupView>
</FlexLayout>
<BoxView Grid.Row="3" BackgroundColor="White" CornerRadius="5">
<BoxView.Effects>
<effects:ShadowEffect />
</BoxView.Effects>
</BoxView>
<!--This appears when Existing selected-->
<Grid Grid.Row="3" Padding="20" x:Name="existingAddressForm">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Text="Billing address" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
<Label Text="Address line 1" Grid.Row="1" TextColor="#757575" FontSize="Small" />
<Label Grid.Row="2" x:Name="lblAddressLine1" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Address line 2" Grid.Row="3" TextColor="#757575" FontSize="Small" />
<Label Grid.Row="4" x:Name="lblAddressLine2" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Address line 3" Grid.Row="5" TextColor="#757575" FontSize="Small" />
<Label Grid.Row="6" x:Name="lblAddressLine3" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Postal code" Grid.Row="7" TextColor="#757575" FontSize="Small" />
<Label Grid.Row="8" x:Name="lblPostalCode" FontAttributes="Bold" FontSize="Medium" />
</Grid>
<!--This appears when New selected-->
<Grid Grid.Row="3" Padding="20" x:Name="newAddressForm">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
<RowDefinition Height="25" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Text="Billing address" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
<Label Text="Address line 1" Grid.Row="1" TextColor="#757575" FontSize="Small" />
<Entry Grid.Row="2" x:Name="addressLine1" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Address line 2" Grid.Row="3" TextColor="#757575" FontSize="Small" />
<Entry Grid.Row="4" x:Name="addressLine2" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Address line 3" Grid.Row="5" TextColor="#757575" FontSize="Small" />
<Entry Grid.Row="6" x:Name="addressLine3" FontAttributes="Bold" FontSize="Medium" />
<Label Text="Postal code" Grid.Row="7" TextColor="#757575" FontSize="Small" />
<Picker Grid.Row="8" TextColor="Black" FontSize="Small" x:Name="postalCodeSelector1" ItemDisplayBinding="{Binding PostalDescription}" WidthRequest="100">
<Picker.Effects>
<effects:DropdownEffect />
</Picker.Effects>
</Picker>
</Grid>
</Grid>
<StackLayout Grid.Row="1" Orientation="Horizontal" VerticalOptions="End">
<Button Text="Clear" Style="{x:StaticResource GrayButton}" HorizontalOptions="FillAndExpand" Clicked="ClearBtn_Clicked"/>
<Button Text="Proceed" HorizontalOptions="FillAndExpand" Clicked="Handle_Clicked" x:Name="proceedBtn" />
</StackLayout>
<!--<StackLayout Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" IsVisible="{Binding IsBusy}" BackgroundColor="White" Opacity="1" Orientation="Vertical">
<StackLayout Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="CenterAndExpand">
<ActivityIndicator Color="#2B428E" IsRunning="true" />
<Label x:Name="progressname" Text="Please wait ..." TextColor="#2B428E" VerticalOptions="Center" />
</StackLayout>
</StackLayout>-->
</Grid>
</ScrollView>
I need to create a table, using list view in xamarin forms. I am able to create list view with five columns. But I can't able to give header for the columns and lines. If anyone know how to create the table structure with headers please help me. Thanks in advance.
This is my source code for table[Header and Listview]
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<StackLayout Grid.Row="0" Padding="40,10,10,40" Spacing="0">
<BoxView HeightRequest="1" BackgroundColor="Black"></BoxView>
<StackLayout Orientation="Horizontal" Spacing="40">
<BoxView WidthRequest="1" HeightRequest="10" BackgroundColor="Black" HorizontalOptions="Start" VerticalOptions="Fill" />
<StackLayout Orientation="Horizontal" Spacing="1" HorizontalOptions="StartAndExpand">
<controls:CheckBox></controls:CheckBox>
<Label Text="Select All" FontAttributes="Bold" HorizontalOptions="Center" VerticalOptions="Center"></Label>
</StackLayout>
<BoxView WidthRequest="1" HeightRequest="10" BackgroundColor="Black" HorizontalOptions="Start" VerticalOptions="Fill" />
<StackLayout Orientation="Horizontal" Spacing="1" HorizontalOptions="StartAndExpand">
<Label Text="Last Name, First Name" HorizontalOptions="Center" VerticalOptions="Center" FontAttributes="Bold"></Label>
<Button Text=">" HeightRequest="5" WidthRequest="5"></Button>
</StackLayout>
<BoxView WidthRequest="1" HeightRequest="10" BackgroundColor="Black" HorizontalOptions="Start" VerticalOptions="Fill" />
<Label Text="Child ID" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontAttributes="Bold"></Label>
<BoxView WidthRequest="1" HeightRequest="10" BackgroundColor="Black" HorizontalOptions="Start" VerticalOptions="Fill" />
<Label Text="Date of Birth" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontAttributes="Bold"></Label>
<BoxView WidthRequest="1" HeightRequest="10" BackgroundColor="Black" HorizontalOptions="Start" VerticalOptions="Fill" />
<Label Text="Location" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontAttributes="Bold"></Label>
<BoxView WidthRequest="1" HeightRequest="10" BackgroundColor="Black" HorizontalOptions="Start" VerticalOptions="Fill" />
<Label Text="Enrollment" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontAttributes="Bold"></Label>
<BoxView WidthRequest="1" HeightRequest="10" BackgroundColor="Black" HorizontalOptions="Start" VerticalOptions="Fill" />
<Label Text="Actions" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontAttributes="Bold"></Label>
<BoxView WidthRequest="1" HeightRequest="10" BackgroundColor="Black" HorizontalOptions="Start" VerticalOptions="Fill" />
</StackLayout>
<BoxView HeightRequest="1" BackgroundColor="Black"></BoxView>
</StackLayout>
<StackLayout Padding="40,10,10,40" HeightRequest="200" Grid.Row="1" Spacing="0">
<ListView ItemsSource="{Binding ChildRecords}" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<!-- <BoxView HeightRequest="1" BackgroundColor="Black"></BoxView>-->
<StackLayout Orientation="Horizontal">
<BoxView WidthRequest="1" HeightRequest="15" BackgroundColor="Black" HorizontalOptions="Start" />
<StackLayout Orientation="Horizontal" Spacing="1" HorizontalOptions="StartAndExpand">
<Label Text="Select All" FontAttributes="Bold" HorizontalOptions="Center" VerticalOptions="Center"></Label>
</StackLayout>
<BoxView WidthRequest="1" HeightRequest="15" BackgroundColor="Black" HorizontalOptions="Start" />
<StackLayout Orientation="Horizontal" Spacing="1" HorizontalOptions="StartAndExpand">
<Label Text="Last Name, First Name" HorizontalOptions="Center" VerticalOptions="Center" FontAttributes="Bold"></Label>
<Button Text=">" HeightRequest="5" WidthRequest="5"></Button>
</StackLayout>
<BoxView WidthRequest="1" BackgroundColor="Black" HorizontalOptions="Start" HeightRequest="15" />
<Label Text="Child ID" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontAttributes="Bold"></Label>
<BoxView WidthRequest="1" BackgroundColor="Black" HorizontalOptions="Start" HeightRequest="15" />
<Label Text="Date of Birth" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontAttributes="Bold"></Label>
<BoxView WidthRequest="1" BackgroundColor="Black" HorizontalOptions="Start" HeightRequest="15" />
<Label Text="Location" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontAttributes="Bold"></Label>
<BoxView WidthRequest="1" BackgroundColor="Black" HorizontalOptions="Start" HeightRequest="15" />
<Label Text="Enrollment" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontAttributes="Bold"></Label>
<BoxView WidthRequest="1" BackgroundColor="Black" HorizontalOptions="Start" HeightRequest="15" />
<Label Text="Actions" HorizontalOptions="StartAndExpand" VerticalOptions="Center" FontAttributes="Bold"></Label>
<BoxView WidthRequest="1" BackgroundColor="Black" HorizontalOptions="Start" HeightRequest="15"/>
</StackLayout>
<BoxView HeightRequest="1" BackgroundColor="Black"></BoxView>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</Grid>
Typically what I like to do is create a Grid above the ListView for a Header, and then create ViewCells containing Grids within the ListView with the same column widths.
As an example:
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="Start" RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Text="Heading 1" />
<Label Grid.Column="1" Text="Heading 2" />
<Label Grid.Column="2" Text="Heading 3" />
</Grid>
<ListView ItemsSource="{}" HasUnevenRows="true" HeightRequest="200" SeparatorVisibility="None">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid Margin="0" Padding="0" RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Margin="0" Text="{Binding data1}" />
<Label Grid.Column="1" Margin="0" Text="{Binding data2}" />
<Label Grid.Column="2" Margin="0" Text="{Binding data3}" />
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Note also the ListView comes with a Header, which is useful if you want the header to scroll with the items in the ListView. Have a look at this documentation: Customizing ListView Appearance
If you want a quick/professional looking way, you can try Synfucion DataGrid custom control for Xamarin. They are free to use if your company earn less than 1 millions.
you can use Grid for that purpose make the first row of the grid as the header, you can easily change the style on the header only. Here is the sample yo create 3 rows and two column
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
<ContentPage.Content>
<ScrollView VerticalOptions="Fill" HorizontalOptions="Fill">
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand" RowSpacing="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Text="Entry Name" BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold"/>
<Label Grid.Column="1" Text="Entry Date" BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold" />
<Label Grid.Column="2" Text="Enty Type" BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold" />
<Label Grid.Column="3" Text="Transaction Type" BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold"/>
<Label Grid.Column="4" Text="Cashflow " BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold" />
<Label Grid.Column="5" Text="Particular" BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold" />
<Label Grid.Column="6" Text="VoucherNumber" BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold" />
<Label Grid.Column="7" Text="LedgerFolio" BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold" />
<Label Grid.Column="8" Text="Amount" BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold" />
<Label Grid.Column="9" Text="PurchaseInvoice" BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold" />
<Label Grid.Column="10" Text="Credit Or Debit" BackgroundColor="LightGreen" TextColor="Black" FontAttributes="Bold"/>
<ListView x:Name="ContentListview" HasUnevenRows="true" HeightRequest="200" SeparatorVisibility="None" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="11" HorizontalScrollBarVisibility="Default" VerticalScrollBarVisibility="Default">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid Margin="0" Padding="0" RowSpacing="0">
<Label Grid.Column="0" Text="{Binding EntryName}" TextColor="Black" />
<Label Grid.Column="1" Text="{Binding EntryDate}" TextColor="Black" />
<Label Grid.Column="2" Text="{Binding EntyType}" TextColor="Black" />
<Label Grid.Column="3" Text="{Binding TransactionType}" TextColor="Black" />
<Label Grid.Column="4" Text="{Binding Cashflow}" TextColor="Black" />
<Label Grid.Column="5" Text="{Binding Particular}" TextColor="Black" />
<Label Grid.Column="6" Text="{Binding VoucherNumber}" TextColor="Black" />
<Label Grid.Column="7" Text="{Binding LedgerFolio}" TextColor="Black" />
<Label Grid.Column="8" Text="{Binding Amount}" TextColor="Black" />
<Label Grid.Column="9" Text="{Binding PurchaseInvoice}" TextColor="Black" />
<Label Grid.Column="10" Text="{Binding CreditOrDebit}" TextColor="Black" />
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ScrollView>
</ContentPage.Content>
This is what I did, and the picture below is its outcome.Xamarin form result. Sorry, cannot show my code behind.
I am using a Grid Layout to make a registration form. I have a Grid which contains two rows. The first row is an image, the second row is another Grid and has the problem that on Android the entries (which are in a StackLayout) overlap the button, but this doesn't make sense because the grid should never overlap its other rows. Indeed, it works on iOS.
XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="*" />
</Grid.RowDefinitions>
<Image
Source="blue_background.png"
Aspect="Fill"
Grid.Row="0"
Grid.Column="0" />
<Image
Source="icon.png"
Grid.Row="0"
Grid.Column="0"
VerticalOptions="Center" />
<Grid
Padding="10"
Grid.Row="1"
Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition
Height="*" />
<RowDefinition
Height="2*" />
<RowDefinition
Height="*" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Label
Text="Unisciti a Youni!"
FontSize="Large"
FontAttributes="Bold"
HorizontalTextAlignment="Center"
TextColor="#174668"
Grid.Row="0"
Grid.Column="0"
VerticalOptions="Center" />
<StackLayout
Grid.Row="1"
Grid.Column="0"
Spacing="0"
VerticalOptions="Fill">
<Entry
Text="{Binding RegName}"
Placeholder="Nome"
VerticalOptions="FillAndExpand" />
<Entry
Text="{Binding RegSurname}"
Placeholder="Cognome"
VerticalOptions="FillAndExpand" />
<Entry
Text="{Binding RegEmail}"
Placeholder="Email"
Keyboard="Email"
VerticalOptions="FillAndExpand" />
<Entry
Text="{Binding RegPassword}"
Placeholder="Password"
IsPassword="true"
VerticalOptions="FillAndExpand" />
<Entry
Text="{Binding RegPasswordConfirm}"
Placeholder="Conferma password"
IsPassword="true"
VerticalOptions="FillAndExpand" />
</StackLayout>
<Button
Command="{Binding RegisterCommand}"
Text=" Registrati "
TextColor="White"
BackgroundColor="#3A8FDA"
Grid.Row="2"
Grid.Column="0"
HorizontalOptions="Center"
VerticalOptions="Center" />
<StackLayout
Orientation="Horizontal"
HorizontalOptions="Center"
VerticalOptions="Center"
Grid.Row="3"
Grid.Column="0">
<StackLayout.Spacing>
<OnPlatform
x:TypeArguments="x:Double">
<On
Platform="Android"
Value="-10" />
<On
Platform="iOS"
Value="3" />
</OnPlatform>
</StackLayout.Spacing>
<Label
Text="Sei già registrato?"
FontSize="Small"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center" />
<Button
x:Name="LoginSwitchButton"
Pressed="LoginSwitch_Handle_Pressed"
Released="LoginSwitch_Handle_Released"
Command="{Binding LoginSwitchCommand}"
Text="Passa al login"
FontSize="Small"
TextColor="#45BFEE"
BackgroundColor="Transparent" />
</StackLayout>
</Grid>
</Grid>
My suggestion to fix your issue would be to start by simplifying your layout because you have extra nested views inside of grids when one single Grid could probably be used for the entire thing. For example:
<Grid ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Grid.ColumnSpan="2" Source="blue_background.png" Aspect="Fill" />
<Image Grid.ColumnSpan="2" Source="icon.png" VerticalOptions="Center" HorizontalOptions="Center"/>
<Label Grid.Row="1" Grid.ColumnSpan="2" Text="Unisciti a Youni!" FontSize="Large" FontAttributes="Bold" TextColor="#174668" VerticalOptions="Center" HorizontalOptions="Center"/>
<Entry Grid.Row="2" Grid.ColumnSpan="2" Margin="10,0" Text="{Binding RegName}" Placeholder="Nome" VerticalOptions="FillAndExpand" />
<Entry Grid.Row="3" Grid.ColumnSpan="2" Margin="10,0" Text="{Binding RegSurname}" Placeholder="Cognome" VerticalOptions="FillAndExpand" />
<Entry Grid.Row="4" Grid.ColumnSpan="2" Margin="10,0" Text="{Binding RegEmail}" Placeholder="Email" Keyboard="Email" VerticalOptions="FillAndExpand" />
<Entry Grid.Row="5" Grid.ColumnSpan="2" Margin="10,0" Text="{Binding RegPassword}" Placeholder="Password" IsPassword="true" VerticalOptions="FillAndExpand" />
<Entry Grid.Row="6" Grid.ColumnSpan="2" Margin="10,0" Text="{Binding RegPasswordConfirm}" Placeholder="Conferma password" IsPassword="true" VerticalOptions="FillAndExpand" />
<Button Grid.Row="7" Grid.ColumnSpan="2" Command="{Binding RegisterCommand}" Text=" Registrati " TextColor="White" BackgroundColor="#3A8FDA" HorizontalOptions="Center" VerticalOptions="Center" />
<Label Grid.Row="8" Text="Sei già registrato?" FontSize="Small" VerticalOptions="Center" HorizontalOptions="End" />
<Button Grid.Row="8" Grid.Column="1" x:Name="LoginSwitchButton" Command="{Binding LoginSwitchCommand}" Text="Passa al login" VerticalOptions="Center" HorizontalOptions="Start" FontSize="Small" TextColor="#45BFEE" BackgroundColor="Transparent" />
</Grid>
Then from there I'd adjust the row heights and spacing to match your designs accordingly.
Just change your root container layout to ScrollView
<ScrollView>
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="*" />
</Grid.RowDefinitions>
<Image
Source="blue_background.png"
Aspect="Fill"
Grid.Row="0"
Grid.Column="0" />
<Image
Source="icon.png"
Grid.Row="0"
Grid.Column="0"
VerticalOptions="Center" />
<Grid
Padding="10"
Grid.Row="1"
Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition
Height="*" />
<RowDefinition
Height="2*" />
<RowDefinition
Height="*" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Label
Text="Unisciti a Youni!"
FontSize="Large"
FontAttributes="Bold"
HorizontalTextAlignment="Center"
TextColor="#174668"
Grid.Row="0"
Grid.Column="0"
VerticalOptions="Center" />
<StackLayout
Grid.Row="1"
Grid.Column="0"
Spacing="0"
VerticalOptions="Fill">
<Entry
Text="{Binding RegName}"
Placeholder="Nome"
VerticalOptions="FillAndExpand" />
<Entry
Text="{Binding RegSurname}"
Placeholder="Cognome"
VerticalOptions="FillAndExpand" />
<Entry
Text="{Binding RegEmail}"
Placeholder="Email"
Keyboard="Email"
VerticalOptions="FillAndExpand" />
<Entry
Text="{Binding RegPassword}"
Placeholder="Password"
IsPassword="true"
VerticalOptions="FillAndExpand" />
<Entry
Text="{Binding RegPasswordConfirm}"
Placeholder="Conferma password"
IsPassword="true"
VerticalOptions="FillAndExpand" />
</StackLayout>
<Button
Command="{Binding RegisterCommand}"
Text=" Registrati "
TextColor="White"
BackgroundColor="#3A8FDA"
Grid.Row="2"
Grid.Column="0"
HorizontalOptions="Center"
VerticalOptions="Center" />
<StackLayout
Orientation="Horizontal"
HorizontalOptions="Center"
VerticalOptions="Center"
Grid.Row="3"
Grid.Column="0">
<StackLayout.Spacing>
<OnPlatform
x:TypeArguments="x:Double">
<On
Platform="Android"
Value="-10" />
<On
Platform="iOS"
Value="3" />
</OnPlatform>
</StackLayout.Spacing>
<Label
Text="Sei già registrato?"
FontSize="Small"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center" />
<Button
x:Name="LoginSwitchButton"
Pressed="LoginSwitch_Handle_Pressed"
Released="LoginSwitch_Handle_Released"
Command="{Binding LoginSwitchCommand}"
Text="Passa al login"
FontSize="Small"
TextColor="#45BFEE"
BackgroundColor="Transparent" />
</StackLayout>
</Grid>
</Grid>
</ScrollView>
Put your Grid in ScrollView
I want to add navigation bar in cart icon with badge count.
I have added cart icon in navigation bar using toolbar item. and also created badge count circle view using plugin. if i am giving margin to set that badge icon to toolbar item it is hide behind tabbed page.
It is not displaying on cart icon.
Please help me out this.
As per above image i want to set badge count with tabbed page.
Below is my XAML Code.
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:lang="clr-namespace:Conekto"
xmlns:controls="clr-namespace:Conekto.Controls;"
x:Class="ProjectName.Pages.SalePage">
<TabbedPage.Children>
<ContentPage Title="{lang:Translate PRODUCTLIST}">
<Grid Margin="10,10,10,0" BackgroundColor="White">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Text="charge 15,123" Style="{StaticResource primaryButton}" />
<SearchBar x:Name="txtSearch" Grid.Row="1" Grid.Column="0" TextChanged="MySearchBarOnTextChanged" Placeholder="{lang:Translate Search}" SearchCommand="{Binding SearchCommand, Mode=TwoWay}" CancelButtonColor="Blue" Text="{Binding SearchText, Mode=TwoWay}" Style="{StaticResource labelgreycolour}" WidthRequest="50" HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" />
<StackLayout Grid.Row="2" Grid.Column="0" VerticalOptions="StartAndExpand" HorizontalOptions="FillAndExpand">
<ListView x:Name="listView" ItemsSource="{Binding ProductList}" HasUnevenRows="True" IsPullToRefreshEnabled="true" RefreshCommand="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}" ItemAppearing="listView_ItemAppearing" ItemSelected="listView_ItemSelected" SelectedItem="{Binding listView_ItemSelected, Mode=TwoWay}" BackgroundColor="White" HorizontalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Margin="0,5,0,5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="50*" />
<ColumnDefinition Width="40*" />
</Grid.ColumnDefinitions>
<Image Source="add" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Aspect="AspectFit" HeightRequest="30" WidthRequest="30" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding BindingContext.AddProductCommand, Source={x:Reference listView}}" CommandParameter="{Binding .}" NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Grid.Row="0" Grid.Column="1" VerticalOptions="CenterAndExpand" VerticalTextAlignment="End" Text="{Binding ProductName,Mode=TwoWay}" Style="{StaticResource entrylogin}" />
<Label Grid.Row="1" Grid.Column="1" VerticalOptions="CenterAndExpand" VerticalTextAlignment="End" Text="{Binding Cost,Mode=TwoWay,StringFormat='XOF {0}'}" Style="{StaticResource listViewsublabel}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</Grid>
<controls:FloatingActionButton Margin="0,0,20,20" Grid.Row="0" x:Name="FABCart" HorizontalOptions="End" VerticalOptions="End" WidthRequest="60" HeightRequest="60" Image="cart" ButtonColor="#09999A" Clicked="FabCart_Clicked" />
<controls:BadgeView Margin="0,0,32,52" Grid.Row="0" Text="{Binding TotalCartItem, Mode=TwoWay}" BadgeColor="White" HorizontalOptions="End" VerticalOptions="End" />
</Grid>
</ContentPage>
<ContentPage Title="{lang:Translate KEYPAD}">
<ContentPage.BackgroundColor>
<OnPlatform x:TypeArguments="Color">
<OnPlatform.Platforms>
<On Platform="iOS" Value="Black" />
<On Platform="Android" Value="#eee" />
</OnPlatform.Platforms>
</OnPlatform>
</ContentPage.BackgroundColor>
<Grid x:Name="controlGrid" Margin="0,0,0,0" Padding="0,0,0,0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid.ColumnSpacing>
<OnPlatform x:TypeArguments="x:Double">
<OnPlatform.Platforms>
<On Platform="iOS" Value="1" />
<On Platform="Android" Value="0" />
</OnPlatform.Platforms>
</OnPlatform>
</Grid.ColumnSpacing>
<Grid.RowSpacing>
<OnPlatform x:TypeArguments="x:Double">
<OnPlatform.Platforms>
<On Platform="iOS" Value="1" />
<On Platform="Android" Value="0" />
</OnPlatform.Platforms>
</OnPlatform>
</Grid.RowSpacing>
<Grid.RowDefinitions>
<RowDefinition Height="74" />
<RowDefinition Height="80" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Text="charge 15,123" Margin="12,12,12,12" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Style="{StaticResource primaryButton}" />
<Label Text="Add note" FontSize="10" Grid.Column="0" Grid.Row="1" HorizontalTextAlignment="Center" VerticalTextAlignment="End" TextColor="Black" />
<Label x:Name="lblVal" Margin="0,0,16,0" Grid.Row="1" Grid.Column="1" HorizontalTextAlignment="End" VerticalTextAlignment="Center" TextColor="Black" FontSize="30" Grid.ColumnSpan="2" VerticalOptions="End" />
<Button Clicked="Button_Clicked" Text ="7" Grid.Row="2" Grid.Column="0" Style="{StaticResource plainButton}" />
<Button Clicked="Button_Clicked" Text = "8" Grid.Row="2" Grid.Column="1" Style="{StaticResource plainButton}" />
<Button Clicked="Button_Clicked" Text = "9" Grid.Row="2" Grid.Column="2" Style="{StaticResource plainButton}" />
<Button Clicked="Button_Clicked" Text = "4" Grid.Row="3" Grid.Column="0" Style="{StaticResource plainButton}" />
<Button Clicked="Button_Clicked" Text = "5" Grid.Row="3" Grid.Column="1" Style="{StaticResource plainButton}" />
<Button Clicked="Button_Clicked" Text = "6" Grid.Row="3" Grid.Column="2" Style="{StaticResource plainButton}" />
<Button Clicked="Button_Clicked" Text = "1" Grid.Row="4" Grid.Column="0" Style="{StaticResource plainButton}" />
<Button Clicked="Button_Clicked" Text = "2" Grid.Row="4" Grid.Column="1" Style="{StaticResource plainButton}" />
<Button Clicked="Button_Clicked" Text = "3" Grid.Row="4" Grid.Column="2" Style="{StaticResource plainButton}" />
<Button Clicked="ButtonClear_Clicked" Text = "C" Grid.Row="5" Grid.Column="0" Style="{StaticResource plainButton}" />
<Button Clicked="Button_Clicked" Text = "0" Grid.Row="5" Grid.Column="1" Style="{StaticResource plainButton}" />
<Button Clicked="Button_Clicked" Text = "+" Grid.Row="5" Grid.Column="2" Style="{StaticResource plainButton}" />
</Grid>
</ContentPage>
<ContentPage Title="{lang:Translate SCAN}">
</ContentPage>
</TabbedPage.Children>
And in .cs Page code i am adding cart icon in toolbar item.
ToolbarItems.Add(new ToolbarItem("Add Product", "floating", async () =>
{
//var page = new ContentPage();
//var result = await page.DisplayAlert("Title", "Message", "Accept", "Cancel");
await Navigation.PushAsync(new CreateProductPage() { Title = Helper.GetResxNameByValue("CreateProduct") });
//Debug.WriteLine("success: {0}", result);
}));
As per design i have added cart button as floating button. Please do not consider that.
To add badge on toolbar item you can hide the default tool bar by using NavigationPage.SetHasNavigationBar(this, false); then you can create your own tool bar with button having badge counter and hamburger to show and hide side menu.
On page in which hamburger button is clicked:
private void Button_Clicked(object sender, System.EventArgs e)
{
MessagingCenter.Send(this, "presnt");
}
On MasterDetail page:
MessagingCenter.Subscribe<YourPage>(this, "presnt", (sender) =>
{
IsPresented = true;
});
Also, Before making IsPresented=true, check for sliding menu is not all-ready presented.
you can check https://github.com/LeslieCorrea/Xamarin-Forms-Shopping-Cart this link for more information. But by using this method in android may make the nav bar appear below tabs, so you may need to create tabs using buttons.
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal">
<Label FontAttributes="Bold" TextColor="Black" FontSize="Medium" Text="Female Category" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"></Label>
<AbsoluteLayout Margin="0,0,5,0" HorizontalOptions="EndAndExpand">
<Frame BackgroundColor="White" BorderColor="Black" CornerRadius="50" WidthRequest="40"
Padding="0"
Margin="0,10,0,10">
<ImageButton Source="add_to_basket.png" BackgroundColor="Transparent" Clicked="ImageButton_Clicked" Padding="5"/>
</Frame>
<Frame BackgroundColor="Red" HeightRequest="30" BorderColor="Black" WidthRequest="20" CornerRadius="50" Padding="0,0,0,-10" Margin="25,5,0,0">
<Label HorizontalOptions="CenterAndExpand" Text="53" TextColor="White" />
</Frame>
</AbsoluteLayout>
</StackLayout>
</NavigationPage.TitleView>