Xamarin Forms Center Grid horizontal - xaml

I have a problem. I am trying to achieve the following Grid:
To do that, I thought that I should set both the ColumnWidth to Auto and set the HorizontalOptions of the Grid to Center, so the Grid is centred in the middle of the screen creating equal spaces at the left and right side, but no matter what I try, I can't seem to move the columns from the right side. Here is what I have now:
And here is my code:
<Frame BorderColor="#00D8FF" Padding="0" HorizontalOptions="FillAndExpand" BackgroundColor="Transparent">
<StackLayout Orientation="Vertical">
<CarouselView ItemsSource="{Binding coinDataList}" HeightRequest="50">
<CarouselView.ItemTemplate>
<DataTemplate>
<Grid RowSpacing="0" HorizontalOptions="Center">
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="1" Text="BTC-USDT" FontAttributes="Bold" TextColor="#00D8FF" FontSize="18"/>
<Label Grid.Row="1" Grid.Column="1" Text="9762.33" TextColor="White" FontSize="18"/>
<Label Grid.RowSpan="2" Grid.Column="2" Text="-$476.22 (-4.77%)" VerticalOptions="CenterAndExpand" FontAttributes="Bold" TextColor="Red" FontSize="18" Margin="15,0,0,0"/>
</Grid>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</StackLayout>
</Frame>
How can I create my wanted result?

Can you try this?
<Frame BorderColor="#00D8FF" Padding="0" HorizontalOptions="FillAndExpand" BackgroundColor="Transparent">
<StackLayout Orientation="Vertical">
<CarouselView ItemsSource="{Binding coinDataList}" HeightRequest="50">
<CarouselView.ItemTemplate>
<DataTemplate>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="1" Text="BTC-USDT" FontAttributes="Bold" TextColor="#00D8FF" FontSize="18"/>
<Label Grid.Row="1" Grid.Column="1" Text="9762.33" FontAttributes="Bold" TextColor="#00D8FF" FontSize="18"/>
<Label Grid.Row="0" Grid.Column="2" VerticalTextAlignment="Center" Text="-$476.22 (-4.77%)" FontAttributes="Bold" TextColor="#00D8FF" FontSize="18"/>
</Grid>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</StackLayout>
</Frame>

Related

xamarin forms - ios - listview header - showing bold border?

Please see below image
please see below code
//PopUp.Xaml
<ListView.Header>
<Frame>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30*" />
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" Text="Product"
HorizontalOptions="Center"/>
<Label Grid.Column="1" Grid.Row="0"
Text="Quantity"
HorizontalOptions="Center"/>
<Label Grid.Column="2" Grid.Row="0"
Text="Price"
HorizontalOptions="Center"/>
<Label Grid.Column="3" Grid.Row="0"
Text="Sub"
HorizontalOptions="Center"/>
<BoxView Grid.Row="1"
Grid.ColumnSpan="4"
HeightRequest="1"
BackgroundColor="LightGray"/>
</Grid>
</Frame>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10" RowSpacing="10" ColumnSpacing="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="43*" />
<ColumnDefinition Width="8*" />
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="24*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="{Binding OrderModel_Id}" VerticalOptions="End"/>
<Label Grid.Column="1" Grid.Row="0" Text="{Binding User_Name}" VerticalOptions="End"/>
<Label Grid.Column="0" Grid.Row="0" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand" Text="{Binding Product_Id, Converter={StaticResource converter}}"/>
<Label Grid.Column="1" Grid.Row="0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Text="{Binding Quantity}"/>
<Label Grid.Column="2" Grid.Row="0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Text="{Binding PriceOf_Item, StringFormat='£{0:0.00}'}"/>
<Label Grid.Column="3" Grid.Row="0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Text="{Binding SubtotalForThis_Item, StringFormat='£{0:0.00}'}"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</pages:PopupPage>
My Q being why does the popUp header of the listview...appear with a bold border below it? only on ios...not on android...I would like to remove it please. does anyone know how?

