Skip to content

Commit

Permalink
Fix crash on .NET 9
Browse files Browse the repository at this point in the history
  • Loading branch information
daltzctr committed Sep 11, 2024
1 parent 5d2ec38 commit 1947742
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 70 deletions.
142 changes: 103 additions & 39 deletions Maui.DataGrid.Sample/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,72 +1,136 @@
<?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">
<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]}" />
<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
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}"
SelectionMode="{Binding SelectionMode}">
<dg:DataGrid.Columns>
<dg:DataGridColumn Title="Logo" PropertyName="Logo" SortingEnabled="False">
<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" />
<Image
Aspect="AspectFit"
HeightRequest="60"
HorizontalOptions="Center"
Source="{Binding}"
VerticalOptions="Center" />
</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
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 Text="Home" TextColor="Black" FontSize="13" FontAttributes="Bold" />
<Span Text=" (won-lost)" TextColor="#333333" FontSize="11" />
<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 %" PropertyName="Percentage" Width="0.75*" StringFormat="{}{0:P1}" />
<dg:DataGridColumn Title="Streak" PropertyName="Streak" Width="0.75*">
<dg:DataGridColumn
Title="Win %"
Width="0.75*"
PropertyName="Percentage"
StringFormat="{}{0:P1}" />
<dg:DataGridColumn
Title="Streak"
Width="0.75*"
PropertyName="Streak">
<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
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 PropertyName="." Width="0.75*">
<dg:DataGridColumn Width="0.75*" PropertyName=".">
<dg:DataGridColumn.CellTemplate>
<DataTemplate x:DataType="m:Team">
<Button Text="Edit" BackgroundColor="LightSkyBlue" Command="{Binding BindingContext.Commands[Edit], Source={Reference self}}" CommandParameter="{Binding .}" />
<Button
BackgroundColor="LightSkyBlue"
Command="{Binding BindingContext.Commands[Edit], Source={Reference self}, x:DataType={x:Null}}"
CommandParameter="{Binding .}"
Text="Edit" />
</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 .}" />
<Button
BackgroundColor="MediumSeaGreen"
Command="{Binding BindingContext.Commands[CompleteEdit], Source={Reference self}, x:DataType={x:Null}}"
CommandParameter="{Binding .}"
Text="Done" />
</DataTemplate>
</dg:DataGridColumn.EditCellTemplate>
</dg:DataGridColumn>
Expand Down
102 changes: 71 additions & 31 deletions Maui.DataGrid/DataGrid.xaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentView x:Name="self"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.DataGrid;assembly=Maui.DataGrid"
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
x:Class="Maui.DataGrid.DataGrid"
x:DataType="local:DataGrid"
CompressedLayout.IsHeadless="True">
<?xml version="1.0" encoding="utf-8" ?>
<ContentView
x:Class="Maui.DataGrid.DataGrid"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
xmlns:local="clr-namespace:Maui.DataGrid;assembly=Maui.DataGrid"
x:Name="self"
x:DataType="local:DataGrid"
CompressedLayout.IsHeadless="True">
<ContentView.Resources>
<ResourceDictionary>
<!--Default Header Style-->
<!-- Default Header Style -->
<Style x:Key="DefaultHeaderStyle" TargetType="Label">
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="TextColor" Value="Black" />
<Setter Property="LineBreakMode" Value="TailTruncation" />
</Style>
<!--Default Sort Icon Style-->
<!-- Default Sort Icon Style -->
<Style x:Key="DefaultSortIconStyle" TargetType="Polygon">
<Setter Property="Aspect" Value="Uniform" />
<Setter Property="Fill" Value="Black" />
<Setter Property="Points" Value="50,0 0,80 100,80" />
<Setter Property="Margin" Value="0,0,3,0" />
</Style>
<!--Default Pagination Stepper Style-->
<!-- Default Pagination Stepper Style -->
<Style x:Key="DefaultPaginationStepperStyle" TargetType="Stepper">
<Setter Property="Margin" Value="5" />
<Setter Property="VerticalOptions" Value="Center" />
Expand All @@ -38,38 +39,77 @@
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<local:DataGridHeaderRow Grid.Row="0" x:Name="_headerRow" DataGrid="{Reference self}" HeightRequest="{Binding HeaderHeight, Source={Reference self}}" />
<RefreshView Grid.Row="1" x:Name="_refreshView" Grid.RowSpan="2" Command="{Binding PullToRefreshCommand, Source={Reference self}}" CommandParameter="{Binding PullToRefreshCommandParameter, Source={Reference self}}"
RefreshColor="{Binding RefreshColor, 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 -->
<local:DataGridHeaderRow
x:Name="_headerRow"
Grid.Row="0"
DataGrid="{Reference self}"
HeightRequest="{Binding HeaderHeight, Source={Reference self}}" />
<RefreshView
x:Name="_refreshView"
Grid.Row="1"
Grid.RowSpan="2"
Command="{Binding PullToRefreshCommand, Source={Reference self}}"
CommandParameter="{Binding PullToRefreshCommandParameter, Source={Reference self}}"
IsEnabled="{Binding RefreshingEnabled, Source={Reference self}}"
IsRefreshing="{Binding IsRefreshing, Source={Reference self}, Mode=TwoWay}"
RefreshColor="{Binding RefreshColor, Source={Reference self}}">
<!-- Set all platforms to use MeasureFirstItem when this bug is resolved https://github.com/dotnet/maui/issues/7562 -->
<CollectionView
x:Name="_collectionView"
BackgroundColor="{Binding BackgroundColor, 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 SelectionMode, Source={Reference self}}">
x:Name="_collectionView"
BackgroundColor="{Binding BackgroundColor, Source={Reference self}}"
ItemSizingStrategy="{Binding ItemSizingStrategy, Source={Reference self}}"
SelectedItem="{Binding SelectedItem, Source={Reference self}, Mode=TwoWay}"
SelectedItems="{Binding SelectedItems, Source={Reference self}, Mode=TwoWay}"
SelectionMode="{Binding SelectionMode, Source={Reference self}}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="x:Object">
<local:DataGridRow DataGrid="{Reference self}" RowToEdit="{Binding RowToEdit, Source={Reference self}}" HeightRequest="{Binding RowHeight, Source={Reference self}, Mode=OneTime}" />
<DataTemplate x:DataType="{x:Null}">
<local:DataGridRow
DataGrid="{Reference self}"
HeightRequest="{Binding RowHeight, Source={Reference self}, Mode=OneTime}"
RowToEdit="{Binding RowToEdit, Source={Reference self}}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
<Grid Grid.Row="2" x:Name="_footerView" IsVisible="{Binding PaginationEnabled, Source={Reference self}}" HeightRequest="{Binding FooterHeight, Source={Reference self}}" BackgroundColor="{Binding FooterBackground, Source={Reference self}}">
<Grid
x:Name="_footerView"
Grid.Row="2"
BackgroundColor="{Binding FooterBackground, Source={Reference self}}"
HeightRequest="{Binding FooterHeight, Source={Reference self}}"
IsVisible="{Binding PaginationEnabled, Source={Reference self}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<HorizontalStackLayout VerticalOptions="Center" IsVisible="{Binding PageSizeVisible, Source={Reference self}}">
<Label Text="# per page:" Margin="5,0,0,0" VerticalTextAlignment="Center" TextColor="Black" />
<Picker ItemsSource="{Binding PageSizeList, Source={Reference self}, Mode=TwoWay}" SelectedItem="{Binding PageSize, Source={Reference self}}" TextColor="Black" MinimumWidthRequest="50" ios:Picker.UpdateMode="WhenFinished"/>
<HorizontalStackLayout IsVisible="{Binding PageSizeVisible, Source={Reference self}}" VerticalOptions="Center">
<Label
Margin="5,0,0,0"
Text="# per page:"
TextColor="Black"
VerticalTextAlignment="Center" />
<Picker
ios:Picker.UpdateMode="WhenFinished"
ItemsSource="{Binding PageSizeList, Source={Reference self}, Mode=TwoWay}"
MinimumWidthRequest="50"
SelectedItem="{Binding PageSize, Source={Reference self}}"
TextColor="Black" />
</HorizontalStackLayout>
<HorizontalStackLayout Grid.Column="2" VerticalOptions="Center">
<Label Text="Page:" Margin="0,0,5,0" VerticalTextAlignment="Center" TextColor="Black" />
<Label Text="{Binding PageNumber, Source={Reference self}}" VerticalTextAlignment="Center" TextColor="Black" />
<Stepper x:Name="_paginationStepper" Value="{Binding PageNumber, Source={Reference self}}" Style="{Binding PaginationStepperStyle, Source={Reference self}}" Minimum="1" />
<Label
Margin="0,0,5,0"
Text="Page:"
TextColor="Black"
VerticalTextAlignment="Center" />
<Label
Text="{Binding PageNumber, Source={Reference self}}"
TextColor="Black"
VerticalTextAlignment="Center" />
<Stepper
x:Name="_paginationStepper"
Minimum="1"
Style="{Binding PaginationStepperStyle, Source={Reference self}}"
Value="{Binding PageNumber, Source={Reference self}}" />
</HorizontalStackLayout>
</Grid>
</Grid>
Expand Down

0 comments on commit 1947742

Please sign in to comment.