I am trying to display items, but only {Binding Peso} is displayed.
If you change {Binding Peso} and use{Binding Contenido} you can see that it is displayed OK
Any Help Pls?
`
<ListView x:Name="PaqueteList">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Frame BorderColor="Black">
<StackLayout Margin="5" Grid.Column="0" Orientation="Vertical"
HorizontalOptions="StartAndExpand"
VerticalOptions="Center">
<Label Text ="{Binding Peso}"
TextColor="Blue"
BackgroundColor="White"
/>
<Label Grid.Column="1" Text ="{Binding TrackingNumber} "
TextColor="Blue"
BackgroundColor="White"
/>
<Label Grid.Column="2" Text ="{Binding Contenido}"
TextColor="Blue"
BackgroundColor="White"
/>
</StackLayout>
</Frame>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I have changed the {Binding Peso} to {Binding Contenido} and so on, and it is works.
I just need to display something like this
Peso Tracking Contenido
xx yyyyy zzzz
xx yyyyy zzzz
xx yyyyy zzzz
Try this for your ViewCell:
<ViewCell>
<Frame BorderColor="Black">
<Grid
Margin="5"
HorizontalOptions="StartAndExpand"
VerticalOptions="Center"
ColumnDefinitions="*, *, *">
<Label
BackgroundColor="White"
Text="{Binding Peso}"
TextColor="Blue" />
<Label
Grid.Column="1"
BackgroundColor="White"
Text="{Binding TrackingNumber}"
TextColor="Blue" />
<Label
Grid.Column="2"
BackgroundColor="White"
Text="{Binding Contenido}"
TextColor="Blue" />
</Grid>
</Frame>
</ViewCell>
You should add the children views into a ListView like the pattern below:
<ListView>
<ViewCell>
<StackLayout>
<Frame>
<Grid>
</Grid>
<Frame/>
</StackLayout>
</ViewCell>
</ListView>
Below is the code snippet for your reference:
<ListView x:Name="PaqueteList" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Margin="5" Orientation="Vertical" HorizontalOptions="StartAndExpand" VerticalOptions="Center">
<Frame BorderColor="Black">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Text ="{Binding Peso}"
TextColor="Blue"
BackgroundColor="White"/>
<Label Grid.Column="1" Text ="{Binding TrackingNumber} "
TextColor="Blue"
BackgroundColor="White"
/>
<Label Grid.Column="2" Text ="{Binding Contenido}"
TextColor="Blue"
BackgroundColor="White" />
</Grid>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I have a Xamarin project with a view of a product's details. I have two buttons which can increase or decrease the quantity of the product. To show how it changes I have a label named lblQuantity which shows the quantity and it's updated if you tap on the remove or add button.
To have some context here's the view
The issue is that the lblQuantity isn't updating itself. I had previously another view with a stacklayout and the gesture recognizers worked fine. Now it doesn't even go inside the method.
Here's the xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:controls="clr-namespace:AppCrijoya.Controls"
x:Class="AppCrijoya.Views.ProductDetailPage">
<ScrollView>
<StackLayout VerticalOptions="FillAndExpand" BackgroundColor="White" Spacing="0" Margin="0" Padding="0">
<Grid BackgroundColor="White" RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<!-- 1. Profile picture-->
<Frame HasShadow="True" Margin="10" CornerRadius="20">
<Image x:Name="ProductImage" Aspect="AspectFit" Grid.Row="0" Margin="0" VerticalOptions="Start" HeightRequest="230"/>
</Frame>
<!-- Here add the code that is being explained in the next block-->
<StackLayout HeightRequest="90" Grid.Row="1" BackgroundColor="Transparent" VerticalOptions="Start">
<StackLayout Padding="20" BackgroundColor="Transparent">
<!-- Here add the code that is being explained in the next block-->
<!-- Blocks: 3 and 4 -->
<Grid Padding="25,5,25,0" RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="80"/>
</Grid.RowDefinitions>
<!-- Here add the code that is being explained in the next block-->
<!-- 4. Contact information-->
<Label x:Name="txtName" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" FontAttributes="Bold" FontSize="30" TextColor="Black"/>
<Label x:Name="txtDescription" Grid.Row="1" Grid.ColumnSpan="4" TextColor="Black" FontSize="16"/>
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" Padding="0,10,0,0" FontSize="16">
<Label.FormattedText>
<FormattedString>
<Span Text="Stock: " FontAttributes="Bold" TextColor="Black"/>
<Span x:Name="txtDetails" TextColor="black"/>
</FormattedString>
</Label.FormattedText>
</Label>
<!--4. Contact information: Board inforation-->
<Label Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="3" Text="Quantity" FontAttributes="Bold" Style="{StaticResource stlBoardTitle}" />
<Frame Grid.Column="2" Grid.Row="3" Style="{StaticResource stkCart}">
<Frame.GestureRecognizers>
<TapGestureRecognizer x:Name="RemoveTap" Tapped="RemoveTap_Tapped"/>
</Frame.GestureRecognizers>
<Label Text="-" Style="{StaticResource lblCart}"/>
</Frame>
<StackLayout Grid.Column="3" Grid.Row="3" HeightRequest="40" VerticalOptions="Center" >
<Label
x:Name="lblQuantity"
Text="1"
FontSize="17"
TextColor="Black"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
HeightRequest="40"/>
</StackLayout>
<Frame Grid.Column="4" Grid.Row="3" Style="{StaticResource stkCart}">
<Frame.GestureRecognizers>
<TapGestureRecognizer x:Name="AddTap" Tapped="AddTap_Tapped"/>
</Frame.GestureRecognizers>
<Label Text="+" Style="{StaticResource lblCart}"/>
</Frame>
</Grid>
</StackLayout>
</StackLayout>
</Grid>
<controls:MyFrame HasShadow="true" HeightRequest="80" BackgroundColor="#e5d3c2" VerticalOptions="EndAndExpand">
<StackLayout WidthRequest="20" VerticalOptions="Center">
<Grid ColumnSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Label
x:Name="txtPrice"
Grid.Column="0"
HorizontalTextAlignment="End"
TextColor="White"
HorizontalOptions="Center"
VerticalOptions="Center"
FontAttributes="Bold"
FontSize="25"
/>
<Button CornerRadius="30"
x:Name="btnAddToCart"
Clicked="BtnAddToCart_Clicked"
Grid.Column="2"
TextColor="Black"
Text="Añadir al carrito"
BackgroundColor="White"
Style="{StaticResource btn}"
FontAttributes="Bold"
/>
</Grid>
</StackLayout>
</controls:MyFrame>
</StackLayout>
</ScrollView>
</ContentPage>
Here's the Add and Remove method that I know work fine
private void RemoveTap_Tapped(object sender, EventArgs e)
{
int quantity = Convert.ToInt32(lblQuantity.Text);
if (quantity > 1)
{
quantity -= 1;
}
lblQuantity.Text = quantity.ToString();
}
private void AddTap_Tapped(object sender, EventArgs e)
{
int quantity = Convert.ToInt32(lblQuantity.Text);
quantity += 1;
lblQuantity.Text = quantity.ToString();
}
The text of the label is supossed to be changed but it isn't. And as I said it doesn't even enter on the method.
I don't know what's the issue. Please help and thanks.
EDIT
I have tried changing it for a Button but still doesn't work. I thought it might be a problem with the grid but I still don't know.
I fixed the issue by making sure the frames where inside the StackLayout as they weren't before
Here is an image to explain it
The frames to add or remove weren't inside the red StackLayout so the tap gesture recognizer wouldn't do anything. I just gave it more height and set the Aspect to FillAndExpand
I have a hidden elements, and when I click on some marker in the map they are visualized.
But when the are hidden when I start app I have some big empty space ?
This is the 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:local="clr-namespace:MaritsaTundzhaForecast"
xmlns:local1="clr-namespace:MaritsaTundzhaForecast.Models"
x:Class="MaritsaTundzhaForecast.MainPage">
<ContentPage.Resources>
<ResourceDictionary>
<local1:LevelToImageConverter x:Key="levelImage" />
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout
BackgroundColor="#262626"
HeightRequest="10">
<Label Text="ХИДРОЛОГИЧНА ПРОГНОЗА"
HorizontalOptions="CenterAndExpand"
VerticalTextAlignment="End"
FontAttributes="Bold"
TextColor="White"
Padding="0,10,0,0"/>
<Label Text="Финансирано по програма на МОН НП 'Млади учени и постдокторанти.' НИМХ - Филиал Пловдив."
HorizontalOptions="CenterAndExpand"
VerticalTextAlignment="End"
FontAttributes="Bold"
TextColor="White"
Padding="0,10,0,0"/>
<Button Text="ПРЕДСТАВЯНЕ И ТЪЛКУВАНЕ НА ПРОГНОЗАТА"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Clicked="OnButtonClicked" />
<ScrollView VerticalOptions="FillAndExpand" x:Name="scrollView">
<Grid Margin="0,10,0,10" VerticalOptions="EndAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="280" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Frame x:Name="frameLevelAlertLbl"
BackgroundColor="#262626"
CornerRadius="30"
HasShadow="True">
<StackLayout Grid.Row="0" x:Name="contentLbl" Spacing="0">
<Label x:Name="LevelAlertLbl"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
TextColor="Black"
FontAttributes="Bold"
FontSize="Medium"/>
</StackLayout>
</Frame>
<StackLayout Grid.Row="1">
<Label x:Name="LevelAlertLbl1"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
TextColor="Black"
FontAttributes="Bold"
FontSize="Medium">
</Label>
</StackLayout>
<StackLayout Grid.Row="2">
<local:CustomMap x:Name="customMap"
MapType="Street"
HasZoomEnabled="True"
HasScrollEnabled="True"
TrafficEnabled="True"
MoveToLastRegionOnLayoutChange="False"/>
</StackLayout>
<StackLayout Grid.Row="3" x:Name="InfoLblForecast" >
<Label TextColor="White" BackgroundColor="#6588cf" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" x:Name="selectedStationLbl" FontAttributes="Bold"/>
</StackLayout>
<StackLayout Grid.Row="4" >
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Frame x:Name="FrameCheckStation"
CornerRadius="30"
HasShadow="True"
BackgroundColor="#262626"
Grid.ColumnSpan="3" Grid.Row="0">
<Label TextColor="White" Grid.ColumnSpan="3" Grid.Row="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" x:Name="checkStationLbl" FontAttributes="Bold"/>
</Frame>
<Label TextColor="White" Grid.ColumnSpan="3" Grid.Row="1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" x:Name="checkStationLbl1" FontAttributes="Bold"/>
<Label Text="Дата/час:" BackgroundColor="#6588cf" TextColor="White" Grid.Column="0" Grid.Row="2" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" x:Name="labelColumn1" FontAttributes="Bold"/>
<Label Text="Показател:" BackgroundColor="#6588cf" TextColor="White" Grid.Column="1" Grid.Row="2" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" x:Name="labelColumn2" FontAttributes="Bold"/>
<Label Text="Праг (0-3):" BackgroundColor="#6588cf" TextColor="White" Grid.Column="2" Grid.Row="2" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" x:Name="labelColumn3" FontAttributes="Bold"/>
</Grid>
<StackLayout>
<ListView x:Name="lstLevel" HasUnevenRows="True" BackgroundColor="#f7f77c">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid BackgroundColor="#f7f77c">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding dateForecast, StringFormat='{0:dd.MM} - {0:hh\\:mmч.}'}" XAlign="Start" YAlign="Center" TextColor="Black" FontAttributes="Bold" FontSize="Small"/>
<Image Grid.Row="0" Grid.Column="1" Source="{Binding levelForecast, Converter={StaticResource levelImage}}" Aspect="Fill"/>
<Label Grid.Row="0" Grid.Column="2" Text="{Binding levelForecast}" XAlign="Center" YAlign="Center" TextColor="Black" FontAttributes="Bold" FontSize="Small"/>
<BoxView Color="#001aff" HeightRequest="1" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"/>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
<StackLayout Grid.Row="5">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Frame x:Name="FrameCheckValuesLbl"
CornerRadius="30"
HasShadow="True"
BackgroundColor="#262626"
Grid.ColumnSpan="3" Grid.Row="0">
<Label BackgroundColor="Green" TextColor="White" Grid.ColumnSpan="3" Grid.Row="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" x:Name="checkValuesLbl" FontAttributes="Bold"/>
</Frame>
<Label Text="Дата/час:" BackgroundColor="#6588cf" TextColor="White" Grid.Column="0" Grid.Row="1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" x:Name="labelColumn11" FontAttributes="Bold"/>
<Label Text="Показател:" BackgroundColor="#6588cf" TextColor="White" Grid.Column="1" Grid.Row="1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" x:Name="labelColumn22" FontAttributes="Bold"/>
<Label Text="Праг (0-3):" BackgroundColor="#6588cf" TextColor="White" Grid.Column="2" Grid.Row="1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" x:Name="labelColumn33" FontAttributes="Bold"/>
</Grid>
<StackLayout HeightRequest="80">
<ListView x:Name="lstLevel2" HasUnevenRows="True" BackgroundColor="#f7f77c">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid BackgroundColor="#f7f77c">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding dateForecast, StringFormat='{0:dd.MM} - {0:hh\\:mmч.}'}" XAlign="Start" YAlign="Center" TextColor="Black" FontAttributes="Bold" FontSize="Small"/>
<Image Grid.Row="0" Grid.Column="1" Source="{Binding levelForecast, Converter={StaticResource levelImage}}" Aspect="Fill"/>
<Label Grid.Row="0" Grid.Column="2" Text="{Binding levelForecast}" XAlign="Center" YAlign="Center" TextColor="Black" FontAttributes="Bold" FontSize="Small"/>
<BoxView Color="#001aff" HeightRequest="1" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"/>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</StackLayout>
</StackLayout>
</Grid>
</ScrollView>
</StackLayout>
</ContentPage>
I have six rows - 0,1,2,3 are not hidden.
rows - 4,5,6 is hidden.
How to reduce ScrollView to rows 0,1,2,3 and when rows 4,5,6 are showing to reduce automatic to the end ?
You can achieve the hidden effect by modifying the row height defined by the Grid.
Here is the xaml code:
<StackLayout>
<ScrollView>
<Grid x:Name="myGrid">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto" />
<RowDefinition Height="280" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="200" />
</Grid.RowDefinitions>
<Label BackgroundColor="Red"></Label>
<Label BackgroundColor="Orange" Grid.Row="1"></Label>
<Label BackgroundColor="Yellow" Grid.Row="2"></Label>
<Label BackgroundColor="Green" Grid.Row="3"></Label>
<Label BackgroundColor="Blue" Grid.Row="4"></Label>
<Label BackgroundColor="Purple" Grid.Row="5"></Label>
</Grid>
</ScrollView>
<Button Clicked="Button_Clicked" HeightRequest="50" Text="click"></Button>
</StackLayout>
Here is the background code:
private void Button_Clicked(object sender, EventArgs e)
{
var res = myGrid.RowDefinitions;
(res[3] as RowDefinition).Height = 0;
(res[4] as RowDefinition).Height = 0;
(res[5] as RowDefinition).Height = 0;
}
I am implementing a picker in xamarin.forms project so while implementing that I am getting the above issue
XamarinPicker.xaml
<pages:CustomPage.Content>
<Grid>
<Grid.Padding>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="10,20,10,10" />
<On Platform="Android" Value="10" />
</OnPlatform>
</Grid.Padding>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Frame Grid.Row="0" Padding="10,1,0,1" Margin="10,0,10,10" HeightRequest="50" HasShadow="False" BorderColor="#24527A" CornerRadius="5" VerticalOptions="Start">
<Grid ColumnSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<controls:CustomEntry Placeholder="{local:Translate NoteSearchHint}" Text="{Binding SearchText}">
<controls:CustomEntry.Behaviors>
<behaviors:EventToCommandBehavior EventName="TextChanged" Command="{Binding TextChangeCommand}" />
</controls:CustomEntry.Behaviors>
</controls:CustomEntry>
<BoxView Grid.Column="1" BackgroundColor="#24527A"/>
<Image Grid.Column="2" Source="search_black" IsEnabled="{Binding IsSearchEnable}" IsVisible="{Binding SearchButtonVisibility}" HeightRequest="20" WidthRequest="20" VerticalOptions="Center" HorizontalOptions="Center" >
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SearchCommand}"/>
</Image.GestureRecognizers>
</Image>
<Image Grid.Column="2" IsEnabled="{Binding IsCloseEnable}" IsVisible="{Binding CloseButtonVisibility}" Source="close_gray" HeightRequest="{OnIdiom Phone='20',Tablet='30'}" WidthRequest="{OnIdiom Phone='20',Tablet='30'}" Aspect="AspectFit" VerticalOptions="Center">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding CloseCommand}"/>
</Image.GestureRecognizers>
</Image>
</Grid>
</Frame>
<StackLayout Grid.Row="1">
<Grid Padding="{OnIdiom Phone='20,10,20,0',Tablet='30,15,30,0'}" RowSpacing="0" ColumnSpacing="{OnIdiom Phone='20',Tablet='30'}" VerticalOptions="Start">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="{OnIdiom Phone='44',Tablet='58'}" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackLayout Grid.Row="0" Grid.Column="0">
<Label Text="My Notes" TextColor="{Binding Tab1TextColor}" Style="{DynamicResource LibraryPurpleSemiBoldLabel}" />
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ChangeTabCommand}" CommandParameter="1" />
</StackLayout.GestureRecognizers>
</StackLayout>
<BoxView Grid.Row="1" Grid.Column="0" IsVisible="{Binding IsVisibleTab1Box}" HeightRequest="{OnIdiom Phone='4',Tablet='7'}" HorizontalOptions="FillAndExpand" VerticalOptions="End" BackgroundColor="{DynamicResource Yellow}" CornerRadius="{OnIdiom Phone='4,4,0,0',Tablet='7,7,0,0'}" />
<StackLayout Grid.Row="0" Grid.Column="1">
<Label Text="Other Notes" TextColor="{Binding Tab2TextColor}" Style="{DynamicResource LibraryGraySemiBoldLabel}" />
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ChangeTabCommand}" CommandParameter="2" />
</StackLayout.GestureRecognizers>
</StackLayout>
<BoxView Grid.Row="1" Grid.Column="1" IsVisible="{Binding IsVisibleTab2Box}" HeightRequest="{OnIdiom Phone='4',Tablet='7'}" HorizontalOptions="FillAndExpand" VerticalOptions="End" BackgroundColor="{DynamicResource Yellow}" CornerRadius="{OnIdiom Phone='4,4,0,0',Tablet='7,7,0,0'}" />
</Grid>
</StackLayout>
<StackLayout Grid.Row="2" Padding="0" HorizontalOptions="EndAndExpand" IsVisible="{Binding FilterVisibility}" VerticalOptions="StartAndExpand" Orientation="Horizontal">
<Label Text="Filter by:"/>
<Frame HeightRequest="{OnIdiom Phone='30',Tablet='50'}" Padding="0" HasShadow="false" CornerRadius="{OnIdiom Phone='4',Tablet='6'}" VerticalOptions="StartAndExpand" HorizontalOptions="FillAndExpand">
<Picker x:Name="FilterPicker"
ios:Picker.UpdateMode="WhenFinished"
Title="All"
TitleColor="{DynamicResource LightGray}"
BackgroundColor="{DynamicResource TransparentLightGray}"
FontSize="{DynamicResource FontSize14}"
SelectedItem="{Binding SelectedFilter,Mode=TwoWay}">
<Picker.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>All</x:String>
<x:String>Public</x:String>
<x:String>Private</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
<!--<Image IsVisible="{Binding EndDropDownVisible}" AbsoluteLayout.LayoutBounds="0.95,0.5,20,20" AbsoluteLayout.LayoutFlags="PositionProportional" Source="chevrondropdown" HeightRequest="{OnIdiom Phone='20',Tablet='30'}" WidthRequest="{OnIdiom Phone='20',Tablet='30'}" VerticalOptions="Center">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="EndDateImage_Tapped"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>-->
</Frame>
</StackLayout>
<ListView x:Name="NoteList" Grid.Row="3" ItemsSource="{Binding Notes}" HasUnevenRows="True" IsVisible="{Binding IsViewVisible}" CachingStrategy="RetainElement" SeparatorVisibility="None">
<ListView.ItemTemplate>
<DataTemplate>
<!--<StackLayout Orientation="Vertical" HeightRequest="90" Margin="5,15,5,5" Padding="10,5,10,5">
<StackLayout Orientation="Horizontal">
<BoxView Color="Black" WidthRequest="5" HeightRequest="80" VerticalOptions="Center" />
<Label Text="Note text" FontSize="14" HeightRequest="80" TextColor="#585858" Margin="3,0,0,0"></Label>
</StackLayout>
<Label Text="Sample note text added by user" FontSize="10" VerticalOptions="StartAndExpand" FontAttributes="Bold" HorizontalOptions="StartAndExpand" TextColor="#000000" Margin="5,0,0,0"></Label>
</StackLayout>-->
<ViewCell>
<Frame Grid.Row="0" HasShadow="False" Padding="0" Margin="10,5" BorderColor="#e0e4e2" IsClippedToBounds="True" CornerRadius="10">
<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<BoxView BackgroundColor="{Binding NoteData.NoteColor, Converter={converters:HighlightColorConverter}}" Grid.Column="0" Grid.Row="0" Grid.RowSpan="5" WidthRequest="10"/>
<Label Text="{Binding NoteData.NoteText}" Grid.Column="1" Grid.Row="0" FontSize="Small" LineBreakMode="TailTruncation" FontAttributes="Italic" Margin="5,10,0,0" TextColor="Gray" MaxLines="2" VerticalTextAlignment="Center"/>
<Label Text="{local:Translate NoteLabel}" Grid.Column="1" Grid.Row="1" FontSize="Large" FontAttributes="Bold" Margin="5,5,0,5" VerticalTextAlignment="Center" TextColor="#3c5d80"/>
<Label Text="{Binding NoteData.NoteContent}" VerticalTextAlignment="Center" VerticalOptions="Center" Grid.Column="1" Grid.Row="2" FontSize="15" Margin="5,3,0,5" FontAttributes="Bold"/>
<Label Grid.Column="1" Grid.Row="3" TextColor="Gray" FontSize="10" Margin="5,0,0,10">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding PageNumber,Converter={converters:EpubPageIndexConverter}, StringFormat='Page Number : {0}'}" />
<Span Text="{Binding DisplayCreatedDate, StringFormat=' Added on {0: dd-MM-yyyy}'}" />
</FormattedString>
</Label.FormattedText>
</Label>
<StackLayout Grid.Column="1" Grid.Row="4" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="1" Text="Make it:"/>
<Frame Grid.Row="1" Grid.Column="2" HeightRequest="{OnIdiom Phone='30',Tablet='50'}" Padding="0" HasShadow="false" CornerRadius="{OnIdiom Phone='4',Tablet='6'}" VerticalOptions="StartAndExpand" HorizontalOptions="FillAndExpand">
<Picker
ios:Picker.UpdateMode="WhenFinished"
Title="Select One"
TitleColor="{DynamicResource LightGray}"
BackgroundColor="{DynamicResource TransparentLightGray}"
FontSize="{DynamicResource FontSize14}"
SelectedItem="{Binding PublicPrivate}">
<Picker.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Public</x:String>
<x:String>Private</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
</Frame>
</Grid>
</StackLayout>
<ImageButton Source="more" HeightRequest="15" WidthRequest="15" Grid.Row="0" Grid.Column="2" Grid.RowSpan="4" VerticalOptions="Start" Margin="0,10,15,0" Command="{Binding Source={x:Reference NoteList}, Path=BindingContext.OpenActionPopupCommand}" CommandParameter="{Binding .}"/>
</Grid>
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference NoteList}, Path=BindingContext.SelectNoteCommand}" CommandParameter="{Binding .}"/>
</Frame.GestureRecognizers>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackLayout Grid.Row="3" IsVisible="{Binding IsViewVisible, Converter={converters:InverseBooleanConverter}}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Label Text="{local:Translate NoNoteText}" FontSize="Default" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" />
</StackLayout>
</Grid>
</pages:CustomPage.Content>
If I remove the SelectedItem="{Binding PublicPrivate}" this line of code it is not throwing any issue but if I add the above line the I am getting the above issue.
XamarinPickerViewModel.cs
string _publicPrivate;
public string PublicPrivate
{
get { return _publicPrivate; }
set { _publicPrivate = value;OnPropertyChanged(); }
}
public override void OnAppearing()
{
base.OnAppearing();
BindPickerData();
}
public void BindPickerData()
{
PublicPrivate = "public";
}
When I tap on the button it is throwing System.ArgumentNullException: 'Value cannot be null. Parameter name: element' this issue and it redirected me to
CustomTabbedPageRendere.cs
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
}
to this
please help me
thanks in advance!!!
Some different requirement i'm using nested ListView in XAMRIN form. It's working perfect in IOS. But in Android it's crashing when scrolling the ListView item then giving the following exception as:
Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAdapter from native handle 0x7fd2839b14 (key_handle 0x4219316).
No constructor found for Xamarin.Forms.Platform.Android.ListViewAdapter::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership
Exception of type 'Java.Interop.JavaLocationException' was thrown.
XAML Code:
<StackLayout>
<ListView
HasUnevenRows="True"
SeparatorVisibility="None"
ItemsSource="{Binding PAContactDetailList,Mode=TwoWay}" HeightRequest="{Binding HeightList}" x:Name="lstRoot">
<!-- <ListView.Behaviors>
<commonClass:AutoSizeBehavior/>
</ListView.Behaviors>-->
<ListView.ItemTemplate>
<DataTemplate>
<customControls:CustomViewCellList>
<StackLayout>
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="10,0,10,0" >
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="1"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackLayout Orientation="Vertical" Spacing="5" Grid.Column="2">
<Label Text="PA Name" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding FullName}" FontSize="17" TextColor="Black"/>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
<Image Source="Phone" Aspect="AspectFit" Grid.Row="1" VerticalOptions="Start" HeightRequest="25"/>
<StackLayout Orientation="Vertical" Grid.Row="1" Spacing="5" Grid.Column="2" >
<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="Handle_Tapped" CommandParameter="{Binding PAMobileNumber}"/>
</StackLayout.GestureRecognizers>
<Label Text="Mobile" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding PAMobileNumber}" FontSize="17" TextColor="Black"/>
</StackLayout>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
<Image Source="Whatsapp" Aspect="AspectFit" VerticalOptions="StartAndExpand" Grid.Row="2" HeightRequest="25"/>
<StackLayout Orientation="Vertical" Spacing="5" Grid.Column="2" Grid.Row="2">
<Label Text="WhatsApp" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding PAWhatsappNumber}" FontSize="17" TextColor="Black"/>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
<customControls:HideScrollListView Grid.ColumnSpan="3" Grid.Row="4"
HasUnevenRows="True"
SeparatorVisibility="None"
ItemsSource="{Binding PAContactDetails}" ItemSelected="Handle_ItemSelected" HeightRequest="{Binding HeightContact}">
<!--<ListView.Behaviors>
<commonClass:AutoSizeBehavior/>
</ListView.Behaviors>-->
<customControls:HideScrollListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid x:Name="rootGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="col1" Width="30"/>
<ColumnDefinition x:Name="col2" Width="5"/>
<ColumnDefinition x:Name="col3" Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Image Source="{Binding PhoneImage}" Aspect="AspectFit" VerticalOptions="Start" HeightRequest="25"/>
<StackLayout Grid.Column="2" Spacing="7" Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >
<Label Text="{Binding ContactType}" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding Phone}" FontSize="17" TextColor="Black"/>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</customControls:HideScrollListView.ItemTemplate>
</customControls:HideScrollListView>
<Image Source="Email" Aspect="AspectFit" VerticalOptions="StartAndExpand" Grid.Row="6" HeightRequest="25"/>
<StackLayout Orientation="Vertical" Spacing="5" Grid.Column="2" Grid.Row="6">
<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="Handle_Tapped" CommandParameter="{Binding PAPrimaryEmail}"/>
</StackLayout.GestureRecognizers>
<Label Text="Email" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding PAPrimaryEmail,Mode=TwoWay}" FontSize="17" TextColor="Black"/>
</StackLayout>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
<Image Source="Phone" Aspect="AspectFit" Grid.Row="3" VerticalOptions="Start" HeightRequest="25"/>
<StackLayout Orientation="Vertical" Spacing="5" Grid.Column="2" Grid.Row="3" >
<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="Handle_Tapped" CommandParameter="{Binding PAWorkNumber}"/>
</StackLayout.GestureRecognizers>
<Label Text="Work" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding PAWorkNumber}" FontSize="17" TextColor="Black"/>
</StackLayout>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
<StackLayout Orientation="Vertical" Spacing="5" Grid.ColumnSpan="3" Grid.Row="8">
<customControls:HideScrollListView
HasUnevenRows="True"
SeparatorVisibility="None"
ItemsSource="{Binding ContactEmailList}" ItemSelected="Handle_ItemSelected" HeightRequest="{Binding HeightEmail}">
<customControls:HideScrollListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid x:Name="rootGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="col1" Width="30"/>
<ColumnDefinition x:Name="col2" Width="5"/>
<ColumnDefinition x:Name="col3" Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Image Source="Email" Aspect="AspectFit" VerticalOptions="Start" HeightRequest="25"/>
<StackLayout Grid.Column="2" Spacing="7" Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >
<Label Text="{Binding EmailType}" FontSize="17" TextColor="#A0A4A3"/>
<Label Text="{Binding Email}" FontSize="17" TextColor="Black"/>
<BoxView BackgroundColor="#979797" HeightRequest=".5" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</customControls:HideScrollListView.ItemTemplate>
</customControls:HideScrollListView>
</StackLayout>
<BoxView HeightRequest="1" BackgroundColor="Black" IsVisible="false" Grid.Row="9" Grid.ColumnSpan="3" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</Grid>
</StackLayout>
</customControls:CustomViewCellList>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
ListView Custom Renderer Code:
public class HideScrollListViewRender:ListViewRenderer
{
Context _context;
public HideScrollListViewRender(Context context):base(context)
{
_context = context;
}
protected override void OnDetachedFromWindow()
{
if (Element == null)
return;
base.OnDetachedFromWindow();
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
{
base.OnElementChanged(e);
}
CellView Custom Renderer Code:
public class CustomAllViewCellRenderer:ViewCellRenderer
{
public override UIKit.UITableViewCell GetCell(Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
if (cell != null)
cell.SelectionStyle = UIKit.UITableViewCellSelectionStyle.None;
return cell;
}
}
The exceptions is only in xamarin form Android. What's wrong with the code?
Nested ListViews are highly discouraged and do not even work on Android. You should probably rethink your UI and change it.
Have you considered using Grouping in your listview?
You can read about it in here