Xamarin.Forms XAML How to show columns in center of grid (not left bind)

I have this grid object:
<!--Legende-->
<Grid Grid.Row="0">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.8*"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="0.8*"/>
</Grid.RowDefinitions>
<Grid Grid.Column="0" Grid.Row="1" HorizontalOptions="Center">
<BoxView BackgroundColor="#faea57" CornerRadius="25"></BoxView>
<Label
Padding="10,0,10,0"
VerticalOptions="Center"
Grid.Column="0"
Text="Geplant"
FontSize="14"
FontFamily="Galvji-01.ttf"
TextColor="#ffffff"/>
</Grid>
<Grid Grid.Column="1" Grid.Row="1" HorizontalOptions="Center">
<BoxView BackgroundColor="#75f056" CornerRadius="25"></BoxView>
<Label
Padding="10,0,10,0"
VerticalOptions="Center"
Text="Aktiv"
FontSize="14"
FontFamily="Galvji-01.ttf"
TextColor="#ffffff"/>
</Grid>
<Grid Grid.Column="2" Grid.Row="1" HorizontalOptions="Center">
<BoxView BackgroundColor="#fa594d" CornerRadius="25"></BoxView>
<Label
Padding="10,0,10,0"
VerticalOptions="Center"
Text="Abgeschlossen"
FontSize="14"
FontFamily="Galvji-01.ttf"
TextColor="#ffffff"/>
</Grid>
</Grid>
The result is this:
The 3 boxviews with the text are bind to the left ob the screen. However, I want those three objets to be rendered in the CENTRE.
I cannot work with padding, since the amount of padding varies from phone to phone so I have to work with attributes like "center", but I cannot seem to figure out how to do that.
Help would be awesome!
Thanks
You could set two extra space column to get the effect like padding.
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*"/> // left
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="0.2*"/> // right
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.8*"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="0.8*"/>
</Grid.RowDefinitions>
<Grid Grid.Column="1" Grid.Row="1" HorizontalOptions="Center">
<BoxView BackgroundColor="#faea57" CornerRadius="25"></BoxView>
<Label
Padding="10,0,10,0"
VerticalOptions="Center"
Grid.Column="0"
Text="Geplant"
FontSize="14"
FontFamily="Galvji-01.ttf"
TextColor="#ffffff"/>
</Grid>
<Grid Grid.Column="2" Grid.Row="1" HorizontalOptions="Center">
<BoxView BackgroundColor="#75f056" CornerRadius="25"></BoxView>
<Label
Padding="10,0,10,0"
VerticalOptions="Center"
Text="Aktiv"
FontSize="14"
FontFamily="Galvji-01.ttf"
TextColor="#ffffff"/>
</Grid>
<Grid Grid.Column="3" Grid.Row="1" HorizontalOptions="Center">
<BoxView BackgroundColor="#fa594d" CornerRadius="25"></BoxView>
<Label
Padding="10,0,10,0"
VerticalOptions="Center"
Text="Abgeschlossen"
FontSize="14"
FontFamily="Galvji-01.ttf"
TextColor="#ffffff"/>
</Grid>
</Grid>

set border to listview Xamarin form

