forked from akgulebubekir/Maui.DataGrid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
akgulebubekir#198 - Add SelectedItems to the example to show the error
@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
1 parent
69886dd
commit e498241
Showing
3 changed files
with
168 additions
and
96 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
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> |
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