using CPF; using CPF.Animation; using CPF.Charts; using CPF.Controls; using CPF.Drawing; using CPF.Input; using CPF.Shapes; using CPF.Styling; using CPF.Svg; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; namespace CPF.Toolkit.Controls { public class PageControl : Control { public PageControl() { this.Pages = new ObservableCollection(); } public int PageIndex { get => GetValue(); set => SetValue(value); } public int PageCount { get => GetValue(); set => SetValue(value); } int pageSize = 10; public event EventHandler PageIndexChanged { add => AddHandler(value); remove => RemoveHandler(value); } ObservableCollection Pages { get => GetValue>(); set => SetValue(value); } protected override void InitializeComponent() { this.Size = SizeField.Fill; this.Children.Add(new StackPanel { Orientation = Orientation.Horizontal, Size = SizeField.Fill, Children = { new Button { Content = "上一页", [nameof(IsEnabled)] = new BindingDescribe(this,nameof(this.PageIndex),BindingMode.OneWay,c => ((int)c) > 1), }, new ListBox { ItemTemplate = new PageButton { [nameof(PageIndexChanged)] = new CommandDescribe((s,e) => this.PageIndex = (e as IndexEventArgs).Index) }, ItemsPanel = new StackPanel{Orientation = Orientation.Horizontal,}, Items = this.Pages, }, new TextBlock { Text = "……", [nameof(Visibility)] = new BindingDescribe(this,nameof(this.PageCount),BindingMode.OneWay,c => ((int)c) > this.pageSize ? Visibility.Visible : Visibility.Collapsed) }, new Button { Content = "100", [nameof(Visibility)] = new BindingDescribe(this,nameof(this.PageCount),BindingMode.OneWay,c => ((int)c) > this.pageSize ? Visibility.Visible : Visibility.Collapsed) }, new Button { Content = "下一页", [nameof(IsEnabled)] = new BindingDescribe(this,nameof(this.PageIndex),BindingMode.OneWay,c => ((int)c) < this.PageCount), }, new StackPanel { MarginLeft = 10, Orientation = Orientation.Horizontal, Children = { new TextBlock { Text = "1 ", Foreground = "dodgerblue", }, new TextBlock { Text = $"/ 100", }, } }, new TextBlock { Text = " 到第几 " }, new Border { MinHeight = 35, MinWidth = 35, MarginLeft = 2, MarginRight = 2, Child = new TextBox { Width = "100%", Text = "10", TextAlignment = TextAlignment.Center, FontSize = 14, }, BorderFill = "silver", BorderStroke = "1", CornerRadius = new CornerRadius(2), IsAntiAlias = true, UseLayoutRounding = true, }, new TextBlock { Text = " 页 " , }, new Button { Content = "确定", } } }); foreach (var item in this.Find()) { item.FontSize = 14; } foreach (var item in Find