I made a table with xamarin forms, but I would like the headers not to have blank spaces and also put borders, use table-striped, have the basic characteristics of a bootstrap table for example. Could you help me?. Thank you for you help.
Here my code.
<StackLayout BindingContext="{Binding OpportunityListViewModel}" Padding="8">
<ListView x:Name="ProposalListProduct"
ItemsSource="{Binding ProposalView}"
IsRefreshing="{Binding IsRefreshing}"
CachingStrategy="RecycleElement"
HasUnevenRows="True"
Margin="0">
<ListView.Header>
<Grid Margin="0" Padding="0" RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*" />
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Margin="0" Text="Item" FontSize="8" TextColor="Black" BackgroundColor="LightGray" HorizontalTextAlignment="Center" HorizontalOptions="Fill" />
<Label Grid.Row="0" Grid.Column="1" Margin="0" Text="Cant." FontSize="8" TextColor="Black" BackgroundColor="LightGray" HorizontalTextAlignment="Center" HorizontalOptions="Fill" />
<Label Grid.Row="0" Grid.Column="2" Margin="0" Text="Precio" FontSize="8" TextColor="Black" BackgroundColor="LightGray" HorizontalTextAlignment="Center" HorizontalOptions="Fill" />
<Label Grid.Row="0" Grid.Column="3" Margin="0" Text="Total" FontSize="8" TextColor="Black" BackgroundColor="LightGray" HorizontalTextAlignment="Center" HorizontalOptions="Fill" />
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid Margin="0" Padding="0" RowSpacing="0" ColumnSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*" />
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Margin="0" x:Name="Nombre" Text="{Binding Nombre}" FontSize="8" TextColor="Black" VerticalTextAlignment="End" HorizontalTextAlignment="Start" />
<Label Grid.Column="1" Margin="0" x:Name="Cantidad" Text="{Binding Cantidad}" FontSize="8" TextColor="Black" VerticalTextAlignment="End" HorizontalTextAlignment="End"/>
<Label Grid.Column="2" Margin="0" x:Name="Precio" Text="{Binding Precio,StringFormat='{0:C2}'}" FontSize="8" TextColor="Black" VerticalTextAlignment="End" HorizontalTextAlignment="End"/>
<Label Grid.Column="3" Margin="0" x:Name="Total" Text="{Binding Total,StringFormat='{0:C2}'}" FontSize="8" TextColor="Black" VerticalTextAlignment="End" HorizontalTextAlignment="End"/>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
you can do it like this:
<ListView ItemsSource="{Binding People}"
HasUnevenRows="True"
SeparatorVisibility="None">
<ListView.Header>
<Frame>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Text="Name"
HorizontalOptions="Center"
FontSize="Large"/>
<Label Grid.Column="1"
Text="Description"
HorizontalOptions="Center"
FontSize="Large"/>
<BoxView Grid.Row="1"
Grid.ColumnSpan="2"
HeightRequest="1"
BackgroundColor="LightGray"/>
</Grid>
</Frame>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Margin="20,10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Text="{Binding Name}"
HorizontalOptions="Center"
VerticalOptions="Center"/>
<Label Grid.Column="1"
Text="{Binding Description}"
HorizontalOptions="Center"
VerticalOptions="Center"/>
<BoxView Grid.Row="1"
Grid.ColumnSpan="2"
HeightRequest="1"
BackgroundColor="LightGray"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

xamarin forms: the page becomes extremely large and I am not sure why

