Frame corner radius not rounding corners on iOS - xaml

I am trying to round the corners of a stack layout, it works on android but on iOS, they still appear square but it does display the Frame shadow
My XAML is
<ContentPage.Content>
<StackLayout BackgroundColor="WHITE">
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Frame CornerRadius="10" Padding="0" Margin="10, 10, 10, 10">
<StackLayout>
. . .
</StackLayout>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>

Set IsClippedToBounds property to Frame control:
<Frame IsClippedToBounds="True" CornerRadius="10" Padding="0" Margin="10, 10, 10, 10">
<StackLayout>
</StackLayout>
</Frame>

they still appear square
Actually, the Frame is round not the StackLayout, we just use Frame wrap it ,so it looks the StackLayout has round corners.
Frame
<Frame CornerRadius="10" Padding="0" Margin="10, 10, 10, 10" HasShadow="False" BackgroundColor="Red">
<StackLayout >
<Label Text="{Binding}"/>
</StackLayout>
</Frame>
StackLayout
<Frame CornerRadius="10" Padding="0" Margin="10, 10, 10, 10" HasShadow="False" >
<StackLayout BackgroundColor="Red">
<Label Text="{Binding}"/>
</StackLayout>
</Frame>
it does display the Frame shadow
You can disable it by HasShadow="False".

Actually I believe, it is a bug of Xamarin.Forms. UWP, Android and iOS should behave the same, but they don't. As a result to implement the same behaviour developers need to use OnPlatform feature.
The bug is described and discussed here, it is still open: https://github.com/xamarin/Xamarin.Forms/issues/2405

Related

Using OnIdiom with AbsoluteLayout

I have circular buttons and am trying to change the size of them depending on if they are on phone or tablet using AbsolutLayout.
Here is my xaml:
<Frame BackgroundColor="{StaticResource ThemeColor}" Padding="0" CornerRadius="40" AbsoluteLayout.LayoutBounds="{StaticResource HomeCircle}" AbsoluteLayout.LayoutFlags="PositionProportional">
<Label Text="" HorizontalOptions="Center" VerticalOptions="Center" Style="{StaticResource Icon}" TextColor="{StaticResource LabelColor}"/>
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="Directions"/>
</Frame.GestureRecognizers>
</Frame>
<AbsoluteLayout.Resources>
<ResourceDictionary>
<OnIdiom x:Key="HomeCircle" x:TypeArguments="Frame" Phone=".85,.375, 80, 80"
Tablet=".85,.375, 120, 120"/>
</ResourceDictionary>
</AbsoluteLayout.Resources>
I looked at this resource and it did not work:
How to use attached properties such as Grid.Row, AbsoluteLayout.LayoutFlags to OnPlatform tag in Xamarin Forms
Edit: Have tried TypeArguments of Rectangle, AbsoluteLayout, and Frame and they all give this error:
Error XFC0009 No property, BindableProperty, or event found for "Phone", or mismatching type between value and property.
Edit: Have also looked at this thread and it provides the same error:
https://xamarin.github.io/bugzilla-archives/55/55183/bug.html
I faced the same problem in the past. My solution is to set the AbsoluteLayout bounds by Binding in place of StaticResource.
In the ViewModel:
public Xamarin.Forms.Rectangle HomeCircle => Xamarin.Forms.Device.Idiom == TargetIdiom.Phone ? new Xamarin.Forms.Rectangle(0.5f, 0.5f, 80, 80) : new Xamarin.Forms.Rectangle(0.5f, 0.5f, 120, 120);
In the yaml:
<AbsoluteLayout>
<Frame BackgroundColor="Gray"
Padding="0"
CornerRadius="40"
AbsoluteLayout.LayoutBounds="{Binding HomeCircle}"
AbsoluteLayout.LayoutFlags="PositionProportional">
<Label Text="TEST"
HorizontalOptions="Center"
VerticalOptions="Center"
TextColor="Black"/>
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding DoSomething}"/>
</Frame.GestureRecognizers>
</Frame>
</AbsoluteLayout>
Anyway AbsoluteLayout.LayoutBounds requires Rectangle, and markup doesn't always allow everything :)

Xamarin Style IndicatorView to look like TabbedPage

