Skip to content

Commit

Permalink
Merge pull request #152 from symbiogenesis/multiple-selection
Browse files Browse the repository at this point in the history
Support multiple selection
  • Loading branch information
symbiogenesis authored Jan 16, 2024
2 parents fcf221d + 55709f7 commit fcdc408
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Maui.DataGrid.Sample/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Button Text="Settings" WidthRequest="100" Clicked="OnSettingsClicked" />
</Grid>

<dg:DataGrid Grid.Row="1" ItemsSource="{Binding Teams}" SelectionEnabled="{Binding SelectionEnabled}" SelectedItem="{Binding SelectedTeam}"
<dg:DataGrid Grid.Row="1" ItemsSource="{Binding Teams}" SelectionMode="{Binding SelectionMode}" SelectedItem="{Binding SelectedTeam}"
RowHeight="70" HeaderHeight="50" BorderColor="{StaticResource GridBorderColor}" RowToEdit="{Binding TeamToEdit}"
HeaderBackground="{StaticResource GridHeaderBgColor}" HeaderBordersVisible="{Binding HeaderBordersVisible}"
PullToRefreshCommand="{Binding Commands[Refresh]}" IsRefreshing="{Binding IsRefreshing}"
Expand Down
6 changes: 5 additions & 1 deletion Maui.DataGrid.Sample/Maui.DataGrid.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
Expand Down Expand Up @@ -74,6 +74,10 @@
<EmbeddedResource Include="teams.json" />
</ItemGroup>

<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Maui.DataGrid\Maui.DataGrid.csproj" />
</ItemGroup>
Expand Down
8 changes: 7 additions & 1 deletion Maui.DataGrid.Sample/Platforms/Windows/App.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<maui:MauiWinUIApplication
<maui:MauiWinUIApplication
x:Class="Maui.DataGrid.Sample.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:Maui.DataGrid.Sample.WinUI">

<maui:MauiWinUIApplication.Resources>
<StaticResource x:Key="ListViewItemCheckBrush" ResourceKey="ControlAltFillColorTransparent" />
<StaticResource x:Key="ListViewItemCheckBoxBrush" ResourceKey="ControlAltFillColorTransparent" />
<ListViewItemPresenterCheckMode x:Key="ListViewItemCheckMode">Overlay</ListViewItemPresenterCheckMode>
</maui:MauiWinUIApplication.Resources>

</maui:MauiWinUIApplication>
4 changes: 2 additions & 2 deletions Maui.DataGrid.Sample/SettingsPopup.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<Label Text="Pagination Enabled?" TextColor="White" VerticalOptions="Center" />
</HorizontalStackLayout>
<HorizontalStackLayout Style="{StaticResource SampleContainerStyle}">
<CheckBox IsChecked="{Binding SelectionEnabled}" />
<Label Text="Selection Enabled?" TextColor="White" VerticalOptions="Center" />
<Picker SelectedItem="{Binding SelectionMode}" ItemsSource="{Binding SelectionModes}" />
<Label Text="Selection Mode" TextColor="White" VerticalOptions="Center" />
</HorizontalStackLayout>
<HorizontalStackLayout Style="{StaticResource SampleContainerStyle}">
<Stepper Minimum="0" Maximum="200" Increment="10" Value="{Binding TeamColumnWidth}"
Expand Down
8 changes: 5 additions & 3 deletions Maui.DataGrid.Sample/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ public MainViewModel()
WonColumnVisible = true;
HeaderBordersVisible = true;
PaginationEnabled = true;
SelectionEnabled = true;
TeamColumnWidth = 70;
SelectionMode = SelectionMode.Single;
PageSize = 6;

Commands.Add("CompleteEdit", new Command(CmdCompleteEdit));
Commands.Add("Edit", new Command<Team>(CmdEdit));
Commands.Add("Refresh", new Command(CmdRefresh));
}

public IEnumerable<SelectionMode> SelectionModes => Enum.GetValues<SelectionMode>().Cast<SelectionMode>();

public ObservableCollection<DataGridColumn> Columns { get; set; }

public Team TeamToEdit
Expand Down Expand Up @@ -72,9 +74,9 @@ public bool PaginationEnabled
set => SetValue(value);
}

public bool SelectionEnabled
public SelectionMode SelectionMode
{
get => GetValue<bool>();
get => GetValue<SelectionMode>();
set => SetValue(value);
}

Expand Down
21 changes: 0 additions & 21 deletions Maui.DataGrid/BoolToSelectionModeConverter.cs

This file was deleted.

