Skip to content

Commit 9993602

Browse files
authored
Merge pull request #28 from janusw/net10_cleanup
Replace ListView by CollectionView in sample app
2 parents 1e7b38b + ea9d269 commit 9993602

5 files changed

Lines changed: 46 additions & 28 deletions

File tree

Source/OxyplotMauiSample/Pages/ExampleBrowser.xaml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,33 @@
2020
TextTransform="None" />
2121
</Grid>
2222

23-
<ListView
23+
<CollectionView
2424
x:Name="LvExamples"
2525
Grid.Row="1"
26-
GroupDisplayBinding="{Binding Category}"
27-
IsGroupingEnabled="true"
28-
ItemSelected="ListView_OnItemSelected"
26+
IsGrouped="true"
2927
ItemsSource="{Binding Examples}">
30-
<ListView.ItemTemplate>
28+
<CollectionView.ItemsLayout>
29+
<LinearItemsLayout Orientation="Vertical"
30+
ItemSpacing="8" />
31+
</CollectionView.ItemsLayout>
32+
<CollectionView.GroupHeaderTemplate>
33+
<DataTemplate x:DataType="oxyplotMauiSample:ExampleGroup">
34+
<Label Text="{Binding Category}"
35+
BackgroundColor="Gray"
36+
FontSize="20"
37+
FontAttributes="Bold" />
38+
</DataTemplate>
39+
</CollectionView.GroupHeaderTemplate>
40+
<CollectionView.ItemTemplate>
3141
<DataTemplate x:DataType="exampleLibrary:ExampleInfo">
32-
<TextCell Text="{Binding Title}" />
42+
<Label Text="{Binding Title}" FontSize="18">
43+
<Label.GestureRecognizers>
44+
<TapGestureRecognizer Tapped="CollectionView_OnItemTapped"
45+
NumberOfTapsRequired="1" />
46+
</Label.GestureRecognizers>
47+
</Label>
3348
</DataTemplate>
34-
</ListView.ItemTemplate>
35-
</ListView>
49+
</CollectionView.ItemTemplate>
50+
</CollectionView>
3651
</Grid>
37-
</ContentPage>
52+
</ContentPage>

Source/OxyplotMauiSample/Pages/ExampleBrowser.xaml.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ protected override void OnAppearing()
2323
this.BindingContext = _viewModel;
2424
}
2525

26-
private async void ListView_OnItemSelected(object sender, SelectedItemChangedEventArgs e)
26+
private async void CollectionView_OnItemTapped(object sender, TappedEventArgs e)
2727
{
28-
if (e.SelectedItemIndex < 0)
29-
return;
30-
31-
var exampleInfo = e.SelectedItem as ExampleInfo;
28+
var lbl = (Label)sender;
29+
var exampleInfo = lbl.BindingContext as ExampleInfo;
3230
var page = new PlotViewPage
3331
{
3432
ExampleInfo = exampleInfo

Source/OxyplotMauiSample/Pages/IssueDemos/IssueDemoPage.xaml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
66
xmlns:oxyplotMauiSample="clr-namespace:OxyplotMauiSample"
77
Title="Select demo">
8-
<ListView
8+
<CollectionView
99
x:Name="list1"
1010
HorizontalOptions="Fill"
11-
ItemTapped="ListView_OnItemTapped"
1211
VerticalOptions="Fill">
13-
<ListView.ItemTemplate>
12+
<CollectionView.ItemTemplate>
1413
<DataTemplate x:DataType="oxyplotMauiSample:DemoInfo">
15-
<TextCell Detail="{Binding Details}"
16-
Text="{Binding Title}"/>
14+
<Grid Padding="10">
15+
<Grid.RowDefinitions>
16+
<RowDefinition Height="Auto" />
17+
<RowDefinition Height="Auto" />
18+
</Grid.RowDefinitions>
19+
<Label Grid.Row="0" Text="{Binding Title}" FontAttributes="Bold" />
20+
<Label Grid.Row="1" Text="{Binding Details}" FontSize="Small" TextColor="Gray" />
21+
<Grid.GestureRecognizers>
22+
<TapGestureRecognizer Tapped="CollectionView_OnItemTapped"
23+
NumberOfTapsRequired="1" />
24+
</Grid.GestureRecognizers>
25+
</Grid>
1726
</DataTemplate>
18-
</ListView.ItemTemplate>
19-
</ListView>
27+
</CollectionView.ItemTemplate>
28+
</CollectionView>
2029
</ContentPage>

Source/OxyplotMauiSample/Pages/IssueDemos/IssueDemoPage.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public IssueDemoPage()
2020
this.list1.ItemsSource = demoPages;
2121
}
2222

23-
private async void ListView_OnItemTapped(object sender, ItemTappedEventArgs e)
23+
private async void CollectionView_OnItemTapped(object sender, TappedEventArgs e)
2424
{
25-
var demoInfo = (DemoInfo)e.Item;
25+
var grid = (Grid)sender;
26+
var demoInfo = (DemoInfo)grid.BindingContext;
2627
var page = demoInfo.CreatePage();
2728
page.Title = demoInfo.Title;
2829
await Navigation.PushAsync(page);

Source/OxyplotMauiSample/Resources/Styles/Styles.xaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@
163163
</Setter>
164164
</Style>
165165

166-
<Style TargetType="ListView">
167-
<Setter Property="SeparatorColor" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray500}}" />
168-
<Setter Property="RefreshControlColor" Value="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource Gray200}}" />
169-
</Style>
170-
171166
<Style TargetType="Picker">
172167
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource White}}" />
173168
<Setter Property="TitleColor" Value="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource Gray200}}" />

0 commit comments

Comments
 (0)