Skip to content

Commit

Permalink
akgulebubekir#198 - Add SelectedItems to the example to show the error
Browse files Browse the repository at this point in the history
@symbiogenesis With the SelectedItems bind to IList<object> SelectedTeams and use in the view. The example won't run at all. Only when remove it from the view the example can run again
  • Loading branch information
thunderhead021 committed Aug 7, 2024
1 parent 69886dd commit e498241
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 96 deletions.
232 changes: 149 additions & 83 deletions Maui.DataGrid.Sample/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,88 +1,154 @@
<?xml version="1.0" encoding="utf-8"?>
<?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"
xmlns:dg="clr-namespace:Maui.DataGrid;assembly=Maui.DataGrid"
xmlns:m="clr-namespace:Maui.DataGrid.Sample.Models"
xmlns:vm="clr-namespace:Maui.DataGrid.Sample.ViewModels"
xmlns:conv="clr-namespace:Maui.DataGrid.Sample.Converters"
x:DataType="vm:MainViewModel"
x:Name="self"
x:Class="Maui.DataGrid.Sample.MainPage">
<Grid RowDefinitions="Auto,*">
<ContentPage
x:Class="Maui.DataGrid.Sample.MainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:conv="clr-namespace:Maui.DataGrid.Sample.Converters"
xmlns:dg="clr-namespace:Maui.DataGrid;assembly=Maui.DataGrid"
xmlns:m="clr-namespace:Maui.DataGrid.Sample.Models"
xmlns:vm="clr-namespace:Maui.DataGrid.Sample.ViewModels"
x:Name="self"
x:DataType="vm:MainViewModel">
<Grid RowDefinitions="Auto,*">

<HorizontalStackLayout HorizontalOptions="Center">
<Button Text="Settings" WidthRequest="100" Command="{Binding Commands[Settings]}" />
<Button Text="Remove Team" WidthRequest="140" Command="{Binding Commands[RemoveTeam]}" />
</HorizontalStackLayout>
<HorizontalStackLayout HorizontalOptions="Center">
<Button
Command="{Binding Commands[Settings]}"
Text="Settings"
WidthRequest="100" />
<Button
Command="{Binding Commands[RemoveTeam]}"
Text="Remove Team"
WidthRequest="140" />
</HorizontalStackLayout>

