Reputation: 3303
My app is really simple: it displays a Xamarin.Forms.Map
in the top half and a ListView
on the bottom half.
This is my 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:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
xmlns:local="clr-namespace:GasStations"
x:Class="GasStations.MainPage">
<StackLayout>
<StackLayout VerticalOptions="FillAndExpand">
<maps:Map WidthRequest="960" HeightRequest="200"
x:Name="MyMap"
IsShowingUser="true"/>
<ListView x:Name="ListView_Pets">
</ListView>
</StackLayout>
</StackLayout>
</ContentPage>
This is app in the emulator:
I would like to hide the ListView
when I click on the map, and at the bottom something that says "Show List". More or less something like this:
I added an event handler like so in class MainPage
(similar to trouble in Hide/show of listview on a click in xamarin android), but it doesn't build:
public MainPage()
{
InitializeComponent();
/* Fills ListView and plots points in map */
ListView_Pets.ItemClick += OnListItemClick;
}
Upvotes: 0
Views: 947
Reputation: 8174
Instead of using <StackLayout>
I would propose to use <Grid>
to achieve this kind of Layout:
Xaml Code:
<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="50" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<StackLayout Grid.Row="0">
<maps:Map WidthRequest="960" HeightRequest="200"
x:Name="MyMap" IsShowingUser="true"/>
</StackLayout>
<StackLayout Grid.Row="1">
<Label Text="Show List" TextColor="LightGray">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapGestureRecognizerTapped"/>
</Label.GestureRecognizers>
</Label>
</StackLayout>
<StackLayout Grid.Row="2" x:Name="listSection" IsVisible="false" HeightRequest="200">
<ListView x:Name="ListView_Pets"/>
</StackLayout>
</Grid>
Code Behind:
private bool isListVisible;
void OnTapGestureRecognizerTapped(object sender, EventArgs args)
{
isListVisible = !isListVisible;
listSection.IsVisible = !isListVisible;
}
You can update the show hide logic using binding, if you are using MVVM Framework.
Upvotes: 2
Reputation: 96
Following steps as follows:
Upvotes: 0