Skip to content

Commit 6bff544

Browse files
Merge pull request #7 from SyncfusionExamples/bottomsheet-sample
Added a new example for bottom sheet
2 parents 8177bcd + c3d1c03 commit 6bff544

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+9661
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:BottomSheetFoodOrder"
5+
x:Class="BottomSheetFoodOrder.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace BottomSheetFoodOrder
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
protected override Window CreateWindow(IActivationState? activationState)
11+
{
12+
return new Window(new AppShell());
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="BottomSheetFoodOrder.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:BottomSheetFoodOrder"
7+
Shell.FlyoutBehavior="Flyout"
8+
Title="BottomSheetFoodOrder">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace BottomSheetFoodOrder
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
using Syncfusion.Maui.Toolkit.BottomSheet;
2+
using Syncfusion.Maui.Toolkit.EffectsView;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace BottomSheetFoodOrder
10+
{
11+
public class BottomSheetBehavior : Behavior<ContentPage>
12+
{
13+
ListView? _listView;
14+
ItemViewModel? _itemViewModel;
15+
SfBottomSheet? _bottomSheet;
16+
SfEffectsView? _decreaseQuantity;
17+
SfEffectsView? _increaseQuantity;
18+
SfEffectsView? _closeIcon;
19+
CheckBox? _extraOne;
20+
CheckBox? _extraTwo;
21+
Grid? grid;
22+
23+
/// <summary>
24+
/// You can override this method to subscribe to AssociatedObject events and initialize properties.
25+
/// </summary>
26+
/// <param name="bindable">SampleView type parameter named as bindable.</param>
27+
protected override void OnAttachedTo(ContentPage bindable)
28+
{
29+
_listView = bindable.FindByName<ListView>("ListView");
30+
_listView.ItemTapped += ListView_ItemTapped;
31+
_itemViewModel = new ItemViewModel();
32+
bindable.BindingContext = _itemViewModel;
33+
_bottomSheet = bindable.FindByName<SfBottomSheet>("BottomSheet");
34+
_bottomSheet.StateChanged += OnStateChanged;
35+
_decreaseQuantity = bindable.FindByName<SfEffectsView>("DecreaseQuantity");
36+
_increaseQuantity = bindable.FindByName<SfEffectsView>("IncreaseQuantity");
37+
_closeIcon = bindable.FindByName<SfEffectsView>("CloseIcon");
38+
_extraOne = bindable.FindByName<CheckBox>("ExtraCheese");
39+
_extraTwo = bindable.FindByName<CheckBox>("ExtraDoubleCheese");
40+
grid = bindable.FindByName<Grid>("Grid");
41+
42+
TapGestureRecognizer decreaseTapped = new TapGestureRecognizer();
43+
decreaseTapped.Tapped += OnDecreaseTapped;
44+
_decreaseQuantity.GestureRecognizers.Add(decreaseTapped);
45+
46+
TapGestureRecognizer increaseTapped = new TapGestureRecognizer();
47+
increaseTapped.Tapped += OnIncreaseTapped;
48+
_increaseQuantity.GestureRecognizers.Add(increaseTapped);
49+
50+
TapGestureRecognizer closeIconTapped = new TapGestureRecognizer();
51+
closeIconTapped.Tapped += OnCloseIconTapped;
52+
_closeIcon.GestureRecognizers.Add(closeIconTapped);
53+
54+
_extraOne.CheckedChanged += ExtraOne_CheckedChanged;
55+
_extraTwo.CheckedChanged += ExtraTwo_CheckedChanged;
56+
57+
base.OnAttachedTo(bindable);
58+
}
59+
60+
private void ExtraTwo_CheckedChanged(object? sender, CheckedChangedEventArgs e)
61+
{
62+
if (_extraTwo is not null && _bottomSheet is not null && grid is not null)
63+
{
64+
if (_extraTwo.IsChecked && _extraOne is not null)
65+
{
66+
_extraOne.IsChecked = false;
67+
var item = (Item)grid.BindingContext;
68+
item.TotalPrice = (item.Price + 4) * item.Quantity;
69+
}
70+
else
71+
{
72+
var item = (Item)grid.BindingContext;
73+
item.TotalPrice = item.Price * item.Quantity;
74+
}
75+
}
76+
}
77+
78+
private void ExtraOne_CheckedChanged(object? sender, CheckedChangedEventArgs e)
79+
{
80+
if (_extraOne is not null && _bottomSheet is not null && grid is not null)
81+
{
82+
if (_extraOne.IsChecked && _extraTwo is not null)
83+
{
84+
_extraTwo.IsChecked = false;
85+
var item = (Item)grid.BindingContext;
86+
item.TotalPrice = (item.Price + 2) * item.Quantity;
87+
}
88+
else
89+
{
90+
var item = (Item)grid.BindingContext;
91+
item.TotalPrice = item.Price * item.Quantity;
92+
}
93+
}
94+
}
95+
96+
private void OnStateChanged(object? sender, StateChangedEventArgs e)
97+
{
98+
if (_bottomSheet is not null && _bottomSheet.State is BottomSheetState.Hidden && grid is not null)
99+
{
100+
grid.BindingContext = null;
101+
}
102+
}
103+
104+
private void ListView_ItemTapped(object? sender, ItemTappedEventArgs e)
105+
{
106+
var selectedItem = (Item)e.Item;
107+
if (_bottomSheet is not null && grid is not null)
108+
{
109+
grid.BindingContext = selectedItem;
110+
if (_bottomSheet.IsOpen)
111+
{
112+
_bottomSheet.State = BottomSheetState.HalfExpanded;
113+
}
114+
115+
_bottomSheet.Show();
116+
}
117+
}
118+
119+
private void OnDecreaseTapped(object? sender, TappedEventArgs e)
120+
{
121+
if (_bottomSheet is not null && grid is not null)
122+
{
123+
var temp = (Item)grid.BindingContext;
124+
if (temp.Quantity > 1)
125+
{
126+
temp.Quantity--;
127+
}
128+
}
129+
}
130+
131+
private void OnIncreaseTapped(object? sender, TappedEventArgs e)
132+
{
133+
if (_bottomSheet is not null && grid is not null)
134+
{
135+
var temp = (Item)grid.BindingContext;
136+
temp.Quantity++;
137+
}
138+
}
139+
140+
private void OnCloseIconTapped(object? sender, TappedEventArgs e)
141+
{
142+
if (_bottomSheet is not null)
143+
{
144+
_bottomSheet.Close();
145+
}
146+
}
147+
148+
/// <summary>
149+
/// You can override this method while View was detached from window
150+
/// </summary>
151+
/// <param name="bindable">SampleView type parameter named as bindable</param>
152+
protected override void OnDetachingFrom(ContentPage bindable)
153+
{
154+
_listView = null;
155+
_itemViewModel = null;
156+
base.OnDetachingFrom(bindable);
157+
}
158+
}
159+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->
8+
9+
<!-- Note for MacCatalyst:
10+
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
11+
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
12+
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
13+
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
14+
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
15+
16+
<OutputType>Exe</OutputType>
17+
<RootNamespace>BottomSheetFoodOrder</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>BottomSheetFoodOrder</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.bottomsheetfoodorder</ApplicationId>
28+
29+
<!-- Versions -->
30+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
31+
<ApplicationVersion>1</ApplicationVersion>
32+
33+
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
34+
<WindowsPackageType>None</WindowsPackageType>
35+
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
37+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
39+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
40+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
41+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
42+
</PropertyGroup>
43+
44+
<ItemGroup>
45+
<!-- App Icon -->
46+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
47+
48+
<!-- Splash Screen -->
49+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
50+
51+
<!-- Images -->
52+
<MauiImage Include="Resources\Images\*" />
53+
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
54+
55+
<!-- Custom Fonts -->
56+
<MauiFont Include="Resources\Fonts\*" />
57+
58+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
59+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
60+
</ItemGroup>
61+
62+
<ItemGroup>
63+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
64+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
65+
<PackageReference Include="Syncfusion.Maui.Toolkit" Version="*" />
66+
</ItemGroup>
67+
68+
<ItemGroup>
69+
<MauiXaml Update="GettingStartedDesktop.xaml">
70+
<Generator>MSBuild:Compile</Generator>
71+
</MauiXaml>
72+
<MauiXaml Update="GettingStartedMobile.xaml">
73+
<Generator>MSBuild:Compile</Generator>
74+
</MauiXaml>
75+
</ItemGroup>
76+
77+
</Project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
5+
<ActiveDebugFramework>net9.0-windows10.0.19041.0</ActiveDebugFramework>
6+
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
7+
<SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
8+
<DefaultDevice>pixel_5_-_api_34</DefaultDevice>
9+
</PropertyGroup>
10+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net9.0-android|AnyCPU'">
11+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
12+
</PropertyGroup>
13+
<ItemGroup>
14+
<MauiXaml Update="GettingStartedDesktop.xaml">
15+
<SubType>Designer</SubType>
16+
</MauiXaml>
17+
<MauiXaml Update="GettingStartedMobile.xaml">
18+
<SubType>Designer</SubType>
19+
</MauiXaml>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<None Update="App.xaml">
23+
<SubType>Designer</SubType>
24+
</None>
25+
<None Update="AppShell.xaml">
26+
<SubType>Designer</SubType>
27+
</None>
28+
<None Update="MainPage.xaml">
29+
<SubType>Designer</SubType>
30+
</None>
31+
<None Update="Platforms\Windows\App.xaml">
32+
<SubType>Designer</SubType>
33+
</None>
34+
<None Update="Platforms\Windows\Package.appxmanifest">
35+
<SubType>Designer</SubType>
36+
</None>
37+
<None Update="Resources\Styles\Colors.xaml">
38+
<SubType>Designer</SubType>
39+
</None>
40+
<None Update="Resources\Styles\Styles.xaml">
41+
<SubType>Designer</SubType>
42+
</None>
43+
</ItemGroup>
44+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35506.116 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BottomSheetFoodOrder", "BottomSheetFoodOrder.csproj", "{462D8B5B-ADF0-427B-BE4D-BE33B419007C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{462D8B5B-ADF0-427B-BE4D-BE33B419007C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{462D8B5B-ADF0-427B-BE4D-BE33B419007C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{462D8B5B-ADF0-427B-BE4D-BE33B419007C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{462D8B5B-ADF0-427B-BE4D-BE33B419007C}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

0 commit comments

Comments
 (0)