How to set form Background as transparency in portable cross platform xamarin form?
Asked Answered
P

3

14

I am using Portable xamarin cross platform. I have two project android and IOS.

I have to make form as transparent form. I have written code for same and this code perfectly working in android but not in IOS

Below is my code:

  <ContentPage BackgroundColor="#00000000">

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="180"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="200"></RowDefinition>
            </Grid.RowDefinitions>

            <StackLayout Grid.Row="0" VerticalOptions="StartAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#80000000" HeightRequest="175" >

            </StackLayout>

            <BoxView HeightRequest="200" Grid.Row="1"></BoxView>

            <StackLayout VerticalOptions="End" HorizontalOptions="FillAndExpand"  BackgroundColor="#80000000" HeightRequest="160"  Grid.Row="2" >
                <Label Text="05:00" FontSize="60" FontAttributes="Bold" TextColor="White" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" ></Label>
            </StackLayout>
        </Grid>  

   </ContentPage>

Below is android Screen shot:

enter image description here

Below is IOS ScreenShot :

enter image description here

Please suggest me what to do to have transparency form in both platform

Thanks in advance

Penury answered 21/9, 2016 at 10:36 Comment(0)
S
16

Even simpler solution would be to just change the hex values of the alpha channel.

FBC1BC is a solid color but #00FBC1BC is a transparent, due to 00 which set the alpha of the color to 0 or transparent.

So just do this #FBC1BC > #50FBC1BC

And you will get a transparent background color with alpha defined by the first two values!

Sclerodermatous answered 22/10, 2019 at 16:43 Comment(0)
E
9

Just include opacity property to your stacklayout :

<StackLayout VerticalOptions="End" HorizontalOptions="FillAndExpand"  BackgroundColor="#80000000" Opacity="0.5" HeightRequest="160"  Grid.Row="2" >
  <Label Text="05:00" FontSize="60" FontAttributes="Bold" TextColor="White" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" ></Label>
</StackLayout>
Eroto answered 21/9, 2016 at 11:12 Comment(2)
By using Opacity, stacklayout become transparent. I dont want to transparent stacklayout. I Need to set Content Page/Form Background color to transparent.Penury
Yes, right, there is a lot of difference between opacity on stacklayout and opacity in background color.Fixity
L
4

SIMPLE AS THIS

BackgroundColor = Color.Transparent

OR in xaml

 `<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="XXX.Core.Views.Pages.XXXX.XXXX"
         xmlns:local="clr-namespace:XXX.Core.Views.CustomControls"    
         BackgroundColor="Transparent">`
Linguist answered 10/11, 2017 at 12:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.