Food Delivery App - Cart Page

Food Delivery App - Cart Page

Please, support my blog by clicking on our sponsors ad!

 CartTemplate.xaml
 <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="FoodDeliveryApp.Pages.Products.Template.CartTemplate">
    <Grid Padding="5" ColumnSpacing="10" RowDefinitions="Auto" RowSpacing="0" ColumnDefinitions="150,*">
        <Frame  Padding="0" CornerRadius="10" Grid.Row="0" Grid.Column="0" Grid.RowSpan="4">
            <Image Source="{Binding Image}" HeightRequest="80" Aspect="AspectFill"></Image>
        </Frame>
        <StackLayout Grid.Row="0" Grid.Column="1" VerticalOptions="CenterAndExpand">
            <Label  Text="{Binding Name}" TextColor="{x:StaticResource Gray}" VerticalOptions="Start" FontAttributes="Bold"></Label>
            <Label Text="{Binding Price}" TextColor="{x:StaticResource Gray}" FontAttributes="Bold"></Label>
            <Label Text="{Binding Description}" TextColor="{x:StaticResource Gray}" ></Label>
        </StackLayout>
    </Grid>
</ContentView> 

CartPage.xaml

 <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="FoodDeliveryApp.Pages.Products.CartPage"
             Title="CartPage"
             xmlns:control="clr-namespace:FoodDeliveryApp.Controls"
             xmlns:template="clr-namespace:FoodDeliveryApp.Pages.Products.Template"
             xmlns:vm="clr-namespace:FoodDeliveryApp.ViewModels"
             Shell.NavBarIsVisible="False">
    <RefreshView x:Name="refreshView" x:DataType="vm:HomeViewModel" Command="{Binding LoadBannerCommand}" 
                 IsRefreshing="{Binding IsBusy, Mode=TwoWay}">
        <Grid RowDefinitions="Auto,Auto,*,Auto" Padding="10" RowSpacing="10" x:DataType="vm:HomeViewModel" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <control:BackControl Grid.Row="0" Text="Restaurant Name"></control:BackControl>
            <control:ProductHomeControl ShowUser="False" Grid.Row="1"></control:ProductHomeControl>

            <ListView x:DataType="vm:HomeViewModel" x:Name="listView"  ItemsSource="{Binding vm}" Grid.Row="2" HasUnevenRows="True" SeparatorVisibility="None">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Grid x:DataType="vm:MainViewModel" RowSpacing="10" RowDefinitions="*">

                                <ListView HasUnevenRows="True" Grid.Row="0" ItemsSource="{Binding Menus}" SeparatorVisibility="None">
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <ViewCell>
                                                <template:CartTemplate></template:CartTemplate>
                                            </ViewCell>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                            </Grid>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
              
            </ListView>
            <Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto" Grid.Row="3" ColumnDefinitions="*,Auto" 
                  Margin="0,10" RowSpacing="10">
                <Label Text="Total Price" TextColor="{x:StaticResource Gray}" Grid.Row="0" Grid.Column="0"></Label>
                <Label Text="50" Grid.Row="0" Grid.Column="1" 
                       HorizontalTextAlignment="End"></Label>
                <Label Text="Total Discount" Grid.Row="1" Grid.Column="0"></Label>
                <Label Text="5" Grid.Row="1" Grid.Column="1" 
                       HorizontalTextAlignment="End"></Label>
                <Label Text="Delivery Charge" Grid.Row="2" Grid.Column="0"></Label>
                <Label Text="10" Grid.Row="2" Grid.Column="1"
                       HorizontalTextAlignment="End"></Label>
                <Label Text="Total" Grid.Row="3" Grid.Column="0" FontAttributes="Bold" FontSize="20" />
                <Label Text="55" Grid.Row="3" Grid.Column="1" FontSize="20" 
                       FontAttributes="Bold" 
                       HorizontalTextAlignment="End"></Label>
                <Button Text="Pay Now" Grid.Row="4" Grid.ColumnSpan="2" BackgroundColor="{x:DynamicResource Primary}"></Button>
            </Grid>
        </Grid>
    </RefreshView>
</ContentPage>  

CartPage.xaml.cs

 public partial class CartPage : ContentPage
{
    HomeViewModel _viewModel;

    public CartPage()
    {
        InitializeComponent();
        BindingContext = _viewModel = new HomeViewModel();
    }

    protected override async void OnAppearing()
    {
        base.OnAppearing();
        _viewModel.OnAppearing();
    }
}  

Hope this is helpful to you.

Comments

Popular posts from this blog

Push Notifications in .NET MAUI: A Comprehensive Guide

Explore the UI libraries available for .NET MAUI at no cost.

Push Notification using Firebase in xamarin form (Android and IOS)