Skip to content

Commit 16bbbd8

Browse files
CopilotVetle444
andcommitted
Add BottomSheet with search sample to Components app
Co-authored-by: Vetle444 <35739538+Vetle444@users.noreply.github.com>
1 parent eac4fb8 commit 16bbbd8

4 files changed

Lines changed: 89 additions & 0 deletions

File tree

src/app/Components/ComponentsSamples/BottomSheets/BottomSheetSamples.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
<dui:NavigationListItem Title="{x:Static localizedStrings:LocalizedStrings.BottomSheet}"
2626
Subtitle="{x:Static localizedStrings:LocalizedStrings.BottomSheet_OpenNotClosableInteracting}"
2727
Command="{dui:OpenBottomSheetCommand {x:Type sheets:BottomSheetNotClosableByInteracting}}"
28+
VerticalOptions="Start"
29+
HasBottomDivider="True" />
30+
31+
<dui:NavigationListItem Title="Open with search"
32+
Subtitle="BottomSheet with native search field"
33+
Command="{dui:OpenBottomSheetCommand {x:Type sheets:BottomSheetWithSearch}}"
2834
VerticalOptions="Start" />
2935
</dui:VerticalStackLayout>
3036
</dui:ContentPage>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<dui:BottomSheet xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
xmlns:dui="http://dips.com/mobile.ui"
6+
xmlns:sheets="clr-namespace:Components.ComponentsSamples.BottomSheets.Sheets"
7+
xmlns:sampleData="clr-namespace:Components.SampleData"
8+
x:Class="Components.ComponentsSamples.BottomSheets.Sheets.BottomSheetWithSearch"
9+
x:DataType="sheets:BottomSheetWithSearchViewModel"
10+
Title="Search"
11+
HasSearchBar="True"
12+
SearchCommand="{Binding SearchCommand}"
13+
Positioning="Large">
14+
15+
<dui:BottomSheet.BindingContext>
16+
<sheets:BottomSheetWithSearchViewModel />
17+
</dui:BottomSheet.BindingContext>
18+
19+
<CollectionView ItemsSource="{Binding People}">
20+
<CollectionView.ItemTemplate>
21+
<DataTemplate x:DataType="{x:Type sampleData:Person}">
22+
<dui:ListItem Title="{Binding DisplayName}"
23+
HasBottomDivider="True" />
24+
</DataTemplate>
25+
</CollectionView.ItemTemplate>
26+
<CollectionView.EmptyView>
27+
<dui:Label Text="No results found"
28+
HorizontalOptions="Center"
29+
Margin="{dui:Thickness Top=content_margin_large}"
30+
Style="{dui:Styles Label=UI200}" />
31+
</CollectionView.EmptyView>
32+
</CollectionView>
33+
34+
</dui:BottomSheet>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Components.ComponentsSamples.BottomSheets.Sheets;
2+
3+
public partial class BottomSheetWithSearch
4+
{
5+
public BottomSheetWithSearch()
6+
{
7+
InitializeComponent();
8+
}
9+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Windows.Input;
2+
using Components.SampleData;
3+
using DIPS.Mobile.UI.MVVM;
4+
5+
namespace Components.ComponentsSamples.BottomSheets.Sheets;
6+
7+
public class BottomSheetWithSearchViewModel : ViewModel
8+
{
9+
private List<Person> m_people;
10+
private readonly List<Person> m_originalPeople;
11+
12+
public BottomSheetWithSearchViewModel()
13+
{
14+
People = SampleDataStorage.People.ToList();
15+
m_originalPeople = People.ToList();
16+
SearchCommand = new Command<string>(FilterItems);
17+
}
18+
19+
private void FilterItems(string filterText)
20+
{
21+
if (string.IsNullOrEmpty(filterText))
22+
{
23+
People = m_originalPeople.ToList();
24+
}
25+
else
26+
{
27+
People = m_originalPeople
28+
.Where(p => p.DisplayName.ToLower().Contains(filterText.ToLower()))
29+
.ToList();
30+
}
31+
}
32+
33+
public List<Person> People
34+
{
35+
get => m_people;
36+
set => RaiseWhenSet(ref m_people, value);
37+
}
38+
39+
public ICommand SearchCommand { get; }
40+
}

0 commit comments

Comments
 (0)