I have a problem. I recently had this problem: Xamarin forms Add button in TabbedPage, but that is fixed using the accepted anwser. In short, I am using a CarouselView and an IndicatorView, so I can have an overlay over multiple screens. Both the views replace my TabbedPage, but the IndicatorView needs to look like the TabbedPageBar. The only good page about styling an IndicatorView was this one: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/indicatorview.
Here is the page I have:
<StackLayout AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
Padding="0"
Spacing="0">
<IndicatorView x:Name="indicatorView">
<IndicatorView.IndicatorTemplate>
<DataTemplate>
<StackLayout HorizontalOptions="FillAndExpand">
<Frame Margin="10">
<Label/>
</Frame>
</StackLayout>
</DataTemplate>
</IndicatorView.IndicatorTemplate>
</IndicatorView>
<CarouselView ItemTemplate="{StaticResource templateSelector}"
IndicatorView="indicatorView">
<CarouselView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>1</x:String>
<x:String>2</x:String>
<x:String>3</x:String>
</x:Array>
</CarouselView.ItemsSource>
</CarouselView>
</StackLayout>
Now how can I let the IndicatorView look like a TabbedPageBar?
I think the key point here is remove the Shadow and CornerRadius of Frame, then you can customize the layout in the Frame. Here is an example:
<IndicatorView x:Name="indicatorView" >
<IndicatorView.IndicatorTemplate>
<DataTemplate>
<StackLayout HorizontalOptions="FillAndExpand" Spacing="0">
<Frame HasShadow="False" CornerRadius="0">
<StackLayout Orientation="Vertical">
<Image Source="Images"/>
<Label Text="123" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</Frame>
</StackLayout>
</DataTemplate>
</IndicatorView.IndicatorTemplate>
</IndicatorView>

CollectionView header

Xamarin.Forms version 4.2.0.848062
- iOS: iPhone 8 iOS 13.1
- Android: 9.0
In iOS => CollectionView.Header doesnt work. image => https://ibb.co/30yw2ZY
In Android works fine. image => https://ibb.co/DLQxr74
Example>>
<CollectionView ItemsSource="{Binding AllNotes}" >
<CollectionView.Header>
<Grid>
<Frame OutlineColor="Black"
HasShadow="True"
CornerRadius="20"
Margin="20,40"
HorizontalOptions="Center">
<Label Text="Ahorrado* este mes"/>
</Frame>
</Grid>
</CollectionView.Header>
<CollectionView.ItemTemplate>
<DataTemplate>
<ContentView>
<Frame Margin="10,6" BackgroundColor="Gray" CornerRadius="20">
<Label Text="test" FontSize="Title"/>
</Frame>
</ContentView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
It seems a design issue in Xamarin.Forms for iOS . You should set the CollectionView.Footer at same time . You can set the content as empty if you don't want it to show anything.
<CollectionView.Footer>
<Grid>
</Grid>
</CollectionView.Footer>

Button escapes stacklayout on lower resolution

Here is a screenshot of the problem (Left= Xamarin.Forms previewer; Right= ADV 768x1080)
Code:
<Frame BackgroundColor="#292929" VerticalOptions="CenterAndExpand" Margin="20,0,20,0" CornerRadius="4" Padding="0">
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="5">
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Tomato">
<Label FontSize="Small" Text="ABBONAMENTO 30 giorni" TextColor="White"/>
<Label FontSize="Small" Text="€10,99" HorizontalOptions="EndAndExpand" TextColor="#ff9900"/>
</StackLayout>
<Button HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Text="ISCRIVITI" TextColor="#eeeeee" BackgroundColor="#FF9900" CornerRadius="4"/>
</StackLayout>
</Frame>
The frames are put in a StackLayout, which parent is a Grid.
The problem persists on low resolution devices only.
Can you tell me why is this happening, and how to fix it?
I need this layout to be height-aware and responsive.

Xamarin Forms ActivityIndicator over ListView

My ActivityIndicator is at the bottom of the Page, but it should be in the middle. I tried everything I found in the internet but nothing worked.
Image
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<SearchBar Placeholder="Parkhaus suchen" Text="{Binding SearchText}"/>
<ListView x:Name="HomeListView" ItemsSource="{Binding Parking}" HasUnevenRows="False" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
...
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer/>
</ListView>
</StackLayout>
<StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<ActivityIndicator IsRunning="{Binding IsBusy}" IsVisible="{Binding IsBusy}" VerticalOptions="Center" HorizontalOptions="Center"/>
</StackLayout>
</AbsoluteLayout>
Try changing your StackLayout around your ActivityIndicator to use:
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1"
The PositionPropertional flag tells the AbsoluteLayout that the x and y position of the element is based on the size of the absolute layout, taking the size of the element into account. So 0.5 tells it to center the element within the AbsoluteLayout.
The values for the width and height are both set to -1. This is considered a "special value" for width and height meaning "Auto".