Skip to content

Commit

Permalink
Added localization support for pagination and # per page customization
Browse files Browse the repository at this point in the history
  • Loading branch information
goodguyjay committed Oct 25, 2024
1 parent 4f075fe commit 694e7c7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Maui.DataGrid.Sample/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
HeaderBackground="{StaticResource GridHeaderBgColor}" HeaderBordersVisible="{Binding HeaderBordersVisible}"
BackgroundColor="{StaticResource GridBgColor}" ActiveRowColor="{StaticResource ActiveRowColor}"
FooterBackground="{StaticResource GridFooterBgColor}" SortedColumnIndex="1"
PaginationEnabled="{Binding PaginationEnabled}" PageSize="{Binding PageSize}"
PaginationEnabled="{Binding PaginationEnabled}" PageSize="{Binding PageSize}" PageText="{Binding PaginationText}" PerPageText="{Binding PerPageText}"
PullToRefreshCommand="{Binding Commands[Refresh]}" IsRefreshing="{Binding IsRefreshing}"
RowHeight="70" HeaderHeight="75" x:Name="_dataGrid1"
RowTappedCommand="{Binding Commands[Tapped]}">
Expand Down
14 changes: 14 additions & 0 deletions Maui.DataGrid.Sample/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public MainViewModel()
SelectionMode = SelectionMode.Single;
PageSize = 6;
BorderThicknessNumeric = 2;
PaginationText = "Page: ";
PerPageText = "# per page: ";

Commands.Add("CompleteEdit", new Command(CmdCompleteEdit));
Commands.Add("Edit", new Command<Team>(CmdEdit));
Expand Down Expand Up @@ -105,6 +107,18 @@ public bool PaginationEnabled
set => SetValue(value);
}

public string PaginationText
{
get => GetValue<string>() ?? "Page:";
set => SetValue(value);
}

public string PerPageText
{
get => GetValue<string>() ?? "# per page:";
set => SetValue(value);
}

public bool RefreshingEnabled
{
get => GetValue<bool>();
Expand Down
4 changes: 2 additions & 2 deletions Maui.DataGrid/DataGrid.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
<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" />
<Label Text="{Binding PerPageText, Source={Reference self}}" 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>
<HorizontalStackLayout Grid.Column="2" VerticalOptions="Center">
<Label Text="Page:" Margin="0,0,5,0" VerticalTextAlignment="Center" TextColor="Black" />
<Label Text="{Binding PageText, Source={Reference self}}" 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" />
</HorizontalStackLayout>
Expand Down
46 changes: 46 additions & 0 deletions Maui.DataGrid/DataGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,34 @@ public partial class DataGrid
}
});

/// <summary>
/// Gets or sets the text for the page label in the DataGrid.
/// </summary>
public static readonly BindableProperty PageTextProperty =
BindablePropertyExtensions.Create<DataGrid, string>(
defaultValue: "Page:",
propertyChanged: (b, _, _) =>
{
if (b is DataGrid self)
{
self.OnPropertyChanged(nameof(PageText));
}
});

/// <summary>
/// Gets or sets the localized text for the per page label.
/// </summary>
public static readonly BindableProperty PerPageTextProperty =
BindablePropertyExtensions.Create<DataGrid, string>(
defaultValue: "# per page:",
propertyChanged: (b, _, _) =>
{
if (b is DataGrid self)
{
self.OnPropertyChanged(nameof(PerPageText));
}
});

/// <summary>
/// Gets or sets the page count for the DataGrid.
/// </summary>
Expand Down Expand Up @@ -1129,6 +1157,24 @@ private set
}
}

/// <summary>
/// Gets or sets the customized text for the 'Page' label in the pagination section.
/// </summary>
public string PageText
{
get => (string)GetValue(PageTextProperty);
set => SetValue(PageTextProperty, value);
}

/// <summary>
/// Gets or sets the customized text for the 'Per Page' label in the pagination section.
/// </summary>
public string PerPageText
{
get => (string)GetValue(PerPageTextProperty);
set => SetValue(PerPageTextProperty, value);
}

internal Style DefaultHeaderLabelStyle { get; }

internal Style DefaultHeaderFilterStyle { get; }
Expand Down

0 comments on commit 694e7c7

Please sign in to comment.