This commit is contained in:
luxiaoqi 2023-12-01 16:23:12 +08:00
parent 0a12d33d15
commit 36433178c2
5 changed files with 237 additions and 48 deletions

View File

@ -6,6 +6,7 @@ using CPF.Drawing;
using CPF.Shapes;
using CPF.Styling;
using CPF.Svg;
using CPF.Toolkit.Controls;
using CPF.Toolkit.Dialogs;
using System;
using System.Collections.Generic;
@ -21,8 +22,8 @@ namespace CPF.Toolkit.Demo
protected override void InitializeComponent()
{
Title = "标题";
Width = 500;
Height = 400;
Width = 1280;
Height = 720;
Background = null;
this.DataContext = this.CommandContext = vm;
this.CanResize = true;
@ -84,6 +85,17 @@ namespace CPF.Toolkit.Demo
{ nameof(Button.Click), (s,e) => new TestMdiView().Show() }
}
},
new Panel
{
},
new PageControl
{
Height = 35,
PageIndex = 1,
PageCount = 100,
Width = "100%",
},
}
}));

View File

@ -336,5 +336,35 @@ namespace CPF.Toolkit.Controls
});
}
}
class MdiWindowRect
{
public MdiWindowRect()
{
}
public MdiWindowRect(float left, float top, float width, float height)
{
this.Left = left;
this.Top = top;
this.Width = width;
this.Height = height;
}
public float Left { get; set; }
public float Top { get; set; }
public float Width { get; set; }
public float Height { get; set; }
public WindowState OldState { get; set; }
public override string ToString()
{
return $"left:{this.Left} top:{this.Top} width:{this.Width} height:{this.Height}";
}
}
}
public enum TaskBarPlacement
{
Top,
Bottom,
}
}

View File

@ -1,34 +0,0 @@
using CPF.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace CPF.Toolkit.Controls
{
internal class MdiWindowRect
{
public MdiWindowRect()
{
}
public MdiWindowRect(float left, float top, float width, float height)
{
this.Left = left;
this.Top = top;
this.Width = width;
this.Height = height;
}
public float Left { get; set; }
public float Top { get; set; }
public float Width { get; set; }
public float Height { get; set; }
public WindowState OldState { get; set; }
public override string ToString()
{
return $"left:{this.Left} top:{this.Top} width:{this.Width} height:{this.Height}";
}
}
}

View File

@ -0,0 +1,193 @@
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<int>();
}
public int PageIndex { get => GetValue<int>(); set => SetValue(value); }
public int PageCount { get => GetValue<int>(); set => SetValue(value); }
int pageSize = 10;
public event EventHandler<IndexEventArgs> PageIndexChanged { add => AddHandler(value); remove => RemoveHandler(value); }
ObservableCollection<int> Pages { get => GetValue<ObservableCollection<int>>(); 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<TextBlock>())
{
item.FontSize = 14;
}
foreach (var item in Find<Button>())
{
item.BorderFill = "dodgerblue";
item.BorderStroke = "1";
item.CornerRadius = new CornerRadius(4);
item.Background = "white";
item.Foreground = "dodgerblue";
item.MinWidth = 35;
item.MinHeight = 35;
item.MarginRight = 2;
item.IsAntiAlias = true;
item.UseLayoutRounding = true;
if (!int.TryParse(item.Content.ToString(), out var _))
{
item.Width = 60;
}
}
}
protected override void OnPropertyChanged(string propertyName, object oldValue, object newValue, PropertyMetadataAttribute propertyMetadata)
{
if (propertyName.Or(nameof(this.PageIndex), nameof(this.PageCount)))
{
this.Pages.Clear();
for (int i = 1; i <= this.PageCount; i++)
{
if (i > this.pageSize)
{
break;
}
this.Pages.Add(i);
}
}
base.OnPropertyChanged(propertyName, oldValue, newValue, propertyMetadata);
}
class PageButton : ListBoxItem
{
public event EventHandler<IndexEventArgs> PageIndexChanged { add => AddHandler(value); remove => RemoveHandler(value); }
protected override void InitializeComponent()
{
this.Children.Add(new RadioButton
{
GroupName = "pageNumber",
Template = (ss,ee) =>
{
ee.Add(new TextBlock
{
//[nameof(TextBlock.Text)] = new BindingDescribe()
});
},
[nameof(Content)] = new BindingDescribe(this, nameof(Content)),
[nameof(RadioButton.Click)] = new CommandDescribe((s, e) => this.RaiseEvent(new IndexEventArgs(Convert.ToInt32((s as RadioButton).Content)), nameof(this.PageIndexChanged)))
});
}
}
}
public class IndexEventArgs : EventArgs
{
public IndexEventArgs(int index)
{
this.Index = index;
}
public int Index { get; set; }
}
}

View File

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CPF.Toolkit.Controls
{
public enum TaskBarPlacement
{
Top,
Bottom,
}
}