<ContentPage.Content>
<ScrollView>
<StackLayout HorizontalOptions="FillAndExpand" Padding="0">
<Label FontSize="Large" Margin="6" HorizontalTextAlignment="Center" Text="Revisión Técnica" HorizontalOptions="Center"></Label>
<BoxView HorizontalOptions="FillAndExpand" HeightRequest="3" Color="Black"></BoxView>
<StackLayout IsVisible="True" Orientation="Horizontal" Padding="0" x:Name="ContainerSec" HorizontalOptions="FillAndExpand">
<StackLayout Padding="0" Spacing="0">
<StackLayout BackgroundColor="LightGray" Padding="0">
<Label Margin="8" VerticalOptions="Center" VerticalTextAlignment="Center" Text="Lista de detalles"></Label>
</StackLayout>
<StackLayout Padding="0" Spacing="0" x:Name="VisualColumnWRP" WidthRequest="{Binding widthCol,Source={x:Reference Pagexaml}}" MinimumWidthRequest="{Binding widthCol,Source={x:Reference Pagexaml}}">
</StackLayout>
</StackLayout>
<BoxView WidthRequest="3" VerticalOptions="FillAndExpand" Color="{StaticResource type2-color}"></BoxView>
<StackLayout Padding="0" Spacing="0" HorizontalOptions="FillAndExpand" VerticalOptions="Start">
<Grid x:Name="ElGrid" HorizontalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="0"/>
<RowDefinition x:Name="row1" Height="Auto"></RowDefinition>
<RowDefinition x:Name="row2" Height="Auto"/>
<RowDefinition x:Name="row3" Height="Auto"></RowDefinition>
<RowDefinition x:Name="row4" Height="Auto"/>
<RowDefinition x:Name="row5" Height="Auto"></RowDefinition>
<RowDefinition x:Name="row6" Height="Auto"/>
<RowDefinition Height="0"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalOptions="End" Margin="5" Text="Garantía"></Label>
<Label Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="3" HorizontalOptions="Start" Margin="5" x:Name="Garantia"></Label>
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" HorizontalOptions="End" Margin="5" Text="Descripción"></Label>
<Label Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="3" HorizontalOptions="Start" Margin="5" x:Name="Description"></Label>
<Label Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" HorizontalOptions="End" Margin="5" Text="Detalle"></Label>
<Label Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="3" HorizontalOptions="Start" Margin="5" x:Name="Detail"></Label>
<StackLayout Orientation="Horizontal" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="5">
<Label Margin="5" Text="Estado"></Label>
<suave:MaterialPicker x:Name="Picker" HorizontalOptions="FillAndExpand" Margin="5"></suave:MaterialPicker>
</StackLayout>
<StackLayout Orientation="Horizontal" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="5">
<Label Margin="5" Text="Nota"></Label>
<Editor x:Name="EditorWRP" HeightRequest="100" HorizontalOptions="FillAndExpand"></Editor>
</StackLayout>
<StackLayout Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="5">
<suave:MaterialButton Clicked="MaterialButton_Clicked" BackgroundColor="LightGray" Text="Agregar evidencia" Margin="5"></suave:MaterialButton>
</StackLayout>
</Grid>
</StackLayout>
</StackLayout>
<Image x:Name="GalleryImage"></Image>
</StackLayout>
</ScrollView>
</ContentPage.Content>
the previous code generate the next screen but is height is a lot bigger than the height of the tablet emulator and I don't know why.
The only way that I solved it was declaring the grid with fix height, but even when the window is big and I checked its height value, turns out to be small. Thank you for your help
You can put your scroll view into absolute layout and set bounds and flags - it should work

I can list my messages , Listview

I can list my messages, but now I wanted every message after that I had a balloon. To identify if I sent or received. The balloon is now the text is not staying. Can you help me?
<ListView x:Name="Post_List" Grid.Row="1">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid ColumnSpacing="2" Padding="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="40"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Frame Grid.Row="0" OutlineColor="Transparent"
HasShadow="False" Grid.Column="0"
CornerRadius="5" BackgroundColor="#03A9F4">
<Label TextColor="White" Text="{Binding Mensagem}"/>
</Frame>
<Label FontSize="Micro" Grid.Row="1" Grid.Column="0"
Text="{Binding Data}" TextColor="Gray"></Label>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Adding HasUnevenRows="True" to your ListView will fix your issue.
This is because you did not set any RowHeight which is alright cause you want the height to be based on the content but the ListView does not know the dimension to apply. Using the HasUnevenRows the ListView will be calculating the size to fit the content.
<ListView x:Name="Post_List" Grid.Row="1" HasUnevenRows="True" >
<ListView.ItemTemplate >
<DataTemplate >
<ViewCell>
<Grid ColumnSpacing="2" Padding="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Frame Grid.Row="0" OutlineColor="Transparent" HasShadow="False" Grid.Column="0" CornerRadius="5" BackgroundColor="#03A9F4">
<Label TextColor="White" Text="{Binding Mensagem}"/>
</Frame>
<Label FontSize="Micro" Grid.Row="1" Grid.Column="0" Text="{Binding Data}" TextColor="Gray"></Label>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Hope this helps.-