<dg:DataGrid Grid.Row="1" ItemsSource="{Binding Teams}" SelectionMode="{Binding SelectionMode}"
SelectedItem="{Binding SelectedTeam}" RowToEdit="{Binding TeamToEdit}" RefreshingEnabled="{Binding RefreshingEnabled}"
BorderColor="{StaticResource GridBorderColor}" BorderThickness="{Binding BorderThickness}"
HeaderBackground="{StaticResource GridHeaderBgColor}" HeaderBordersVisible="{Binding HeaderBordersVisible}"
BackgroundColor="{StaticResource GridBgColor}" ActiveRowColor="{StaticResource ActiveRowColor}"
FooterBackground="{StaticResource GridFooterBgColor}"
PaginationEnabled="{Binding PaginationEnabled}" PageSize="{Binding PageSize}"
PullToRefreshCommand="{Binding Commands[Refresh]}" IsRefreshing="{Binding IsRefreshing}"
RowHeight="70" HeaderHeight="50" x:Name="_dataGrid1"
RowTappedCommand="{Binding Commands[Tapped]}">
<dg:DataGrid.Columns>
<dg:DataGridColumn Title="Logo" PropertyName="Logo" SortingEnabled="False">
<dg:DataGridColumn.CellTemplate>
<DataTemplate x:DataType="x:String">
<Image Source="{Binding}" HorizontalOptions="Center" VerticalOptions="Center"
Aspect="AspectFit" HeightRequest="60" />
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<dg:DataGridColumn Title="Team" PropertyName="Name" IsVisible="{Binding TeamColumnVisible}" Width="{Binding TeamColumnWidth}" />
<dg:DataGridColumn Title="Won" PropertyName="Won" Width="0.5*" IsVisible="{Binding WonColumnVisible}" />
<dg:DataGridColumn Title="Lost" PropertyName="Lost" Width="0.5*" />
<dg:DataGridColumn PropertyName="Home">
<dg:DataGridColumn.FormattedTitle>
<FormattedString>
<Span Text="Home" TextColor="Black" FontSize="13" FontAttributes="Bold" />
<Span Text=" (won-lost)" TextColor="#333333" FontSize="11" />
</FormattedString>
</dg:DataGridColumn.FormattedTitle>
</dg:DataGridColumn>
<dg:DataGridColumn Title="Win %" PropertyName="Percentage" Width="0.75*" StringFormat="{}{0:P1}" />
<dg:DataGridColumn Title="Streak" PropertyName="Streak" Width="0.75*">
<dg:DataGridColumn.CellTemplate>
<DataTemplate x:DataType="m:Streak">
<ContentView HorizontalOptions="Fill" VerticalOptions="Fill"
BackgroundColor="{Binding Converter={StaticResource StreakToColorConverter}}">
<Label Text="{Binding}" HorizontalOptions="Center" VerticalOptions="Center"
TextColor="Black" />
</ContentView>
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<dg:DataGridColumn PropertyName="." Width="0.75*">
<dg:DataGridColumn.CellTemplate>
<DataTemplate x:DataType="m:Team">
<Button Text="Edit" BackgroundColor="LightSkyBlue" Command="{Binding BindingContext.Commands[Edit], Source={Reference self}}" CommandParameter="{Binding .}" />
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
<dg:DataGridColumn.EditCellTemplate>
<DataTemplate x:DataType="m:Team">
<Button Text="Done" BackgroundColor="MediumSeaGreen" Command="{Binding BindingContext.Commands[CompleteEdit], Source={Reference self}}" CommandParameter="{Binding .}" />
</DataTemplate>
</dg:DataGridColumn.EditCellTemplate>
</dg:DataGridColumn>
</dg:DataGrid.Columns>
<dg:DataGrid.RowsBackgroundColorPalette>
<dg:PaletteCollection>
<Color>#F2F2F2</Color>
<Color>#FFFFFF</Color>
</dg:PaletteCollection>
</dg:DataGrid.RowsBackgroundColorPalette>
<dg:DataGrid.Resources>
<ResourceDictionary>
<conv:StreakToColorConverter x:Key="StreakToColorConverter" />
</ResourceDictionary>
</dg:DataGrid.Resources>
</dg:DataGrid>
</Grid>
<dg:DataGrid
x:Name="_dataGrid1"
Grid.Row="1"
ActiveRowColor="{StaticResource ActiveRowColor}"
BackgroundColor="{StaticResource GridBgColor}"
BorderColor="{StaticResource GridBorderColor}"
BorderThickness="{Binding BorderThickness}"
FooterBackground="{StaticResource GridFooterBgColor}"
HeaderBackground="{StaticResource GridHeaderBgColor}"
HeaderBordersVisible="{Binding HeaderBordersVisible}"
HeaderHeight="50"
IsRefreshing="{Binding IsRefreshing}"
ItemsSource="{Binding Teams}"
PageSize="{Binding PageSize}"
PaginationEnabled="{Binding PaginationEnabled}"
PullToRefreshCommand="{Binding Commands[Refresh]}"
RefreshingEnabled="{Binding RefreshingEnabled}"
RowHeight="70"
RowTappedCommand="{Binding Commands[Tapped]}"
RowToEdit="{Binding TeamToEdit}"
SelectedItem="{Binding SelectedTeam}"
SelectedItems="{Binding SelectedTeams}"
SelectionMode="{Binding SelectionMode}">
<dg:DataGrid.Columns>
<dg:DataGridColumn
Title="Logo"
PropertyName="Logo"
SortingEnabled="False">
<dg:DataGridColumn.CellTemplate>
<DataTemplate x:DataType="x:String">
<Image
Aspect="AspectFit"
HeightRequest="60"
HorizontalOptions="Center"
Source="{Binding}"
VerticalOptions="Center" />
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<dg:DataGridColumn
Title="Team"
Width="{Binding TeamColumnWidth}"
IsVisible="{Binding TeamColumnVisible}"
PropertyName="Name" />
<dg:DataGridColumn
Title="Won"
Width="0.5*"
IsVisible="{Binding WonColumnVisible}"
PropertyName="Won" />
<dg:DataGridColumn
Title="Lost"
Width="0.5*"
PropertyName="Lost" />
<dg:DataGridColumn PropertyName="Home">
<dg:DataGridColumn.FormattedTitle>
<FormattedString>
<Span
FontAttributes="Bold"
FontSize="13"
Text="Home"
TextColor="Black" />
<Span
FontSize="11"
Text=" (won-lost)"
TextColor="#333333" />
</FormattedString>
</dg:DataGridColumn.FormattedTitle>
</dg:DataGridColumn>
<dg:DataGridColumn
Title="Win %"
Width="0.75*"
PropertyName="Percentage"
StringFormat="{}{0:P1}" />
<dg:DataGridColumn
Title="Streak"
Width="0.75*"
PropertyName="Streak"
SortingEnabled="True">
<dg:DataGridColumn.CellTemplate>
<DataTemplate x:DataType="m:Streak">
<ContentView
BackgroundColor="{Binding Converter={StaticResource StreakToColorConverter}}"
HorizontalOptions="Fill"
VerticalOptions="Fill">
<Label
HorizontalOptions="Center"
Text="{Binding}"
TextColor="Black"
VerticalOptions="Center" />
</ContentView>
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<dg:DataGridColumn Width="0.75*" PropertyName=".">
<dg:DataGridColumn.CellTemplate>
<DataTemplate x:DataType="m:Team">
<Button
BackgroundColor="LightSkyBlue"
Command="{Binding BindingContext.Commands[Edit], Source={Reference self}}"
CommandParameter="{Binding .}"
Text="Edit" />
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
<dg:DataGridColumn.EditCellTemplate>
<DataTemplate x:DataType="m:Team">
<Button
BackgroundColor="MediumSeaGreen"
Command="{Binding BindingContext.Commands[CompleteEdit], Source={Reference self}}"
CommandParameter="{Binding .}"
Text="Done" />
</DataTemplate>
</dg:DataGridColumn.EditCellTemplate>
</dg:DataGridColumn>
</dg:DataGrid.Columns>
<dg:DataGrid.RowsBackgroundColorPalette>
<dg:PaletteCollection>
<Color>#F2F2F2</Color>
<Color>#FFFFFF</Color>
</dg:PaletteCollection>
</dg:DataGrid.RowsBackgroundColorPalette>
<dg:DataGrid.Resources>
<ResourceDictionary>
<conv:StreakToColorConverter x:Key="StreakToColorConverter" />
</ResourceDictionary>
</dg:DataGrid.Resources>
</dg:DataGrid>
</Grid>

