-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Redth/Maui.VirtualListView
- Loading branch information
Showing
26 changed files
with
358 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Sample/VirtualListViewSample/BindableSelectedItemPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="VirtualListViewSample.BindableSelectedItemPage" | ||
xmlns:local="clr-namespace:VirtualListViewSample" | ||
xmlns:vlv="clr-namespace:Microsoft.Maui.Controls;assembly=VirtualListView" | ||
x:DataType="local:BindableSelectedItemViewModel" | ||
Title="BindableSelectedItemPage"> | ||
<Grid RowDefinitions="*,Auto" ColumnDefinitions="*,Auto" Padding="20"> | ||
<vlv:VirtualListView | ||
Grid.Row="0" | ||
Grid.Column="0" Grid.ColumnSpan="2" | ||
x:Name="vlv" | ||
Adapter="{Binding Adapter}" | ||
SelectedItem="{Binding SelectedItem, Mode=TwoWay}" | ||
OnSelectedItemsChanged="vlv_SelectedItemsChanged" | ||
SelectionMode="Single"> | ||
<vlv:VirtualListView.ItemTemplate> | ||
<DataTemplate> | ||
<vlv:VirtualViewCell SelectedBackground="DarkBlue" UnselectedBackground="LightBlue"> | ||
<Border | ||
Margin="10,0,0,0" | ||
Padding="4" | ||
Background="Transparent" | ||
StrokeShape="{RoundRectangle CornerRadius=10}"> | ||
<Label Margin="10,6,10,6" Text="{Binding .}" /> | ||
</Border> | ||
</vlv:VirtualViewCell> | ||
</DataTemplate> | ||
</vlv:VirtualListView.ItemTemplate> | ||
</vlv:VirtualListView> | ||
|
||
<Entry x:Name="entryItem" Grid.Row="1" Grid.Column="0" Placeholder="Item" /> | ||
<Button Grid.Row="1" Grid.Column="1" Text="Select/Deselect" Clicked="Button_Clicked" /> | ||
</Grid> | ||
</ContentPage> |
75 changes: 75 additions & 0 deletions
75
Sample/VirtualListViewSample/BindableSelectedItemPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using Microsoft.Maui.Adapters; | ||
using System.Collections.ObjectModel; | ||
|
||
namespace VirtualListViewSample; | ||
|
||
public partial class BindableSelectedItemViewModel : ObservableObject | ||
{ | ||
public BindableSelectedItemViewModel(IDispatcher dispatcher) | ||
{ | ||
Dispatcher = dispatcher; | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
Items.Add($"Item: {i}"); | ||
} | ||
|
||
Adapter = new ObservableCollectionAdapter<string>(Items); | ||
} | ||
|
||
protected IDispatcher Dispatcher { get; } | ||
|
||
[ObservableProperty] | ||
ItemPosition? selectedItem; | ||
|
||
[ObservableProperty] | ||
ObservableCollectionAdapter<string> adapter; | ||
|
||
public ObservableCollection<string> Items = new(); | ||
|
||
public void OnAppearing() | ||
{ | ||
Task.Delay(1000).ContinueWith(t => | ||
{ | ||
Dispatcher.Dispatch(() => | ||
{ | ||
Items.Add("Item 11"); | ||
Items.Add("Item 12"); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
public partial class BindableSelectedItemPage : ContentPage | ||
{ | ||
public BindableSelectedItemPage() | ||
{ | ||
InitializeComponent(); | ||
|
||
ViewModel = new BindableSelectedItemViewModel(Dispatcher); | ||
|
||
BindingContext = ViewModel; | ||
} | ||
|
||
public readonly BindableSelectedItemViewModel ViewModel; | ||
|
||
private void Button_Clicked(object sender, EventArgs e) | ||
{ | ||
if (!string.IsNullOrEmpty(entryItem.Text)) | ||
{ | ||
var index = ViewModel.Items.IndexOf(entryItem.Text); | ||
|
||
if (index == ViewModel.SelectedItem?.ItemIndex) | ||
ViewModel.SelectedItem = null; | ||
else if (index >= 0) | ||
ViewModel.SelectedItem = new ItemPosition(0, index); | ||
} | ||
} | ||
|
||
private void vlv_SelectedItemsChanged(object sender, SelectedItemsChangedEventArgs e) | ||
{ | ||
var selection = string.Join(", ", e.NewSelection.Select(i => i.ItemIndex)); | ||
System.Diagnostics.Debug.WriteLine($"SelectedItemsChanged: {selection}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.