I'm using CollectionView with DataTemplate
<DataTemplate x:Key="tileTemplate">
<StackLayout VerticalOptions="FillAndExpand" BackgroundColor="Red" Padding="5" x:Name="ItemContainer">
<StackLayout Padding="5" HorizontalOptions="CenterAndExpand" WidthRequest="{Binding Width, Source={x:Reference ItemContainer}}" HeightRequest="{Binding Width, Source={x:Reference ItemContainer}}">
<Image Source="{Binding LogoID}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFit" />
</StackLayout>
</StackLayout>
</DataTemplate>
<CollectionView x:Name="ItemsCollectionView" ItemsSource="{Binding Items}" ItemTemplate="{StaticResource itemsDataTemplateSelector}">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"/>
</CollectionView.ItemsLayout>
</CollectionView>
On Android they align vertically from the top:
But on IOS they align rather chaotically:
I can't figure out how to align them from the top like in Android.
--== UPDATE ==-- :
The problem is with HeightRequest of inner StackLayout
HeightRequest="{Binding Width, Source={x:Reference ItemContainer}}"
(same result if you use OnSizeAllocated)
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
HeightRequest = Width;
}
How to keep proportions and prevent tiles from popping on IOS is still opened question.
It may caused by the layout in your stacklayout, I wrote a sample and it works well in iOS:
<CollectionView >
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" Span="3"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Baboon</x:String>
<x:String>Capuchin Monkey Capuchin MonkeyCapuchin MonkeyCapuchin MonkeyCapuchin MonkeyCapuchin MonkeyCapuchin MonkeyCapuchin Monkey</x:String>
<x:String>Blue Monkey</x:String>
</x:Array>
</CollectionView.ItemsSource>
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout VerticalOptions="FillAndExpand" BackgroundColor="Red">
<Frame BackgroundColor="Green" WidthRequest="100" HeightRequest="90">
<Image Source="Images.png"/>
</Frame>
<Label Text="{Binding .}" HorizontalTextAlignment="Center"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Try using StartAndExpand instead of FillAndExpand on the StackLayouts VerticalOptions
Related
I am trying to create a UI like the image below.
As you can see, it works fine on Android, but when I run this on iOS, it shows a gray rectangle.
How can I make this gray rectangle transparent?
Here is the actual code.
<CollectionView SelectionMode="Single"
HeightRequest="50"
WidthRequest="250"
ItemsLayout="HorizontalList"
BackgroundColor="White">
<CollectionView.ItemTemplate>
<DataTemplate>
<Border StrokeThickness="0"
WidthRequest="50"
HeightRequest="50"
StrokeShape="RoundRectangle 25">
<Border StrokeThickness="0" BackgroundColor="Transparent">
<Label Text="{Binding}" HorizontalOptions="Center" VerticalOptions="Center"/>
</Border>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal"/>
<VisualState Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="yellow"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>1</x:String>
<x:String>2</x:String>
<x:String>3</x:String>
<x:String>4</x:String>
<x:String>5</x:String>
</x:Array>
</CollectionView.ItemsSource>
</CollectionView>
Quick question:
Is the TableView in Xamarin.Forms supposed to be all grey like below picture? I was expecting a layout similar to what I'm getting, but with white backgrounds for individual TableSections.
Is this because of iOS 14, something I'm doing wrong or maybe the simulator? I'm also experiencing lack of DatePicker and TimePicker support - works on android but not on iPhone simulator, and I was told this issue was the simulator.
I haven't been able to test it on a real device.
I'm posting my code for the Tableview XAML below.
XAML code
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
Title="{Binding FullName}"
xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="ContactBook.ContactsDetailPage">
<TableView Intent="Form">
<TableRoot>
<TableSection Title="Personal Info">
<EntryCell Label="First Name" Text="{Binding FirstName}" Keyboard="Text" />
<EntryCell Label ="Last Name" Text="{Binding LastName}" Keyboard="Text"/>
</TableSection>
<TableSection Title="Contact Info">
<EntryCell Label="Phone" Text="{Binding Phone}" Keyboard="Telephone"/>
<EntryCell Label="Email" Text="{Binding Email}" Keyboard="Email" />
</TableSection>
<TableSection Title="Other">
<SwitchCell Text="Blocked" On="{Binding IsBlocked}" />
</TableSection>
<TableSection>
<ViewCell>
<Button Text="Save" HorizontalOptions="FillAndExpand" Clicked="Button_Clicked"/>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
</ContentPage>
You could use ViewCell and StackLayout to achieve that, becuause xxxCell not contain a BackgroundColor pproperty.
For example, code as follows:
<TableSection Title="Contact Info">
<ViewCell>
<StackLayout Orientation="Horizontal" BackgroundColor="White">
<Label Margin="10,0,0,0" Text="Phone" VerticalOptions="Center"/>
<Entry Text="Binding Phone" HorizontalOptions="FillAndExpand" Keyboard="Telephone"/>
</StackLayout>
</ViewCell>
<ViewCell>
<StackLayout Orientation="Horizontal" BackgroundColor="White">
<Label Margin="10,0,0,0" Text="Email" VerticalOptions="Center" />
<Entry Text="Binding Email" HorizontalOptions="FillAndExpand" Keyboard="Email" />
</StackLayout>
</ViewCell>
</TableSection>
<TableSection Title="Other" >
<ViewCell>
<StackLayout Orientation="Horizontal" BackgroundColor="White">
<Label Margin="15,0,0,0" Text="Blocked" VerticalOptions="Center"/>
<Switch Margin="280,0,0,0" />
</StackLayout>
</ViewCell>
</TableSection>
<TableSection>
<ViewCell>
<StackLayout BackgroundColor="White">
<Button Text="Save"
HorizontalOptions="FillAndExpand"
/>
</StackLayout>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
The effect:
TableView has a BackgroundColor property that lets you set the background color you want. So if you want it to match the rest of your page, you can do
<TableView Intent="Form" BackgroundColor="White">
I have a MapView in my custom ViewRenderer. I am trying to set it's size like this:
public CustomMapRenderer()
{
var camera = CameraPosition.FromCamera(47.497913, 19.040236, 15);
mapView = new MapView(new CGRect(0, 0, 414, 200), camera); //also tried with this: mapView = MapView.FromCamera(new CGRect(0, 0, 414, 200), camera);
this.AddSubview(mapView);
...
}
The view seems to remain in fullscreen though (414*896), if I check it in the debugger though. Since I found not much documentation, I am asking wheter I am setting it correctly? If so, is that a bug? How should I change the size of the view?
EDIT: Added the relevant XAML code too
The XAML where the Map is embedded in is:
<?xml version="1.0" encoding="UTF-8"?>
<attractionbase:AttractionContentListItemBase 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"
xmlns:attractionbase="clr-namespace:AppTourism.CardView.ItemTypes.AttractionPage"
xmlns:map="clr-namespace:AppTourism.MapModule"
mc:Ignorable="d"
x:Class="AppTourism.CardView.ItemTypes.AttractionPage.AddressWithMapContentListItem">
<Frame
HasShadow="False"
Padding="0"
Margin="{Binding MainFrameMargin}"
RelativeLayout.XConstraint="{ConstraintExpression Type=Constant,Property=X,Constant=0}"
RelativeLayout.YConstraint="{ConstraintExpression Type=Constant,Property=Y,Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width}">
<StackLayout Orientation="Vertical" Spacing="0" Margin="0" >
<StackLayout Orientation="Vertical" Margin="10" >
<StackLayout Orientation="Horizontal">
<Image Source="iMarkerSmall.png" HeightRequest="30"></Image>
<Label Text="{Binding Pin.Address}" FontSize="Medium" TextColor="Black"></Label>
</StackLayout>
<Frame Padding="0" HeightRequest="100" CornerRadius="20" HasShadow="False">
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="Map_Tapped"></TapGestureRecognizer>
</Frame.GestureRecognizers>
<AbsoluteLayout>
<map:CustomMap x:Name="Map" IsEnabled="False"
AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" />
<Label Text="N/A" FontSize="Medium" FontAttributes="Bold" TextColor="Black" Margin="5,0" VerticalOptions="Center" x:Name="NALabel" IsVisible="False"
AbsoluteLayout.LayoutBounds="0.5,0.5,AutoSize,AutoSize" AbsoluteLayout.LayoutFlags="PositionProportional" ></Label>
</AbsoluteLayout>
</Frame>
</StackLayout>
<BoxView HeightRequest="{Binding SEPARATOR_HEIGHT}" Margin="{Binding SeparatorMargin}">
<BoxView.BackgroundColor>
<Color>#e6e6e6</Color>
</BoxView.BackgroundColor>
</BoxView>
</StackLayout>
</Frame>
</attractionbase:AttractionContentListItemBase>
I am facing trouble to implement "Soft Keyboard Input Mode" and fix keyboard overlap issue in Xamarin.Forms iOS app.
The following solutions that I have tried:
Scroll View: Which is not work for me because I am already using one scroll view in my content page so nested scroll view will not work as defined in following article https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scroll-view.
Xamarin.IQKeyboardManager: Which is solve the overlap issue but hides the top content by taking it up which I am not be able to scroll down.
I have also tried following articles
https://xamgirl.com/adjusting-elements-when-keyboard-shows-in-xamarin-forms/
https://github.com/adamped/SoftInput/blob/master/SoftInput/SoftInput.iOS/Render/KeyboardRender.cs
Also facing another issue without "Soft Keyboard Input Mode" getting blank white space sometime top and bottom while focusing to Entry control that trigger keyboard up and down on multiple clicks.
The following page layout designs I am using in my two pages (Facing issue in 2 pages which has I am already using scroll view)
Page 1:
`<ContentPage.Content>
<StackLayout >
<ScrollView Margin="10,10,10,0">
<StackLayout x:Name="pageContentLayout">
</StackLayout>
</ScrollView>
<AbsoluteLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<StackLayout x:Name="mainEntryLayout"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1">
<ActivityIndicator x:Name="entryIndicator"
IsVisible="False"
IsRunning="False">
</ActivityIndicator>
<Grid VerticalOptions="EndAndExpand"
HorizontalOptions="EndAndExpand"
x:Name="entryGrid"
BackgroundColor ="{StaticResource Color}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="85*"/>
<ColumnDefinition Width="15*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<custom:CustomEntry CornerRadius="4"
IsCurvedCornersEnabled="True"
BorderColor="{StaticResource Color}"
PlaceholderColor="{StaticResource Color}"
TextColor="{StaticResource Color}"
VerticalOptions="FillAndExpand"
HeightRequest="100"
HorizontalOptions="FillAndExpand"
Grid.Column="0"
FontSize="12"
BackgroundColor ="{StaticResource Color}"
x:Name="commentCustomEntry"
Keyboard="Chat"
Margin="10"/>
<ImageButton VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
Grid.Column="1"
HeightRequest="30"
WidthRequest="30"
x:Name="SendBtn"
BackgroundColor="Transparent"/>
</Grid>
</StackLayout>
<StackLayout x:Name="pageIndicatorLayout"
IsVisible="false"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1">
<Label x:Name="loadingLabel" TextColor="{StaticResource Color}"/>
<ActivityIndicator IsRunning="true"
Color ="{DynamicResource Color}"/>
</StackLayout>
</AbsoluteLayout>
</StackLayout>
</ContentPage.Content>
`
Page 2:
`
<StackLayout>
<AbsoluteLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<StackLayout x:Name="pageContentLayout"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1">
<StackLayout x:Name="ImgLayout" ></StackLayout>
<ScrollView>
<StackLayout>
<StackLayout Orientation="Vertical"
HorizontalOptions="FillAndExpand">
<Label Text="{Binding titleLable}"
FontAttributes="Bold"
TextColor="{StaticResource Color}"
Margin="10, 0, 0, 0"
FontSize="14"/>
<Label x:Name="resourceLabel"
TextColor="{StaticResource Color}"
FontSize="11"
Margin="10, 0, 0, 0" />
<Label Text="{Binding sourceLabel}"
TextColor="{StaticResource Color}"
FontSize="11"
FontAttributes="Bold"
Margin="10, 0, 0, 0" />
<Label x:Name="personLabel"
TextColor="{StaticResource Color}"
FontSize="11"
Margin="10, 0, 0, 0" />
<Label FontAttributes="Bold, Italic"
FontSize="12"
Padding="10,10,10,0"
Text="{Binding hightlightLabel}"/>
</StackLayout>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<local:ExtendedWebViewModel x:Name="webContentView"
Grid.Row="0"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"/>
</Grid>
</StackLayout>
</ScrollView>
<Grid Padding="10,0,10,0" RowSpacing="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60*"/>
<ColumnDefinition Width="40*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackLayout Grid.Column="1"
Grid.Row="0"
Grid.RowSpan="2"
Orientation="Horizontal"
HorizontalOptions="EndAndExpand"
VerticalOptions="CenterAndExpand">
<Image Source="{Binding lImg, Converter={StaticResource Converter}}"
HeightRequest="20"
WidthRequest="20">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnLImgTapped"
CommandParameter="{Binding item}"/>
</Image.GestureRecognizers>
</Image>
<Label x:Name="tCount"
VerticalOptions="CenterAndExpand"
Text="{Binding tCount}"
FontSize="12">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="OntCountTapped"
CommandParameter="{Binding item}"/>
</Label.GestureRecognizers>
</Label>
<Image Source="{Binding cImg, Converter={StaticResource Converter}}"
HeightRequest="20"
WidthRequest="20">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnCImgTapped"
CommandParameter="{Binding item}"/>
</Image.GestureRecognizers>
</Image>
<Label Text="{Binding cCount}"
VerticalOptions="CenterAndExpand"
FontSize="12">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="OnCCountTapped"
CommandParameter="{Binding item}"/>
</Label.GestureRecognizers>
</Label>
<Image Source="{Binding SImg, Converter={StaticResource Converter}}"
HeightRequest="20"
WidthRequest="20">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSImgTapped"
CommandParameter="{Binding item}"/>
</Image.GestureRecognizers>
</Image>
</StackLayout>
</Grid>
<Grid VerticalOptions="EndAndExpand"
HorizontalOptions="EndAndExpand"
x:Name="entryGrid"
BackgroundColor ="{StaticResource Color}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="85*"/>
<ColumnDefinition Width="15*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<custom:CustomEntry CornerRadius="4"
IsCurvedCornersEnabled="True"
BorderColor="{StaticResource Color}"
PlaceholderColor="{StaticResource Color}"
TextColor="{StaticResource CommentEntryValueColor}"
VerticalOptions="FillAndExpand"
HeightRequest="100"
HorizontalOptions="FillAndExpand"
Grid.Column="0"
FontSize="12"
BackgroundColor ="Color"
x:Name="commentCustomEntry"
Keyboard="Chat"
Margin="10"/>
<ImageButton VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"Grid.Column="1"
HeightRequest="30"
WidthRequest="30"
Clicked="OnSendButtonClicked"
x:Name="SendBtn"
BackgroundColor="Transparent"/>
</Grid>
</StackLayout>
<StackLayout x:Name="pageIndicatorLayout"
IsVisible="false"
Padding="12"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1">
<Label x:Name="loadingLabel" TextColor="{StaticResource Color}"/>
<ActivityIndicator IsRunning="true"
Color ="{DynamicResource Color}"/>
</StackLayout>
</AbsoluteLayout>
</StackLayout>
`
Could you please suggest the better solution?
Thanks
If you are targeting ios only, Remove the scrollview and try this plugin. https://github.com/paulpatarinski/Xamarin.Forms.Plugins/tree/master/KeyboardOverlap
After installing this nuget ,
Add these line in your Appdelegate class after Xamarin.Forms.Init().
KeyboardOverlapRenderer.Init ();
No need for you to do anything other then initialize the plugin. The keyboard will no longer overlap your Controls!!!
First I'd like to mention that I'm no professional at Xamarin.
The problem I'm currently facing occured after using a custom renderer to achieve a transparent master detail page on my xamarin.ios project, after achieving this, I noticed that I now have a grey border on the outside of my master detail page, I tried accessing it throught a couple properties, but none seem to work.
Here's the customer renderer code
public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
var master = ViewControllers[0];
master.View.BackgroundColor = UIColor.Clear;
var detail = ViewController.ChildViewControllers[1];
}
Here's my xaml code used for the design of the side menu:
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage
x:Class="LoyaltyWorx.SideMenu"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
xmlns:fftransformations="clr-namespace:FFImageLoading.Transformations;assembly=FFImageLoading.Transformations"
xmlns:local="clr-namespace:LoyaltyWorx.MarkupExtensions; assembly=LoyalyWorx"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<MasterDetailPage.Master>
<ContentPage Title="Menu" BackgroundColor="Transparent">
<StackLayout Orientation="Vertical" BackgroundColor="Transparent" Spacing="0">
<StackLayout
HorizontalOptions="Fill"
Orientation="Horizontal"
VerticalOptions="Fill" BackgroundColor="Black" Padding="50, 50, 50, 50" >
<StackLayout HorizontalOptions="Center" Orientation="Vertical">
<ffimageloading:CachedImage x:Name="ProfilePictureCircleImage"
LoadingPlaceholder="profile_image_placeholder.png"
ErrorPlaceholder="profile_image_placeholder.png"
DownsampleToViewSize="true"
FadeAnimationEnabled="true"
HeightRequest="65"
WidthRequest="65">
<ffimageloading:CachedImage.Transformations>
<fftransformations:CircleTransformation/>
</ffimageloading:CachedImage.Transformations>
</ffimageloading:CachedImage>
</StackLayout>
<StackLayout
HorizontalOptions="CenterAndExpand"
Orientation="Vertical"
VerticalOptions="CenterAndExpand">
<Label
x:Name="FullNameLabel"
FontSize="18"
HorizontalOptions="Center"
TextColor="White"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</StackLayout>
<BoxView HeightRequest="2" BackgroundColor="#D90B31"/>
<ListView
x:Name="NavigationMenuItems"
ItemSelected="OnMenuItemSelected"
BackgroundColor="{StaticResource TileColour}"
RowHeight="60"
SeparatorVisibility="None"
SeparatorColor="Transparent"
Margin="0">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<!-- Main design for menu items -->
<StackLayout
Padding="20,10,0,10"
Orientation="Horizontal"
Spacing="20"
VerticalOptions="FillAndExpand"
BackgroundColor="Transparent">
<local:TintedCachedImage TintColor="{StaticResource SideMenuIconColor}"
Source="{Binding Icon}"
VerticalOptions="Center"
DownsampleToViewSize="true"
HeightRequest="19"
WidthRequest="19"/>
<Label
FontSize="15"
Text="{Binding Title}"
TextColor="{StaticResource SideMenuTextColor}"
VerticalOptions="Center" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage />
</MasterDetailPage.Detail>
</MasterDetailPage>
Please assist.