</ContentPage>
6 changes: 6 additions & 0 deletions Maui.DataGrid.Sample/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ public Team? SelectedTeam
set => SetValue(value);
}

public IList<object> SelectedTeams
{
get => GetValue<IList<object>>();
set => SetValue(value);
}

public bool IsRefreshing
{
get => GetValue<bool>();
Expand Down
26 changes: 13 additions & 13 deletions Maui.DataGrid.Sample/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[8.0.7, )",
"resolved": "8.0.7",
"contentHash": "iI52ptEKby2ymQ6B7h4TWbFmm85T4VvLgc/HvS45Yr3lgi4IIFbQtjON3bQbX/Vc94jXNSLvrDOp5Kh7SJyFYQ=="
"requested": "[8.0.6, )",
"resolved": "8.0.6",
"contentHash": "E+lDylsTeP4ZiDmnEkiJ5wobnGaIJzFhOgZppznJCb69UZgbh6G3cfv1pnLDLLBx6JAgl0kAlnINDeT3uCuczQ=="
},
"Shiny.Xunit.Runners.Maui": {
"type": "Direct",
Expand Down Expand Up @@ -1553,7 +1553,7 @@
"contentHash": "t2Tmu6Y2NtJ2um0RtcuhP7ZdNNxXEgUm2JeoA/0NvlMjAhKCnM1NX07TDl3244mVp3QU6LPEhT3HTtH1uF7IYw=="
}
},
"net8.0-android34.0/ios-arm64": {
"net8.0-android34.0/iossimulator-x64": {
"System.IO.Compression": {
"type": "Transitive",
"resolved": "4.3.0",
Expand Down Expand Up @@ -1693,9 +1693,9 @@
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[8.0.7, )",
"resolved": "8.0.7",
"contentHash": "iI52ptEKby2ymQ6B7h4TWbFmm85T4VvLgc/HvS45Yr3lgi4IIFbQtjON3bQbX/Vc94jXNSLvrDOp5Kh7SJyFYQ=="
"requested": "[8.0.6, )",
"resolved": "8.0.6",
"contentHash": "E+lDylsTeP4ZiDmnEkiJ5wobnGaIJzFhOgZppznJCb69UZgbh6G3cfv1pnLDLLBx6JAgl0kAlnINDeT3uCuczQ=="
},
"Shiny.Xunit.Runners.Maui": {
"type": "Direct",
Expand Down Expand Up @@ -6281,7 +6281,7 @@
}
}
},
"net8.0-ios17.2/ios-arm64": {
"net8.0-ios17.2/iossimulator-x64": {
"Microsoft.Win32.Primitives": {
"type": "Transitive",
"resolved": "4.3.0",
Expand Down Expand Up @@ -8912,9 +8912,9 @@
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[8.0.7, )",
"resolved": "8.0.7",
"contentHash": "iI52ptEKby2ymQ6B7h4TWbFmm85T4VvLgc/HvS45Yr3lgi4IIFbQtjON3bQbX/Vc94jXNSLvrDOp5Kh7SJyFYQ=="
"requested": "[8.0.6, )",
"resolved": "8.0.6",
"contentHash": "E+lDylsTeP4ZiDmnEkiJ5wobnGaIJzFhOgZppznJCb69UZgbh6G3cfv1pnLDLLBx6JAgl0kAlnINDeT3uCuczQ=="
},
"Shiny.Xunit.Runners.Maui": {
"type": "Direct",
Expand Down Expand Up @@ -13500,7 +13500,7 @@
}
}
},
"net8.0-maccatalyst17.2/ios-arm64": {
"net8.0-maccatalyst17.2/iossimulator-x64": {
"Microsoft.Win32.Primitives": {
"type": "Transitive",
"resolved": "4.3.0",
Expand Down Expand Up @@ -20837,7 +20837,7 @@
}
}
},
"net8.0-windows10.0.22621/ios-arm64": {
"net8.0-windows10.0.22621/iossimulator-x64": {
"Microsoft.Graphics.Win2D": {
"type": "Transitive",
"resolved": "1.2.0",
Expand Down

0 comments on commit e498241

Please sign in to comment.