I'm trying to horizontally center a StackLayout within a ScrollView. However, the StackLayout isn't horizontally centered (it's left aligned). I tried centering the ScrollView but then the whole view is not scrollable - only the center section is.
<ScrollView BackgroundColor="Teal">
<StackLayout Spacing="5"
Padding="30"
WidthRequest="400"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
BackgroundColor="Transparent">
<Label Text="Test"/>
<Label Text="Test"/>
<Label Text="Test"/>
<Label Text="Test"/>
</StackLayout>
</ScrollView>
The centering works with 2 nested StackLayout elements, but it doesn't with the ScrollView. Any ideas?
You have a couple of options, and each Label in the example below should show up centered.
The key thing is that the StackLayout bases its layout on its contents. You'd think that you could center the whole StackLayout the way you did, but at least as the content of a ScrollView, it doesn't work that way. But centering the children of that StackLayout will center within the ScrollView:
<ScrollView BackgroundColor="Teal">
<StackLayout Spacing="5"
Padding="30"
WidthRequest="400"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
BackgroundColor="Transparent">
<Label Text="Test" HorizontalOptions="Center"/>
<StackLayout HorizontalOptions="Center">
<Label Text="Test"/>
</StackLayout>
</StackLayout>
</ScrollView>
The HorizontalOptions on the outer StackLayout does not seem to have any impact in this situation, but I would use FillAndExpand as a way to document the intent to fill the entire horizontal space of the ScrollView.
The way that StackLayout works is that it Fills in one axis while splitting the space available in the other axis for all child elements. It does not autosize on the "filled" axis (horizontal in this case), and therefore centering the element on that axis will not produce any results.
However you can achieve the desired layout using a Grid and possibly using other layout models as well.
Using a Grid:
<ScrollView BackgroundColor="Teal">
<Grid HorizontalOptions="Fill" VerticalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="1" Grid.Row="0" Text="Test"/>
<Label Grid.Column="1" Grid.Row="1" Text="Test"/>
<Label Grid.Column="1" Grid.Row="2" Text="Test"/>
<Label Grid.Column="1" Grid.Row="3" Text="Test"/>
<Label Grid.Column="1" Grid.Row="4" Text="Test"/>
<Label Grid.Column="1" Grid.Row="5" Text="Test"/>
<Label Grid.Column="1" Grid.Row="6" Text="Test"/>
<Label Grid.Column="1" Grid.Row="7" Text="Test"/>
<Label Grid.Column="1" Grid.Row="8" Text="Test"/>
<Label Grid.Column="1" Grid.Row="9" Text="Test"/>
<Label Grid.Column="1" Grid.Row="10" Text="Test"/>
<Label Grid.Column="1" Grid.Row="11" Text="Test"/>
<Label Grid.Column="1" Grid.Row="12" Text="Test"/>
<Label Grid.Column="1" Grid.Row="13" Text="Test"/>
<Label Grid.Column="1" Grid.Row="14" Text="Test"/>
<Label Grid.Column="1" Grid.Row="15" Text="Test"/>
<Label Grid.Column="1" Grid.Row="16" Text="Test"/>
<Label Grid.Column="1" Grid.Row="17" Text="Test"/>
<Label Grid.Column="1" Grid.Row="18" Text="Test"/>
<Label Grid.Column="1" Grid.Row="19" Text="Test"/>
<Label Grid.Column="1" Grid.Row="20" Text="Test"/>
<Label Grid.Column="1" Grid.Row="21" Text="Test"/>
<Label Grid.Column="1" Grid.Row="22" Text="Test"/>
<Label Grid.Column="1" Grid.Row="23" Text="Test"/>
<Label Grid.Column="1" Grid.Row="24" Text="Test"/>
<Label Grid.Column="1" Grid.Row="25" Text="Test"/>
<Label Grid.Column="1" Grid.Row="26" Text="Test"/>
<Label Grid.Column="1" Grid.Row="27" Text="Test"/>
<Label Grid.Column="1" Grid.Row="28" Text="Test"/>
<Label Grid.Column="1" Grid.Row="29" Text="Test"/>
<Label Grid.Column="1" Grid.Row="30" Text="Test"/>
<Label Grid.Column="1" Grid.Row="31" Text="Test"/>
<Label Grid.Column="1" Grid.Row="32" Text="Test"/>
<Label Grid.Column="1" Grid.Row="33" Text="Test"/>
<Label Grid.Column="1" Grid.Row="34" Text="Test"/>
<Label Grid.Column="1" Grid.Row="35" Text="Test"/>
<Label Grid.Column="1" Grid.Row="36" Text="Test"/>
<Label Grid.Column="1" Grid.Row="37" Text="Test"/>
<Label Grid.Column="1" Grid.Row="38" Text="Test"/>
<Label Grid.Column="1" Grid.Row="39" Text="Test"/>
</Grid>
</ScrollView>
Related
Title: app_nome -> TWW / SALDO - HOSPITAL... (Example)
Time: dt_cadastro_hora -> 08:56 (Example)
NotificationsPage.xaml
<RefreshView x:DataType="local:NotificacoesViewModel"
Command="{Binding LoadItemsCommand}"
IsRefreshing="{Binding IsBusy, Mode=TwoWay}"
Padding="0,15,0,0">
<CollectionView x:Name="ItemsListView"
ItemsSource="{Binding Notificacoes}"
SelectionMode="None"
ItemsUpdatingScrollMode="KeepItemsInView"
VerticalScrollBarVisibility="Never"
HorizontalScrollBarVisibility="Never"
IsGrouped="True">
<CollectionView.GroupHeaderTemplate>
<DataTemplate x:DataType="model:NotificacaoGrupoData">
<Label Text="{Binding Data_agrupada}"
FontSize="20"
FontAttributes="Bold"
HorizontalTextAlignment="Center"
Padding="0,15,0,15"
Style="{StaticResource LabelDataAgrupadaStyle}"/>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout x:DataType="model:Notificacao">
<StackLayout Orientation="Horizontal">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1"
Command="{Binding Source={RelativeSource AncestorType={x:Type local:NotificacoesViewModel}},
Path=NotificacaoSelecionada}"
CommandParameter="{Binding .}"/>
</StackLayout.GestureRecognizers>
<Image Source="logo"
HeightRequest="40"
Margin="0,0,5,0"
VerticalOptions="CenterAndExpand"/>
<StackLayout VerticalOptions="CenterAndExpand"
Margin="0,0,10,0">
<FlexLayout JustifyContent="SpaceBetween"
AlignItems="Center">
<Label Text="{Binding app_nome}"
Style="{StaticResource LabelStyle}"
FontSize="20"
WidthRequest="230"
LineBreakMode="TailTruncation"
FontAttributes="Bold"/>
<Label Text="{Binding dt_cadastro_hora}"
Style="{StaticResource LabelStyle}"
FontSize="13"
LineBreakMode="NoWrap"
MinimumWidthRequest="50"
FontAttributes="Bold"/>
</FlexLayout>
<Label Text="{Binding mensagem}"
TextType="Html"
LineBreakMode="TailTruncation"
Style="{StaticResource LabelStyle}"/>
</StackLayout>
<Label Text=""
FontFamily="FontAwesomeBold"
TextColor="#ACACAC"
FontSize="24"
HorizontalOptions="EndAndExpand"
VerticalOptions="CenterAndExpand"
Style="{StaticResource LabelStyle}">
</Label>
</StackLayout>
<BoxView HeightRequest="1"
BackgroundColor="#DDDDDD"
Margin="0,5,0,5"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
You can try replace
<FlexLayout JustifyContent="SpaceBetween"
AlignItems="Center">
<Label Text="{Binding app_nome}"
Style="{StaticResource LabelStyle}"
FontSize="20"
WidthRequest="230"
LineBreakMode="TailTruncation"
FontAttributes="Bold"/>
<Label Text="{Binding dt_cadastro_hora}"
Style="{StaticResource LabelStyle}"
FontSize="13"
LineBreakMode="NoWrap"
MinimumWidthRequest="50"
FontAttributes="Bold"/>
</FlexLayout>
By (notice the HorizontalOptions)
<StackLayout Orientation="Horizontal">
<Label Text="{Binding app_nome}"
Style="{StaticResource LabelStyle}"
HorizontalOptions="StartAndExpand"
FontSize="20"
WidthRequest="230"
LineBreakMode="TailTruncation"
FontAttributes="Bold"/>
<Label Text="{Binding dt_cadastro_hora}"
Style="{StaticResource LabelStyle}"
HorizontalOptions="End"
FontSize="13"
LineBreakMode="NoWrap"
MinimumWidthRequest="50"
FontAttributes="Bold"/>
</StackLayout>
I have an Expander in a CollectionView.
I try to select a radio button in every row but everytime I scroll multiple rows displaying the same radio button as selected even though the row is not selected. I am using xamarin forms 5.0.0.1874
here is my code
<CollectionView ItemsSource="{Binding sI_Refill_s}">
<CollectionView.ItemTemplate>
<DataTemplate>
<yummy:PancakeView CornerRadius="10" BackgroundColor="{StaticResource GreenColor}" Padding="10">
<xct:Expander IsExpanded="{Binding IsEnable}">
<xct:Expander.Header>
<Grid RowDefinitions="Auto,Auto" ColumnDefinitions="*,*,*" RowSpacing="10" Padding="05">
<!--ROW1-->
<Label Grid.Row="0" Grid.Column="0" Text="Last" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="1" Text="DOB" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="2" Text="Reason" Style="{StaticResource headerStyle}"/>
<!--ROW2-->
<Label Grid.Row="1" Grid.Column="0" Text="{Binding Last}" Style="{StaticResource ValStyle}"/>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding DOB}" Style="{StaticResource ValStyle}"/>
<Entry Grid.Row="1" Grid.Column="2" Text="{Binding Reason, Mode=TwoWay}" HorizontalOptions="Fill" Style="{StaticResource ValStyle}"/>
</Grid>
</xct:Expander.Header>
<xct:Expander.ContentTemplate>
<DataTemplate>
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="*,*,*,*,*" RowSpacing="10">
<!--ROW3-->
<Label Grid.Row="0" Grid.Column="0" Text="First" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="1" Text="L_DISP_DT" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="2" Text="REM_INJS" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="3" Text="STATUS" Style="{StaticResource headerStyle}"/>
<Label Grid.Row="0" Grid.Column="4" Text="Refill#" Style="{StaticResource headerStyle}"/>
<!--ROW4-->
<Label Grid.Row="1" Grid.Column="0" Text="{Binding First}" Style="{StaticResource ValStyle}"/>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding L_Disp_Dt}" Style="{StaticResource ValStyle}"/>
<Label Grid.Row="1" Grid.Column="2" Text="{Binding Rem_injs}" Style="{StaticResource ValStyle}"/>
<Label Grid.Row="1" Grid.Column="3" Text="{Binding Status}" Style="{StaticResource ValStyle}"/>
<Label Grid.Row="1" Grid.Column="4" Text="{Binding RefillNo}" Style="{StaticResource ValStyle}"/>
<!--ROW5-->
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="5" Text="Decision" Style="{StaticResource headerStyle}"/>
<!--ROW6-->
<StackLayout Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="5"
RadioButtonGroup.GroupName="{Binding groupName}"
RadioButtonGroup.SelectedValue="{Binding SelectedItem}" Orientation="Horizontal" HorizontalOptions="Center">
<RadioButton Content="Approved"
Value="Approved" FontSize="Micro"/>
<RadioButton Content="Hold"
Value="Hold" FontSize="Micro"/>
<RadioButton Content="Reject"
Value="Reject" FontSize="Micro"/>
</StackLayout>
</Grid>
</DataTemplate>
</xct:Expander.ContentTemplate>
</xct:Expander>
</yummy:PancakeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
If you are targeting iOS then it is likely to be XamarinCommunityToolkit bug you can follow it status/progress in:
Expander within CollectionView does not work properly on iOS #608
Expander is not expanding and collapsing properly when load in CollectionView #572
I am using the following xaml in xamrin forms to create an order details page with the list of orders in a sub list-view however I am having a biit of difficulty in aligning the list view items.
<ContentPage.Content>
<ScrollView>
<StackLayout Spacing="2">
<Label Text="Order Number:"></Label>
<Label Text="{Binding Item.SopOrderNumber}"
LineBreakMode="NoWrap"
FontSize="20" />
<Label Text="Phone Number:" FontSize="20" ></Label>
<Label Text="{Binding Item.TelephoneNumber}"/>
<Button Command="{Binding SubmitCommand}" Text="Click To Call" TextColor="White"
FontAttributes="Bold" FontSize="Large" HorizontalOptions="FillAndExpand"
BackgroundColor="#088da5" />
<Label Text="{Binding Item.CustomerName}"
LineBreakMode="NoWrap"
FontSize="20" />
<Label Text="Order Status"
HorizontalOptions="StartAndExpand" />
<Picker x:Name="picker" Title="Order Status">
<Picker.ItemsSource >
<x:Array Type="{x:Type x:String}">
<x:String>Delivered</x:String>
<x:String>Damaged</x:String>
<x:String>Missing</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
<Label Text="Order Details" FontSize="Large"></Label>
<ListView x:Name="DeliveryItemsList" HeightRequest="80" HasUnevenRows="True" >
<ListView.ItemTemplate >
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<StackLayout Orientation="Horizontal" Padding="10" Spacing="15">
<Label Text="{Binding ItemNumber}" FontSize="20" ></Label>
<Label Text="{Binding StockCode}" FontSize="20" TextColor="Gray"></Label>
<Label Text="{Binding StockDescription}" FontSize="20" TextColor="Gray"></Label>
<Label Text="{Binding Price}" TextColor="Gray" FontSize="20" ></Label>
<Label Text="{Binding Qty}" TextColor="Gray" FontSize="20" ></Label>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Label Text="Notes"
HorizontalOptions="StartAndExpand"
/>
<Editor x:Name="txtNotes"
VerticalOptions="FillAndExpand" HeightRequest="20"></Editor>
<Sig:SignaturePadView x:Name="signaturePad" />
<Image x:Name="PhotoSource" ></Image>
<Button Command="{Binding SubmitCommand}" Text="Take Picture of Delivery" x:Name="btnTakePhto" Clicked="BtnTakePhto_Clicked" TextColor="White"
FontAttributes="Bold" FontSize="Large" HorizontalOptions="FillAndExpand"
BackgroundColor="#088da5" />
<Button Text="Update Order" BackgroundColor="AliceBlue" Clicked="Update_Order_Clicked"></Button>
<Button Text="Update Order and Goto Next Job" BackgroundColor="AliceBlue" Clicked="Update_Order_Clicked"></Button>
</StackLayout>
</ScrollView>
</ContentPage.Content>
As you can see from the image the items in the Listview are not in line with each other how can i make them so aligned.
Edit 2
Hi Again I AM afraid I tried the below answer but it didn't work in end it looked sound.
<ListView x:Name="DeliveryItemsList" HeightRequest="80" HasUnevenRows="True" >
<ListView.ItemTemplate >
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
<Label Text="{Binding ItemNumber}" FontSize="20" ></Label>
<Label Text="{Binding StockCode}" FontSize="20" TextColor="Gray"></Label>
<Label Text="{Binding StockDescription}" FontSize="20" TextColor="Gray"></Label>
<Label Text="{Binding Price}" TextColor="Gray" FontSize="20" ></Label>
<Label Text="{Binding Qty}" TextColor="Gray" FontSize="20" ></Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
If you want things to align, StackLayout is probably not the way to do it. StackLayout allocates space to each child element based on how much it needs, so if each row in your list has differing width requirements for different elements, like price, you'll get the kind of layout you see.
A better approach would be Grid, which gives you explicit control over how wide each column is:
<ListView.ItemTemplate >
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
<Label Text="{Binding ItemNumber}" Grid.Column="0" FontSize="20" ></Label>
<Label Text="{Binding StockCode}" Grid.Column="1" FontSize="20" TextColor="Gray"></Label>
<Label Text="{Binding StockDescription}" Grid.Column="2" FontSize="20" TextColor="Gray"></Label>
<Label Text="{Binding Price}" Grid.Column="3" TextColor="Gray" FontSize="20" ></Label>
<Label Text="{Binding Qty}" Grid.Column="4" TextColor="Gray" FontSize="20" ></Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
In this example, each column is defined to have an equal width (dividing the available width evenly), but you can adjust as you see fit.
You could change one of the ColumnDefinitions to Width="1.5*" which would allocate 1.5 times the space to that column as it does to the other columns. Or could you define a column with Width="100" which would give it a fixed size regardless of the width of the screen.
There is also Width="Auto" which lets you set the width of the column based on the amount of space needed by the contents of that column, but since each row in your ListView is a different Grid, you'd end up with the same problem as you are having now with StackLayout.
How to bind nested listview within listitem of parent list.
I followed below posts, and now need help to bind ItemSource of a nested listview present within listitem data template.
https://montemagno.com/enhancing-xamarin-forms-listview-with-grouping/
how to bind list inside litview in xamarin.forms
Some thing like below-
Group Header 1
Item 1
Listitem 1
Listitem 2
Item 2
Listitem 1
Listitem 2
Group Header 2
Item 1
Listitem 1
Item 2
Listitem 1
Listitem 2
Listitem 3
My Code-
<ContentPage.Content>
<StackLayout Spacing="0">
<StackLayout HeightRequest="5" HorizontalOptions="CenterAndExpand" BackgroundColor="{StaticResource Key=primary-back-title-color}">
<Label HeightRequest="5" WidthRequest="800" HorizontalOptions="FillAndExpand" BackgroundColor="{StaticResource Key=primary-back-title-color}" />
</StackLayout>
<StackLayout HeightRequest="40" BackgroundColor="{StaticResource Key=page-name-background-color}" Orientation="Vertical">
<Label VerticalOptions="CenterAndExpand" Margin="10,0,0,0" FontAttributes="Bold" TextColor="White" Text="My Cart" />
</StackLayout>
<ListView ItemsSource="{Binding VendorProduct}" HasUnevenRows="true" SeparatorVisibility="None" SelectedItem="none" IsGroupingEnabled="true" x:Name="CartProductListView" ItemSelected="Handle_ItemSelected">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell Height="20">
<Grid BackgroundColor="White" HeightRequest="25" Margin="0,0,0,5">
<Label Margin="10,1,0,1" FontSize="14" VerticalOptions="CenterAndExpand" FontAttributes="Bold" TextColor="{StaticResource Key=page-name-background-color}" Text="{Binding VendorName}">
</Label>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="15" />
<RowDefinition Height="15" />
</Grid.RowDefinitions>
<StackLayout Margin="5,0,0,0" Grid.Row="0" Orientation="Horizontal">
<Label FontSize="14" Text="DC-Customer Name: ">
</Label>
<Label FontSize="14" TextColor="#AD2C2C" Text="ABC-123456">
</Label>
</StackLayout>
<StackLayout Margin="5,0,0,0" Grid.Row="1" Orientation="Horizontal">
<Label FontSize="14" Text="Zone Price: ">
</Label>
<Label FontSize="14" TextColor="#AD2C2C" Text="$4.21">
</Label>
</StackLayout>
</Grid>
<Grid Margin="10,10,0,0" ColumnSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<RelativeLayout HeightRequest="94" Grid.Column="0" WidthRequest="{Binding DealsHeight}">
<ListView ItemsSource="{Binding Deals}" Rotation="270" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0.5,Constant=-47}" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=-0.5,Constant=47}" RelativeLayout.WidthConstraint="{ConstraintExpression Type=Constant,Constant=94}" RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1}" RowHeight="94" SeparatorVisibility="None" HasUnevenRows="true" BackgroundColor="White">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid BackgroundColor="#BCD153" RowSpacing="1" Padding="1" Rotation="90" HeightRequest="94">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<StackLayout BackgroundColor="White" Grid.Row="0" Padding="5">
<Label Text="{Binding BookCode}" FontSize="13" />
</StackLayout>
<StackLayout BackgroundColor="White" Grid.Row="1" Padding="5">
<Label Text="{Binding Amount, StringFormat='${0} OFF'}" FontSize="13" />
</StackLayout>
<StackLayout BackgroundColor="White" Grid.Row="2">
<Entry Keyboard="Numeric" IsEnabled="{Binding IsQuantityEditable}" Text="{Binding Quantity}">
<Entry.Behaviors>
<converters:NumericMaxLengthBehavior x:Name="PhoneNumberValidator" />
</Entry.Behaviors>
</Entry>
</StackLayout>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</RelativeLayout>
<StackLayout Grid.Column="1">
<Label Text="Month" VerticalOptions="CenterAndExpand" TextColor="Silver" FontSize="12" HeightRequest="30" />
<Label Text="Discount" VerticalOptions="CenterAndExpand" TextColor="Silver" FontSize="12" HeightRequest="30" />
<Label Text="Quantity" VerticalOptions="CenterAndExpand" TextColor="Silver" FontSize="12" HeightRequest="30" />
</StackLayout>
</Grid>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Margin="0,20,0,0" Text="Propose Order" Command="{Binding ShowOrdersCommand}" BackgroundColor="{StaticResource Key=primary-back-title-color}" TextColor="White" VerticalOptions="Center" HorizontalOptions="Center" WidthRequest="200">
</Button>
</StackLayout>
</ContentPage.Content>
I have a grid with labels, each "Tile" has a transparent background color, however the text also appears to be transparent. Is there a way to remove the transparency from the label text?
My 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"
x:Class="LoyaltyWorx.GridMenu"
BackgroundImage="grid.jpg"
Title="Main Menu"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Label Text="Cards" TextColor="White" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Row="0" Grid.Column="0" BackgroundColor="#1481BA" Opacity="0.5" x:Name="CardTile"/>
<Label Text="Transactions" TextColor="Black" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Row="0" Grid.Column="1" BackgroundColor="#ede890" Opacity="0.5" x:Name="TransactionTile"/>
<Label Text="Promotions" TextColor="White" FontSize="30" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Row="1" Grid.Column="0" BackgroundColor="#1481BA" Grid.ColumnSpan="2" Opacity="0.7" x:Name="PromoTile"/>
<Label Text="Settings" TextColor="Black" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Row="2" Grid.Column="0" BackgroundColor="#ede890" Opacity="0.5" x:Name="SettingsTile" />
<Label Text="My Profile" TextColor="White" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Row="2" Grid.Column="1" BackgroundColor="#1481BA" Opacity="0.5" x:Name="ProfileTile"/>
</Grid>
</ContentPage>
ScreenShot:
You need to add your label in StackLayout look like this :
<StackLayout Grid.Row="0" Grid.Column="0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" BackgroundColor="#1481BA" Opacity="0.5" >
<Label Text="Cards" TextColor="White" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" BackgroundColor="Transparent" x:Name="CardTile"/>
</StackLayout>
You can also use Frame in place of StackLayout
On the labels, set the BackgroundColor property to 0.5 alpha (128 = 0x80) and keep Opacity at 1.0.
<Label ... BackgroundColor="#801481BA" Opacity="1.0" />