Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit a5bbc64

Browse files
maxkoshevoiAndreiMisiukevichpictosjfversluis
authored
Add sample page for ListIsNullOrEmptyConvertor (#780)
* Add sample page for ListIsNullOrEmptyConvertor * Remove HasUnevenRows Co-authored-by: Andrei <[email protected]> Co-authored-by: Pedro Jesus <[email protected]> Co-authored-by: Gerald Versluis <[email protected]>
1 parent cee2eab commit a5bbc64

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
5+
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
6+
xmlns:vm="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.Converters"
7+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Converters.ListIsNullOrEmptyPage">
8+
9+
<pages:BasePage.BindingContext>
10+
<vm:ListIsNullOrEmptyViewModel />
11+
</pages:BasePage.BindingContext>
12+
13+
<AbsoluteLayout>
14+
<ListView ItemsSource="{Binding Items}"
15+
IsVisible="{Binding Items, Converter={xct:ListIsNotNullOrEmptyConverter}}">
16+
<ListView.ItemTemplate>
17+
<DataTemplate>
18+
<ViewCell>
19+
<Label Text="{Binding Name}" />
20+
</ViewCell>
21+
</DataTemplate>
22+
</ListView.ItemTemplate>
23+
</ListView>
24+
<Label Text="Collection is empty"
25+
AbsoluteLayout.LayoutBounds="0,0,1,1"
26+
AbsoluteLayout.LayoutFlags="All"
27+
IsVisible="{Binding Items, Converter={xct:ListIsNullOrEmptyConverter}}"
28+
VerticalOptions="CenterAndExpand"
29+
HorizontalOptions="CenterAndExpand"
30+
HorizontalTextAlignment="Center" />
31+
32+
<StackLayout Orientation="Horizontal" Margin="5" Spacing="5"
33+
AbsoluteLayout.LayoutFlags="PositionProportional"
34+
AbsoluteLayout.LayoutBounds="1,1,AutoSize,AutoSize">
35+
<Button Text="Add" Command="{Binding AddItemCommand}" />
36+
<Button Text="Remove" Command="{Binding RemoveItemCommand}" IsEnabled="{Binding Items, Converter={xct:ListIsNotNullOrEmptyConverter}}" />
37+
</StackLayout>
38+
</AbsoluteLayout>
39+
</pages:BasePage>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Xamarin.CommunityToolkit.Sample.Pages.Converters
2+
{
3+
public partial class ListIsNullOrEmptyPage : BasePage
4+
{
5+
public ListIsNullOrEmptyPage()
6+
=> InitializeComponent();
7+
}
8+
}

samples/XCT.Sample/ViewModels/Converters/ConvertersGalleryViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public class ConvertersGalleryViewModel : BaseGalleryViewModel
4040
typeof(VariableMultiValueConverterPage),
4141
nameof(VariableMultiValueConverter),
4242
"A converter that allows you to combine multiple boolean bindings into a single binding."),
43+
44+
new SectionModel(
45+
typeof(ListIsNullOrEmptyPage),
46+
nameof(ListIsNullOrEmptyConverter),
47+
"A converter that allows you to check if collection is null or empty"),
4348
};
4449
}
4550
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Xamarin.CommunityToolkit.ObjectModel;
2+
using Xamarin.Forms;
3+
4+
namespace Xamarin.CommunityToolkit.Sample.ViewModels.Converters
5+
{
6+
public class ListIsNullOrEmptyViewModel : BaseViewModel
7+
{
8+
public ObservableRangeCollection<Person> Items { get; } = new ObservableRangeCollection<Person>();
9+
10+
public ListIsNullOrEmptyViewModel()
11+
{
12+
AddItemCommand = new Command(() =>
13+
{
14+
Items.Add(new Person
15+
{
16+
Id = Items.Count,
17+
Name = $"Person {Items.Count}"
18+
});
19+
});
20+
RemoveItemCommand = new Command(() => Items.RemoveAt(0));
21+
22+
// ListIsNullOrEmptyConvertor needs to know that Items are updated
23+
Items.CollectionChanged += (sender, e) => OnPropertyChanged(nameof(Items));
24+
}
25+
26+
public Command AddItemCommand { get; }
27+
28+
public Command RemoveItemCommand { get; }
29+
}
30+
}

0 commit comments

Comments
 (0)