113 changes: 112 additions & 1 deletion Maui.DataGrid/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:Maui.DataGrid.DataGrid.SelectedItemsProperty</Target>
<Left>lib/net7.0/Maui.DataGrid.dll</Left>
<Right>lib/net7.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:Maui.DataGrid.DataGrid.SelectionModeProperty</Target>
<Left>lib/net7.0/Maui.DataGrid.dll</Left>
<Right>lib/net7.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.get_SelectedItems</Target>
<Left>lib/net7.0/Maui.DataGrid.dll</Left>
<Right>lib/net7.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.get_SelectionEnabled</Target>
<Left>lib/net7.0/Maui.DataGrid.dll</Left>
<Right>lib/net7.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.get_SelectionMode</Target>
<Left>lib/net7.0/Maui.DataGrid.dll</Left>
<Right>lib/net7.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.set_SelectedItems(System.Collections.ObjectModel.ObservableCollection{System.Object})</Target>
<Left>lib/net7.0/Maui.DataGrid.dll</Left>
<Right>lib/net7.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.set_SelectionEnabled(System.Boolean)</Target>
<Left>lib/net7.0/Maui.DataGrid.dll</Left>
<Right>lib/net7.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.set_SelectionMode(Microsoft.Maui.Controls.SelectionMode)</Target>
<Left>lib/net7.0/Maui.DataGrid.dll</Left>
<Right>lib/net7.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:Maui.DataGrid.DataGrid.SelectedItemsProperty</Target>
<Left>lib/net8.0/Maui.DataGrid.dll</Left>
<Right>lib/net8.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:Maui.DataGrid.DataGrid.SelectionModeProperty</Target>
<Left>lib/net8.0/Maui.DataGrid.dll</Left>
<Right>lib/net8.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.get_SelectedItems</Target>
<Left>lib/net8.0/Maui.DataGrid.dll</Left>
<Right>lib/net8.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.get_SelectionEnabled</Target>
<Left>lib/net8.0/Maui.DataGrid.dll</Left>
<Right>lib/net8.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.get_SelectionMode</Target>
<Left>lib/net8.0/Maui.DataGrid.dll</Left>
<Right>lib/net8.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.set_SelectedItems(System.Collections.ObjectModel.ObservableCollection{System.Object})</Target>
<Left>lib/net8.0/Maui.DataGrid.dll</Left>
<Right>lib/net8.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.set_SelectionEnabled(System.Boolean)</Target>
<Left>lib/net8.0/Maui.DataGrid.dll</Left>
<Right>lib/net8.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGrid.set_SelectionMode(Microsoft.Maui.Controls.SelectionMode)</Target>
<Left>lib/net8.0/Maui.DataGrid.dll</Left>
<Right>lib/net8.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
</Suppressions>
8 changes: 4 additions & 4 deletions Maui.DataGrid/DataGrid.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
CompressedLayout.IsHeadless="True">
<ContentView.Resources>
<ResourceDictionary>
<local:BoolToSelectionModeConverter x:Key="boolToSelectionMode" />
<!--Default Header Style-->
<Style x:Key="DefaultHeaderStyle" TargetType="Label">
<Setter Property="FontAttributes" Value="Bold" />
Expand Down Expand Up @@ -43,14 +42,15 @@
<RefreshView Grid.Row="1" x:Name="_refreshView" Grid.RowSpan="2" Command="{Binding PullToRefreshCommand, Source={Reference self}}"
IsRefreshing="{Binding IsRefreshing, Source={Reference self}, Mode=TwoWay}" IsEnabled="{Binding RefreshingEnabled, Source={Reference self}}">
<!-- Set all platforms to use MeasureFirstItem when this bug is resolved https://github.com/dotnet/maui/issues/7562 -->
<CollectionView
<CollectionView
x:Name="_collectionView"
WidthRequest="{Binding WidthRequest, Source={Reference self}}"
BackgroundColor="{Binding BorderColor, Source={Reference self}}"
SelectedItem="{Binding SelectedItem, Source={Reference self}, Mode=TwoWay}"
SelectedItems="{Binding SelectedItems, Source={Reference self}, Mode=TwoWay}"
ItemSizingStrategy="{Binding ItemSizingStrategy, Source={Reference self}}"
SelectionMode="{Binding SelectionEnabled, Source={Reference self}, Converter={StaticResource boolToSelectionMode}}">
<CollectionView.ItemTemplate>
SelectionMode="{Binding SelectionMode, Source={Reference self}}">
<CollectionView.ItemTemplate>
<DataTemplate>
<local:DataGridRow DataGrid="{Reference self}" RowToEdit="{Binding RowToEdit, Source={Reference self}}" HeightRequest="{Binding RowHeight, Source={Reference self}, Mode=OneTime}" />
</DataTemplate>
Expand Down
Loading

0 comments on commit fcdc408

Please sign in to comment.