diff --git a/controlgallery/AtomUIGallery/ShowCases/Views/DataEntry/TransferShowCase.axaml b/controlgallery/AtomUIGallery/ShowCases/Views/DataEntry/TransferShowCase.axaml index d32a05aa2..0721559e0 100644 --- a/controlgallery/AtomUIGallery/ShowCases/Views/DataEntry/TransferShowCase.axaml +++ b/controlgallery/AtomUIGallery/ShowCases/Views/DataEntry/TransferShowCase.axaml @@ -76,7 +76,8 @@ + IsPaginationEnabled="True" + ListHeight="370"/> diff --git a/src/AtomUI.Desktop.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.TokenResourceKeyGenerator/TokenResourceConst.g.cs b/src/AtomUI.Desktop.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.TokenResourceKeyGenerator/TokenResourceConst.g.cs index 6ed95060c..2d0e07897 100644 --- a/src/AtomUI.Desktop.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.TokenResourceKeyGenerator/TokenResourceConst.g.cs +++ b/src/AtomUI.Desktop.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.TokenResourceKeyGenerator/TokenResourceConst.g.cs @@ -1170,6 +1170,7 @@ namespace AtomUI.Desktop.Controls.DesignTokens public static readonly TokenResourceKey ListHeight = new TokenResourceKey("AtomUI.Desktop.Controls.Transfer.ListHeight"); public static readonly TokenResourceKey ListWidth = new TokenResourceKey("AtomUI.Desktop.Controls.Transfer.ListWidth"); public static readonly TokenResourceKey ListWidthLG = new TokenResourceKey("AtomUI.Desktop.Controls.Transfer.ListWidthLG"); + public static readonly TokenResourceKey PaginationMargin = new TokenResourceKey("AtomUI.Desktop.Controls.Transfer.PaginationMargin"); } public static class TreeSelectTokenKey diff --git a/src/AtomUI.Desktop.Controls/ListView/ListView.Pagination.cs b/src/AtomUI.Desktop.Controls/ListView/ListView.Pagination.cs index be1a79c46..344089a9e 100644 --- a/src/AtomUI.Desktop.Controls/ListView/ListView.Pagination.cs +++ b/src/AtomUI.Desktop.Controls/ListView/ListView.Pagination.cs @@ -77,7 +77,6 @@ public partial class ListView _topPaginationDisposables.Add(BindUtils.RelayBind(this, TopPaginationAlignProperty, newPagination, AbstractPagination.AlignProperty)); _topPaginationDisposables.Add(BindUtils.RelayBind(this, IsHideOnSinglePageProperty, newPagination, AbstractPagination.IsHideOnSinglePageProperty)); _topPaginationDisposables.Add(BindUtils.RelayBind(this, IsEnabledProperty, newPagination, AbstractPagination.IsEnabledProperty)); - _topPaginationDisposables.Add(BindUtils.RelayBind(this, SizeTypeProperty, newPagination, AbstractPagination.SizeTypeProperty)); _topPaginationDisposables.Add(BindUtils.RelayBind(this, IsMotionEnabledProperty, newPagination, AbstractPagination.IsMotionEnabledProperty)); _topPaginationDisposables.Add(BindUtils.RelayBind(this, PaginationVisibilityProperty, newPagination, AbstractPagination.IsMotionEnabledProperty)); _topPagination = newPagination; @@ -97,10 +96,9 @@ public partial class ListView { newPagination.CurrentPageChanged += HandlePageChangeRequest; _bottomPaginationDisposables = new CompositeDisposable(); - _bottomPaginationDisposables.Add(BindUtils.RelayBind(this, TopPaginationAlignProperty, newPagination, AbstractPagination.AlignProperty)); + _bottomPaginationDisposables.Add(BindUtils.RelayBind(this, BottomPaginationAlignProperty, newPagination, AbstractPagination.AlignProperty)); _bottomPaginationDisposables.Add(BindUtils.RelayBind(this, IsHideOnSinglePageProperty, newPagination, AbstractPagination.IsHideOnSinglePageProperty)); _bottomPaginationDisposables.Add(BindUtils.RelayBind(this, IsEnabledProperty, newPagination, AbstractPagination.IsEnabledProperty)); - _bottomPaginationDisposables.Add(BindUtils.RelayBind(this, SizeTypeProperty, newPagination, AbstractPagination.SizeTypeProperty)); _bottomPaginationDisposables.Add(BindUtils.RelayBind(this, IsMotionEnabledProperty, newPagination, AbstractPagination.IsMotionEnabledProperty)); _bottomPaginationDisposables.Add(BindUtils.RelayBind(this, PaginationVisibilityProperty, newPagination, AbstractPagination.IsMotionEnabledProperty)); _bottomPagination = newPagination; diff --git a/src/AtomUI.Desktop.Controls/ListView/ListViewSelectionModel.cs b/src/AtomUI.Desktop.Controls/ListView/ListViewSelectionModel.cs index 4f3fa8ecd..1a58a8cd3 100644 --- a/src/AtomUI.Desktop.Controls/ListView/ListViewSelectionModel.cs +++ b/src/AtomUI.Desktop.Controls/ListView/ListViewSelectionModel.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Specialized; using System.Diagnostics.CodeAnalysis; using AtomUI.Collections; -using AtomUI.Controls.Data; using AtomUI.Desktop.Controls.Primitives; using Avalonia; using Avalonia.Collections; @@ -356,7 +355,7 @@ internal class ListViewSelectionModel : SelectionModel, ISelectionModel { return l.IndexOf(item); } - else if (source is ItemsSourceView v) + if (source is ItemsSourceView v) { return v.IndexOf(item); } diff --git a/src/AtomUI.Desktop.Controls/ListView/Themes/ListViewTheme.axaml b/src/AtomUI.Desktop.Controls/ListView/Themes/ListViewTheme.axaml index 66e629511..2d2761a9f 100644 --- a/src/AtomUI.Desktop.Controls/ListView/Themes/ListViewTheme.axaml +++ b/src/AtomUI.Desktop.Controls/ListView/Themes/ListViewTheme.axaml @@ -111,6 +111,7 @@ + diff --git a/src/AtomUI.Desktop.Controls/Pagination/AbstractPagination.cs b/src/AtomUI.Desktop.Controls/Pagination/AbstractPagination.cs index f5d369665..882474b89 100644 --- a/src/AtomUI.Desktop.Controls/Pagination/AbstractPagination.cs +++ b/src/AtomUI.Desktop.Controls/Pagination/AbstractPagination.cs @@ -97,17 +97,17 @@ public abstract class AbstractPagination : TemplatedControl, ISizeTypeAware, IMo #region 内部属性定义 - internal static readonly DirectProperty IsEffectiveHideOnSinglePageVisibleProperty = + internal static readonly DirectProperty IsEffectiveVisibleProperty = AvaloniaProperty.RegisterDirect( - nameof(IsEffectiveHideOnSinglePageVisible), - o => o.IsEffectiveHideOnSinglePageVisible, - (o, v) => o.IsEffectiveHideOnSinglePageVisible = v); + nameof(IsEffectiveVisible), + o => o.IsEffectiveVisible, + (o, v) => o.IsEffectiveVisible = v); - private bool _isEffectiveHideOnSinglePageVisible = false; - internal bool IsEffectiveHideOnSinglePageVisible + private bool _isEffectiveVisible = false; + internal bool IsEffectiveVisible { - get => _isEffectiveHideOnSinglePageVisible; - set => SetAndRaise(IsEffectiveHideOnSinglePageVisibleProperty, ref _isEffectiveHideOnSinglePageVisible, value); + get => _isEffectiveVisible; + set => SetAndRaise(IsEffectiveVisibleProperty, ref _isEffectiveVisible, value); } private static bool PageSizeValidator(int pageSize) @@ -135,15 +135,23 @@ public abstract class AbstractPagination : TemplatedControl, ISizeTypeAware, IMo HandlePageConditionChanged(); } if (change.Property == IsHideOnSinglePageProperty || - change.Property == PageCountProperty) + change.Property == PageCountProperty || + change.Property == TotalProperty) { - if (IsHideOnSinglePage) + if (Total > 0) { - SetValue(IsEffectiveHideOnSinglePageVisibleProperty, PageCount > 1); + if (IsHideOnSinglePage) + { + SetValue(IsEffectiveVisibleProperty, PageCount > 1); + } + else + { + SetValue(IsEffectiveVisibleProperty, true); + } } else { - SetValue(IsEffectiveHideOnSinglePageVisibleProperty, true); + SetValue(IsEffectiveVisibleProperty, false); } } } diff --git a/src/AtomUI.Desktop.Controls/Pagination/QuickJumpEdit.cs b/src/AtomUI.Desktop.Controls/Pagination/QuickJumpEdit.cs new file mode 100644 index 000000000..f320a9db2 --- /dev/null +++ b/src/AtomUI.Desktop.Controls/Pagination/QuickJumpEdit.cs @@ -0,0 +1,60 @@ +using Avalonia; +using Avalonia.Input; + +namespace AtomUI.Desktop.Controls; + +internal class QuickJumpEdit : LineEdit +{ + public static readonly StyledProperty MinimumProperty = + AvaloniaProperty.Register(nameof(Minimum), 1); + + public static readonly StyledProperty MaximumProperty = + AvaloniaProperty.Register(nameof(Maximum), int.MaxValue); + + public int Minimum + { + get => GetValue(MinimumProperty); + set => SetValue(MinimumProperty, value); + } + + public int Maximum + { + get => GetValue(MaximumProperty); + set => SetValue(MaximumProperty, value); + } + + protected override Type StyleKeyOverride => typeof(LineEdit); + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + if (change.Property == TextProperty) + { + if (int.TryParse(Text, out var pageNumber)) + { + if (pageNumber < Minimum) + { + SetCurrentValue(TextProperty, Minimum.ToString()); + } + + if (pageNumber > Maximum) + { + SetCurrentValue(TextProperty, Maximum.ToString()); + } + } + } + } + + protected override void OnTextInput(TextInputEventArgs e) + { + var inputText = e.Text?.Trim(); + if (!string.IsNullOrEmpty(inputText) && inputText.All(char.IsDigit)) + { + base.OnTextInput(e); + } + else + { + e.Handled = true; + } + } +} \ No newline at end of file diff --git a/src/AtomUI.Desktop.Controls/Pagination/SimplePagination.cs b/src/AtomUI.Desktop.Controls/Pagination/SimplePagination.cs index e9cc31ce5..768f3a428 100644 --- a/src/AtomUI.Desktop.Controls/Pagination/SimplePagination.cs +++ b/src/AtomUI.Desktop.Controls/Pagination/SimplePagination.cs @@ -35,7 +35,7 @@ public class SimplePagination : AbstractPagination, IControlSharedTokenResources private PaginationNavItem? _previousPageItem; private PaginationNavItem? _nextPageItem; private TextBlock? _infoIndicator; - private LineEdit? _quickJumper; + private QuickJumpEdit? _quickJumper; static SimplePagination() { @@ -53,7 +53,7 @@ public class SimplePagination : AbstractPagination, IControlSharedTokenResources _previousPageItem = e.NameScope.Find(SimplePaginationThemeConstants.PreviousNavItemPart); _nextPageItem = e.NameScope.Find(SimplePaginationThemeConstants.NextNavItemPart); _infoIndicator = e.NameScope.Find(SimplePaginationThemeConstants.InfoIndicatorPart); - _quickJumper = e.NameScope.Find(SimplePaginationThemeConstants.QuickJumperPart); + _quickJumper = e.NameScope.Find(SimplePaginationThemeConstants.QuickJumperPart); Debug.Assert(_nextPageItem != null); Debug.Assert(_previousPageItem != null); @@ -96,10 +96,25 @@ public class SimplePagination : AbstractPagination, IControlSharedTokenResources _nextPageItem.IsEnabled = currentPage < pageCount; _nextPageItem.PageNumber = Math.Min(pageCount, CurrentPage + 1); } - + if (_quickJumper != null) + { + _quickJumper.Maximum = PageCount; + } base.NotifyPageConditionChanged(currentPage, pageCount, pageSize, total); } - + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + if (change.Property == PageCountProperty) + { + if (_quickJumper != null) + { + _quickJumper.Maximum = PageCount; + } + } + } + private void HandleNavItemClicked(object? sender, RoutedEventArgs args) { if (sender is PaginationNavItem navItemSender) @@ -111,7 +126,7 @@ public class SimplePagination : AbstractPagination, IControlSharedTokenResources private void HandleLineEditKeyUp(object? sender, KeyEventArgs e) { - if (sender is LineEdit lineEdit) + if (sender is QuickJumpEdit lineEdit) { if (e.Key == Key.Enter) { @@ -120,10 +135,6 @@ public class SimplePagination : AbstractPagination, IControlSharedTokenResources var pageCount = (int)Math.Ceiling(Total / (double)PageSize); CurrentPage = Math.Max(1, Math.Min(pageNumber, pageCount)); } - else - { - lineEdit.Text = $"{CurrentPage}"; - } } } } diff --git a/src/AtomUI.Desktop.Controls/Pagination/Themes/PaginationNavItemTheme.axaml b/src/AtomUI.Desktop.Controls/Pagination/Themes/PaginationNavItemTheme.axaml index 3a1cb67dc..ca1fcda27 100644 --- a/src/AtomUI.Desktop.Controls/Pagination/Themes/PaginationNavItemTheme.axaml +++ b/src/AtomUI.Desktop.Controls/Pagination/Themes/PaginationNavItemTheme.axaml @@ -136,6 +136,10 @@ + + diff --git a/src/AtomUI.Desktop.Controls/Pagination/Themes/PaginationTheme.axaml b/src/AtomUI.Desktop.Controls/Pagination/Themes/PaginationTheme.axaml index 211fa168d..12af59c53 100644 --- a/src/AtomUI.Desktop.Controls/Pagination/Themes/PaginationTheme.axaml +++ b/src/AtomUI.Desktop.Controls/Pagination/Themes/PaginationTheme.axaml @@ -10,7 +10,7 @@ + IsVisible="{TemplateBinding IsEffectiveVisible}"> diff --git a/src/AtomUI.Desktop.Controls/Pagination/Themes/SimplePaginationTheme.axaml b/src/AtomUI.Desktop.Controls/Pagination/Themes/SimplePaginationTheme.axaml index 6e6f39f3e..1a0efb2eb 100644 --- a/src/AtomUI.Desktop.Controls/Pagination/Themes/SimplePaginationTheme.axaml +++ b/src/AtomUI.Desktop.Controls/Pagination/Themes/SimplePaginationTheme.axaml @@ -9,18 +9,20 @@ + Orientation="Horizontal" + IsVisible="{TemplateBinding IsEffectiveVisible}"> - + - - - - + diff --git a/src/AtomUI.Desktop.Controls/Transfer/Themes/TransferListViewTheme.axaml b/src/AtomUI.Desktop.Controls/Transfer/Themes/TransferListViewTheme.axaml index 5a6b60f5a..f08178dbd 100644 --- a/src/AtomUI.Desktop.Controls/Transfer/Themes/TransferListViewTheme.axaml +++ b/src/AtomUI.Desktop.Controls/Transfer/Themes/TransferListViewTheme.axaml @@ -5,54 +5,20 @@ x:ClassModifier="internal"> - + - - - - - - - - - - - - - - - - - + + + + + + + \ No newline at end of file diff --git a/src/AtomUI.Desktop.Controls/Transfer/Transfer.cs b/src/AtomUI.Desktop.Controls/Transfer/Transfer.cs index bd02959e1..9d48c14af 100644 --- a/src/AtomUI.Desktop.Controls/Transfer/Transfer.cs +++ b/src/AtomUI.Desktop.Controls/Transfer/Transfer.cs @@ -549,7 +549,8 @@ public class Transfer : TemplatedControl, .Where(item => !(TargetKeys?.Contains(item.ItemKey ?? default) ?? false)) .Where(item => !IsFilterEnabled || string.IsNullOrEmpty(SourceFilterValue) || (Filter?.Filter(FilterValueSelector != null ? FilterValueSelector(item) : item, - SourceFilterValue) ?? false)); + SourceFilterValue) ?? false)) + .ToArray(); } if (changeType.HasFlag(FilterChangeType.Target)) @@ -557,7 +558,8 @@ public class Transfer : TemplatedControl, TargetPanelSource = ItemsSource? .Where(item => TargetKeys?.Contains(item.ItemKey ?? default) ?? false) .Where(item => !IsFilterEnabled || string.IsNullOrEmpty(TargetFilterValue) || - (Filter?.Filter(FilterValueSelector != null ? FilterValueSelector(item) : item, TargetFilterValue) ?? false)); + (Filter?.Filter(FilterValueSelector != null ? FilterValueSelector(item) : item, TargetFilterValue) ?? false)) + .ToArray(); } } diff --git a/src/AtomUI.Desktop.Controls/Transfer/TransferListItem.cs b/src/AtomUI.Desktop.Controls/Transfer/TransferListItem.cs index c1914f0cc..7f4467081 100644 --- a/src/AtomUI.Desktop.Controls/Transfer/TransferListItem.cs +++ b/src/AtomUI.Desktop.Controls/Transfer/TransferListItem.cs @@ -2,7 +2,7 @@ using Avalonia; namespace AtomUI.Desktop.Controls; -public class TransferListItem : ListBoxItem +public class TransferListItem : ListViewItem { #region 内部属性定义 internal static readonly DirectProperty IsCheckableProperty = diff --git a/src/AtomUI.Desktop.Controls/Transfer/TransferListView.cs b/src/AtomUI.Desktop.Controls/Transfer/TransferListView.cs index 749ec9d0e..dee2b88b7 100644 --- a/src/AtomUI.Desktop.Controls/Transfer/TransferListView.cs +++ b/src/AtomUI.Desktop.Controls/Transfer/TransferListView.cs @@ -1,11 +1,8 @@ using System.Collections; -using System.Diagnostics; using System.Reactive.Disposables; using AtomUI.Controls; using AtomUI.Controls.Data; using AtomUI.Data; -using AtomUI.Desktop.Controls.Primitives; -using AtomUI.Utils; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; @@ -15,10 +12,9 @@ using VirtualizingStackPanel = Avalonia.Controls.VirtualizingStackPanel; namespace AtomUI.Desktop.Controls; -public class TransferListView : ListBox, ITransferView +public class TransferListView : ListView, ITransferView { #region 公共属性定义 - public static readonly DirectProperty?> SelectedKeysProperty = AvaloniaProperty.RegisterDirect?>(nameof(SelectedKeys), o => o.SelectedKeys, @@ -31,9 +27,6 @@ public class TransferListView : ListBox, ITransferView public static readonly StyledProperty IsPaginationEnabledProperty = Transfer.IsPaginationEnabledProperty.AddOwner(); - - public static readonly StyledProperty PageSizeProperty = - Transfer.PageSizeProperty.AddOwner(); private IList? _selectedKeys; public IList? SelectedKeys @@ -54,12 +47,6 @@ public class TransferListView : ListBox, ITransferView get => GetValue(IsPaginationEnabledProperty); set => SetValue(IsPaginationEnabledProperty, value); } - - public int PageSize - { - get => GetValue(PageSizeProperty); - set => SetValue(PageSizeProperty, value); - } public bool IsSupportItemTemplate => true; public bool IsSupportPagination => true; @@ -75,8 +62,6 @@ public class TransferListView : ListBox, ITransferView private bool _ignoreSyncSelection; private IList? _selectedKeysBackup; private int _currentPageSizeBackup; - private IListCollectionView? _listCollectionView; - private SimplePagination? _pagination; private static readonly FuncTemplate DefaultPanel = new(() => new VirtualizingStackPanel()); @@ -102,10 +87,9 @@ public class TransferListView : ListBox, ITransferView return NeedsContainer(item, out recycleKey); } - protected override void PrepareListBoxItem(ListBoxItem listItem, object? item, int index, - CompositeDisposable disposables) + protected override void PrepareListViewItem(ListViewItem listItem, object? item, int index, CompositeDisposable disposables) { - base.PrepareListBoxItem(listItem, item, index, disposables); + base.PrepareListViewItem(listItem, item, index, disposables); if (listItem is TransferListItem transferListItem) { disposables.Add(BindUtils.RelayBind(this, IsSelectableProperty, transferListItem, TransferListItem.IsCheckableProperty)); @@ -133,15 +117,6 @@ public class TransferListView : ListBox, ITransferView } } - protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) - { - base.OnPropertyChanged(change); - if (change.Property == ItemsSourceProperty) - { - Selection.Clear(); - } - } - private void HandleSelectedKeysChanged() { SelectedKeyChanged?.Invoke(this, EventArgs.Empty); @@ -154,10 +129,7 @@ public class TransferListView : ListBox, ITransferView SetCurrentValue(SelectedItemsProperty, selectedItems); } - public void DeselectAll() - { - Selection.Clear(); - } + public void DeselectAll() => Selection.Clear(); void ITransferView.SetPaginationEnabled(bool enabled) { @@ -166,104 +138,19 @@ public class TransferListView : ListBox, ITransferView void ITransferView.SetItemsSource(IEnumerable? itemsSource) { - if (!IsPaginationEnabled) - { - SetCurrentValue(ItemsSourceProperty, itemsSource); - _listCollectionView = null; - } - else - { - var oldCollectionView = _listCollectionView; - var newItemsSource = itemsSource; - - _listCollectionView = null; - IListCollectionView? newCollectionView; - if (newItemsSource is IListCollectionView) - { - newCollectionView = (IListCollectionView)newItemsSource; - } - else - { - newCollectionView = newItemsSource is not null - ? CreateView(newItemsSource) - : default; - } - if (oldCollectionView != null) - { - if (oldCollectionView is ListCollectionView oldDataGridCollectionView) - { - oldDataGridCollectionView.PageChanging -= HandlePageChanging; - } - } - if (newCollectionView != null) - { - if (newCollectionView is ListCollectionView newDataGridCollectionView) - { - newDataGridCollectionView.PageChanging += HandlePageChanging; - } - } - - _listCollectionView = newCollectionView; - - if (oldCollectionView != newCollectionView) - { - SetCurrentValue(ItemsSourceProperty, _listCollectionView); - } - ReConfigurePagination(); - } - } - - internal static IListCollectionView CreateView(IEnumerable source) - { - Debug.Assert(source != null, "source unexpectedly null"); - Debug.Assert(!(source is IListCollectionView), "source is an IListCollectionView"); - - IListCollectionView? collectionView = null; - - if (source is IListCollectionViewFactory collectionViewFactory) - { - // If the source is a collection view factory, give it a chance to produce a custom collection view. - collectionView = collectionViewFactory.CreateView(); - // Intentionally not catching potential exception thrown by ICollectionViewFactory.CreateView(). - } - if (collectionView == null) - { - // If we still do not have a collection view, default to a PagedCollectionView. - collectionView = new ListCollectionView(source); - } - return collectionView; - } - - private void HandlePageChanging(object? sender, PageChangingEventArgs args) - { - var targetPage = args.NewPageIndex + 1; - if (_pagination != null && _pagination.CurrentPage != targetPage) - { - _pagination.CurrentPage = targetPage; - } - } - - private void ReConfigurePagination() - { - if (IsSupportPagination && IsPaginationEnabled) - { - if (_listCollectionView is ListCollectionView collectionView) - { - collectionView.PageSize = PageSize; - if (_pagination != null) - { - _pagination.Total = collectionView.ItemCount; - _pagination.PageSize = PageSize; - _pagination.CurrentPage = Pagination.DefaultCurrentPage; - } - } - } + SetCurrentValue(ItemsSourceProperty, itemsSource); } void ITransferView.NotifyAboutToTransfer(TransferDirection transferDirection) { - _selectedKeysBackup = SelectedKeys; - _currentPageSizeBackup = _pagination?.CurrentPage ?? 1; + _selectedKeysBackup = SelectedKeys; + if (IsPaginationEnabled && BottomPagination != null) + { + if (ItemsSource is IListCollectionView listCollectionView) + { + _currentPageSizeBackup = listCollectionView.PageIndex; + } + } } void ITransferView.NotifyTransferCompleted(TransferDirection transferDirection) @@ -280,15 +167,19 @@ public class TransferListView : ListBox, ITransferView { SetCurrentValue(SelectedKeysProperty, null); } - - if (IsPaginationEnabled && _pagination != null) + + if (IsPaginationEnabled && BottomPagination != null) { - var pageCount = _pagination.PageCount; - var newPageCount = _currentPageSizeBackup <= pageCount ? _currentPageSizeBackup : pageCount; - _pagination.CurrentPage = newPageCount; + if (ItemsSource is IListCollectionView listCollectionView) + { + var pageCount = listCollectionView.TotalItemCount / listCollectionView.PageSize; + var newPageCount = _currentPageSizeBackup <= pageCount ? _currentPageSizeBackup : pageCount; + listCollectionView.MoveToPage(newPageCount); + } } + _selectedKeysBackup = null; - _currentPageSizeBackup = 1; + _currentPageSizeBackup = 0; } void ITransferView.SetSelectionEnabled(bool enabled) @@ -320,39 +211,19 @@ public class TransferListView : ListBox, ITransferView { if (e.Source is CheckBox checkBox && GetContainerFromEventSource(e.Source) is TransferListItem listItem) { - listItem.SetCurrentValue(IsSelectedProperty, checkBox.IsChecked == true); + UpdateSelection(listItem, checkBox.IsChecked == true, false, true); } } + public void SelectAll() => Selection.SelectAll(); + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); - _pagination = e.NameScope.Find("Pagination"); - if (_pagination != null) + SetCurrentValue(BottomPaginationProperty, new SimplePagination() { - _pagination.CurrentPageChanged += HandlePageChangeRequest; - } - } - - private void HandlePageChangeRequest(object? sender, PageChangedEventArgs args) - { - if (_listCollectionView is ListCollectionView collectionView) - { - collectionView.MoveToPage(args.PageIndex - 1); - } - } - - protected override void PrepareContainerForItemOverride(Control container, object? item, int index) - { - var selection = this.GetSelection(); - if (selection == null) - { - selection = new TransferListViewSelectionModel - { - SingleSelect = !SelectionMode.HasAllFlags(SelectionMode.Multiple), - }; - this.InitializeSelectionModel(selection); - } - base.PrepareContainerForItemOverride(container, item, index); + IsReadOnly = false, + SizeType = SizeType.Small + }); } } \ No newline at end of file diff --git a/src/AtomUI.Desktop.Controls/Transfer/TransferToken.cs b/src/AtomUI.Desktop.Controls/Transfer/TransferToken.cs index 99b3aa0a5..55b85e874 100644 --- a/src/AtomUI.Desktop.Controls/Transfer/TransferToken.cs +++ b/src/AtomUI.Desktop.Controls/Transfer/TransferToken.cs @@ -54,6 +54,11 @@ internal class TransferToken : AbstractControlDesignToken /// public Thickness HeaderPadding { get; set; } + /// + /// 分页器的外边距 + /// + public Thickness PaginationMargin { get; set; } + public override void CalculateTokenValues(bool isDarkMode) { base.CalculateTokenValues(isDarkMode); @@ -65,5 +70,6 @@ internal class TransferToken : AbstractControlDesignToken ItemPadding = new Thickness(0, (SharedToken.ControlHeight - SharedToken.FontHeight) / 2); HeaderPadding = new Thickness(SharedToken.UniformlyPaddingSM, Math.Ceiling((SharedToken.ControlHeightLG - SharedToken.LineWidth - SharedToken.FontHeight) / 2)); + PaginationMargin = new Thickness(0, SharedToken.UniformlyMarginXXS); } } \ No newline at end of file