mirror of
https://gitee.com/csharpui/CPF.git
synced 2025-04-05 17:37:51 +08:00
toolkit
This commit is contained in:
parent
293d5da657
commit
f673ced43a
19
CPF.Toolkit.Demo/CPF.Toolkit.Demo.csproj
Normal file
19
CPF.Toolkit.Demo/CPF.Toolkit.Demo.csproj
Normal file
@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CPF.Linux\CPF.Linux.csproj" />
|
||||
<ProjectReference Include="..\CPF.Mac\CPF.Mac.csproj" />
|
||||
<ProjectReference Include="..\CPF.Skia\CPF.Skia.csproj" />
|
||||
<ProjectReference Include="..\CPF.Toolkit\CPF.Toolkit.csproj" />
|
||||
<ProjectReference Include="..\CPF.Windows\CPF.Windows.csproj" />
|
||||
<ProjectReference Include="..\CPF\CPF.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
68
CPF.Toolkit.Demo/MainView.cs
Normal file
68
CPF.Toolkit.Demo/MainView.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using CPF;
|
||||
using CPF.Animation;
|
||||
using CPF.Charts;
|
||||
using CPF.Controls;
|
||||
using CPF.Drawing;
|
||||
using CPF.Shapes;
|
||||
using CPF.Styling;
|
||||
using CPF.Svg;
|
||||
using CPF.Toolkit.Dialogs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace CPF.Toolkit.Demo
|
||||
{
|
||||
public class MainView : Window
|
||||
{
|
||||
public MainView()
|
||||
{
|
||||
|
||||
}
|
||||
protected override void InitializeComponent()
|
||||
{
|
||||
Title = "标题";
|
||||
Width = 500;
|
||||
Height = 400;
|
||||
Background = null;
|
||||
var vm = new MainViewModel();
|
||||
this.DataContext = this.CommandContext = vm;
|
||||
vm.Dialog = new DialogService(this);
|
||||
|
||||
Children.Add(new WindowFrame(this, new WrapPanel
|
||||
{
|
||||
Orientation = Orientation.Horizontal,
|
||||
Size = SizeField.Fill,
|
||||
Children =
|
||||
{
|
||||
new Button
|
||||
{
|
||||
Content = "alert",
|
||||
Commands = { { nameof(Button.Click),(s,e) => vm.Dialog.Alert("这是一条测试消息") } }
|
||||
},
|
||||
new Button
|
||||
{
|
||||
Content = "Sucess",
|
||||
Commands = { { nameof(Button.Click),(s,e) => vm.Dialog.Sucess("这是一条测试消息") } }
|
||||
},
|
||||
new Button
|
||||
{
|
||||
Content = "Error",
|
||||
Commands = { { nameof(Button.Click),(s,e) => vm.Dialog.Error("这是一条测试消息") } }
|
||||
},
|
||||
new Button
|
||||
{
|
||||
Content = "Ask",
|
||||
Commands = { { nameof(Button.Click),(s,e) => vm.Dialog.Ask("这是一条测试消息") } }
|
||||
},
|
||||
new Button
|
||||
{
|
||||
Content = "Warn",
|
||||
Commands = { { nameof(Button.Click),(s,e) => vm.Dialog.Warn("这是一条测试消息") } }
|
||||
},
|
||||
}
|
||||
})) ;
|
||||
}
|
||||
}
|
||||
}
|
14
CPF.Toolkit.Demo/MainViewModel.cs
Normal file
14
CPF.Toolkit.Demo/MainViewModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CPF.Toolkit.Demo
|
||||
{
|
||||
internal class MainViewModel : ViewModelBase
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
20
CPF.Toolkit.Demo/Program.cs
Normal file
20
CPF.Toolkit.Demo/Program.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using CPF.Platform;
|
||||
using CPF.Skia;
|
||||
using CPF.Windows;
|
||||
|
||||
namespace CPF.Toolkit.Demo
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Application.Initialize(
|
||||
(OperatingSystemType.Windows, new WindowsPlatform(false), new SkiaDrawingFactory { })
|
||||
, (OperatingSystemType.OSX, new CPF.Mac.MacPlatform(), new SkiaDrawingFactory { UseGPU = false })
|
||||
, (OperatingSystemType.Linux, new CPF.Linux.LinuxPlatform(), new SkiaDrawingFactory { UseGPU = false })
|
||||
);
|
||||
Application.Run(new MainView { });
|
||||
}
|
||||
}
|
||||
}
|
25
CPF.Toolkit/CPF.Toolkit.csproj
Normal file
25
CPF.Toolkit/CPF.Toolkit.csproj
Normal file
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Images\ask.png" />
|
||||
<None Remove="Images\error.png" />
|
||||
<None Remove="Images\sucess.png" />
|
||||
<None Remove="Images\warn.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Images\ask.png" />
|
||||
<EmbeddedResource Include="Images\error.png" />
|
||||
<EmbeddedResource Include="Images\sucess.png" />
|
||||
<EmbeddedResource Include="Images\warn.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CPF\CPF.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
310
CPF.Toolkit/Dialogs/DialogFrame.cs
Normal file
310
CPF.Toolkit/Dialogs/DialogFrame.cs
Normal file
@ -0,0 +1,310 @@
|
||||
using CPF.Controls;
|
||||
using CPF.Drawing;
|
||||
using CPF.Shapes;
|
||||
using CPF.Styling;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace CPF.Toolkit.Dialogs
|
||||
{
|
||||
internal class DialogFrame : Control
|
||||
{
|
||||
public DialogFrame(IWindow window, UIElement content)
|
||||
{
|
||||
this.window = window;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示最大化还原按钮
|
||||
/// </summary>
|
||||
public bool MaximizeBox { get { return GetValue<bool>(); } set { SetValue(value); } }
|
||||
/// <summary>
|
||||
/// 是否显示最小化
|
||||
/// </summary>
|
||||
[PropertyMetadata(true)]
|
||||
public bool MinimizeBox { get { return GetValue<bool>(); } set { SetValue(value); } }
|
||||
|
||||
IWindow window;
|
||||
/// <summary>
|
||||
/// 关联的窗体
|
||||
/// </summary>
|
||||
[NotCpfProperty]
|
||||
public IWindow Window
|
||||
{
|
||||
get { return window; }
|
||||
}
|
||||
|
||||
UIElement content;
|
||||
/// <summary>
|
||||
/// 窗体的内容
|
||||
/// </summary>
|
||||
[NotCpfProperty]
|
||||
public UIElement Content
|
||||
{
|
||||
get { return content; }
|
||||
}
|
||||
|
||||
IEnumerable<UIElement> systemButtons;
|
||||
/// <summary>
|
||||
/// 系统按钮集合
|
||||
/// </summary>
|
||||
[NotCpfProperty]
|
||||
public IEnumerable<UIElement> SystemButtons
|
||||
{
|
||||
get { return systemButtons; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 阴影宽度
|
||||
/// </summary>
|
||||
[Description("阴影宽度")]
|
||||
[UIPropertyMetadata((byte)5, UIPropertyOptions.AffectsMeasure)]
|
||||
public byte ShadowBlur
|
||||
{
|
||||
get { return GetValue<byte>(); }
|
||||
set { SetValue(value); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 显示标题栏图标
|
||||
/// </summary>
|
||||
[Description("显示标题栏图标"), PropertyMetadata(true)]
|
||||
public bool ShowIcon
|
||||
{
|
||||
get { return GetValue<bool>(); }
|
||||
set { SetValue(value); }
|
||||
}
|
||||
|
||||
protected override void InitializeComponent()
|
||||
{
|
||||
|
||||
ViewFill color = "black";
|
||||
ViewFill hoverColor = "255,255,255,40";
|
||||
Width = "100%";
|
||||
Height = "100%";
|
||||
//窗体阴影
|
||||
var frame = Children.Add(new Border
|
||||
{
|
||||
Name = "frame",
|
||||
Width = "100%",
|
||||
Height = "100%",
|
||||
Background = "#fff",
|
||||
BorderType = BorderType.BorderStroke,
|
||||
BorderStroke = new Stroke(0),
|
||||
ShadowBlur = ShadowBlur,
|
||||
ShadowColor = Color.FromRgba(0, 0, 0, 150),
|
||||
Bindings =
|
||||
{
|
||||
{
|
||||
nameof(Border.ShadowBlur),
|
||||
nameof(IWindow.WindowState),
|
||||
window,
|
||||
BindingMode.OneWay,
|
||||
a => (WindowState)a == WindowState.Maximized||(WindowState)a == WindowState.FullScreen ? 0 : ShadowBlur
|
||||
},
|
||||
{
|
||||
nameof(Border.ShadowBlur),
|
||||
nameof(ShadowBlur),
|
||||
this,
|
||||
BindingMode.OneWay,
|
||||
a =>window.WindowState == WindowState.Maximized||window. WindowState == WindowState.FullScreen ? 0 : (byte)a
|
||||
},
|
||||
}
|
||||
});
|
||||
//用来裁剪内容,不然内容超出阴影
|
||||
var clip = new Decorator
|
||||
{
|
||||
Width = "100%",
|
||||
Height = "100%",
|
||||
ClipToBounds = true
|
||||
};
|
||||
frame.Child = clip;
|
||||
var grid = (Grid)(clip.Child = new Grid
|
||||
{
|
||||
Width = "100%",
|
||||
Height = "100%",
|
||||
ColumnDefinitions =
|
||||
{
|
||||
new ColumnDefinition()
|
||||
},
|
||||
RowDefinitions =
|
||||
{
|
||||
new RowDefinition
|
||||
{
|
||||
Height = "auto"
|
||||
},
|
||||
new RowDefinition
|
||||
{
|
||||
|
||||
}
|
||||
},
|
||||
});
|
||||
//标题栏和按钮
|
||||
grid.Children.Add(
|
||||
new Panel
|
||||
{
|
||||
Name = "caption",
|
||||
Background = "white",
|
||||
Width = "100%",
|
||||
Height = "30",
|
||||
Commands =
|
||||
{
|
||||
{
|
||||
nameof(MouseDown),
|
||||
nameof(IWindow.DragMove),
|
||||
Window
|
||||
},
|
||||
{
|
||||
nameof(DoubleClick),
|
||||
(s,e)=> DoubleClickTitle()
|
||||
}
|
||||
},
|
||||
Children =
|
||||
{
|
||||
new StackPanel
|
||||
{
|
||||
Name="titleBox",
|
||||
MarginLeft=0,
|
||||
Orientation= Orientation.Horizontal,
|
||||
Children=
|
||||
{
|
||||
new Picture
|
||||
{
|
||||
Name="icon",
|
||||
MarginLeft=5,
|
||||
Width=20,
|
||||
Height=20,
|
||||
Stretch= Stretch.Fill,
|
||||
Bindings=
|
||||
{
|
||||
{
|
||||
nameof(Picture.Source),
|
||||
nameof(window.Icon),
|
||||
window
|
||||
},
|
||||
{
|
||||
nameof(Visibility),
|
||||
nameof(window.Icon),
|
||||
window,
|
||||
BindingMode.OneWay,
|
||||
a=>a==null||!ShowIcon?Visibility.Collapsed:Visibility.Visible
|
||||
},
|
||||
{
|
||||
nameof(Visibility),
|
||||
nameof(ShowIcon),
|
||||
this,
|
||||
BindingMode.OneWay,
|
||||
(bool showIcon)=>!showIcon||window.Icon==null?Visibility.Collapsed:Visibility.Visible
|
||||
}
|
||||
}
|
||||
},
|
||||
new TextBlock
|
||||
{
|
||||
Name="title",
|
||||
MarginLeft=8,
|
||||
MarginTop=2,
|
||||
FontSize = 14,
|
||||
Foreground="Gray",
|
||||
Bindings=
|
||||
{
|
||||
{
|
||||
nameof(TextBlock.Text),
|
||||
nameof(IWindow.Title),
|
||||
Window
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
new StackPanel
|
||||
{
|
||||
Name="controlBox",
|
||||
MarginRight=0,
|
||||
Height = "100%",
|
||||
Orientation= Orientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
new SystemButton
|
||||
{
|
||||
Name="close",
|
||||
ToolTip="关闭",
|
||||
Width = 30,
|
||||
Height = "100%",
|
||||
Content=new Panel{
|
||||
Size=SizeField.Fill,
|
||||
Children =
|
||||
{
|
||||
new Line
|
||||
{
|
||||
MarginTop=8,
|
||||
MarginLeft=8,
|
||||
StartPoint = new Point(1, 1),
|
||||
EndPoint = new Point(14, 13),
|
||||
StrokeStyle = "2",
|
||||
IsAntiAlias=true,
|
||||
StrokeFill=color
|
||||
},
|
||||
new Line
|
||||
{
|
||||
MarginTop=8,
|
||||
MarginLeft=8,
|
||||
StartPoint = new Point(14, 1),
|
||||
EndPoint = new Point(1, 13),
|
||||
StrokeStyle = "2",
|
||||
IsAntiAlias=true,
|
||||
StrokeFill=color
|
||||
}
|
||||
}
|
||||
},
|
||||
Commands =
|
||||
{
|
||||
{
|
||||
nameof(Button.Click),
|
||||
(s,e)=>
|
||||
{
|
||||
//(e as MouseButtonEventArgs).Handled=true;
|
||||
Window.Close();
|
||||
}
|
||||
}
|
||||
},
|
||||
Triggers=
|
||||
{
|
||||
new Trigger(nameof(Panel.IsMouseOver), Relation.Me)
|
||||
{
|
||||
Setters =
|
||||
{
|
||||
{
|
||||
nameof(Panel.Background),
|
||||
hoverColor
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if (Content != null)
|
||||
{
|
||||
grid.Children.Add(Content, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
protected void DoubleClickTitle()
|
||||
{
|
||||
if (MaximizeBox)
|
||||
{
|
||||
this.Delay(TimeSpan.FromMilliseconds(100), () =>
|
||||
{
|
||||
if (Window.WindowState == WindowState.Normal)
|
||||
{ Window.WindowState = WindowState.Maximized; }
|
||||
else if (Window.WindowState == WindowState.Maximized)
|
||||
{ Window.WindowState = WindowState.Normal; }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
158
CPF.Toolkit/Dialogs/DialogView.cs
Normal file
158
CPF.Toolkit/Dialogs/DialogView.cs
Normal file
@ -0,0 +1,158 @@
|
||||
using CPF;
|
||||
using CPF.Animation;
|
||||
using CPF.Charts;
|
||||
using CPF.Controls;
|
||||
using CPF.Drawing;
|
||||
using CPF.Shapes;
|
||||
using CPF.Styling;
|
||||
using CPF.Svg;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace CPF.Toolkit.Dialogs
|
||||
{
|
||||
public class DialogView : Window
|
||||
{
|
||||
public DialogView(string text, string title, DialogType dialogType, string defaultButton, params string[] buttons)
|
||||
{
|
||||
this.Title = title;
|
||||
this.Text = text;
|
||||
this.Buttons = buttons;
|
||||
this.DefaultButton = defaultButton;
|
||||
this.DialogType = dialogType;
|
||||
}
|
||||
|
||||
public DialogType DialogType { get => GetValue<DialogType>(); set => SetValue(value); }
|
||||
public string DefaultButton { get => GetValue<string>(); set => SetValue(value); }
|
||||
public string Text { get => GetValue<string>(); set => SetValue(value); }
|
||||
public string[] Buttons { get => GetValue<string[]>(); set => SetValue(value); }
|
||||
protected override void InitializeComponent()
|
||||
{
|
||||
this.ShowInTaskbar = false;
|
||||
this.MaxWidth = 800;
|
||||
this.MinWidth = 400;
|
||||
this.MaxHeight = 600;
|
||||
this.MinHeight = 250;
|
||||
this.CanResize = false;
|
||||
this.Width = "auto";
|
||||
this.Height = "auto";
|
||||
this.Background = null;
|
||||
this.Children.Add(new DialogFrame(this, new Grid
|
||||
{
|
||||
Size = SizeField.Fill,
|
||||
RowDefinitions =
|
||||
{
|
||||
new RowDefinition{ Height = "auto" },
|
||||
new RowDefinition{ },
|
||||
new RowDefinition{ Height = 35 },
|
||||
},
|
||||
Children =
|
||||
{
|
||||
new Picture
|
||||
{
|
||||
Stretch = Stretch.None,
|
||||
Bindings =
|
||||
{
|
||||
{
|
||||
nameof(Visibility),
|
||||
nameof(DialogType),
|
||||
this,BindingMode.OneWay,
|
||||
(DialogType t) => t == DialogType.None ? Visibility.Collapsed : Visibility.Visible
|
||||
},
|
||||
{
|
||||
nameof(Picture.Source),
|
||||
nameof(DialogType),
|
||||
this,BindingMode.OneWay,
|
||||
(DialogType t) =>
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
case DialogType.Sucess: return "res://CPF.Toolkit/Images/sucess.png";
|
||||
case DialogType.Error:return"res://CPF.Toolkit/Images/error.png";
|
||||
case DialogType.Ask: return"res://CPF.Toolkit/Images/ask.png";
|
||||
case DialogType.Warn:return "res://CPF.Toolkit/Images/warn.png";
|
||||
default:return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new TextBox
|
||||
{
|
||||
Attacheds = { { Grid.RowIndex,1 } },
|
||||
BorderType = BorderType.BorderThickness,
|
||||
BorderStroke = new Stroke(1, DashStyles.Solid),
|
||||
BorderThickness = new Thickness(0,0,0,1),
|
||||
//BorderFill = "Silver",
|
||||
IsReadOnly = true,
|
||||
Size = SizeField.Fill,
|
||||
FontSize = 16,
|
||||
WordWarp = true,
|
||||
TextAlignment = TextAlignment.Center,
|
||||
Bindings =
|
||||
{
|
||||
{ nameof(TextBox.Text),nameof(Text),this,BindingMode.OneWay}
|
||||
}
|
||||
}.Assign(out var textBox),
|
||||
//new Border
|
||||
//{
|
||||
// Attacheds = { { Grid.RowIndex,2 } },
|
||||
// BorderThickness = new Thickness(0,1,0,0),
|
||||
// BorderType = BorderType.BorderThickness,
|
||||
// BorderFill = "236,236,236",
|
||||
// Size = SizeField.Fill,
|
||||
// MarginBottom = 5,
|
||||
//},
|
||||
new StackPanel
|
||||
{
|
||||
Height = "100%",
|
||||
Attacheds = { { Grid.RowIndex,2 } },
|
||||
MarginBottom = 4,
|
||||
Orientation = Orientation.Horizontal,
|
||||
}.Assign(out var p),
|
||||
}
|
||||
}));
|
||||
|
||||
this.Buttons.Select(x => new Button
|
||||
{
|
||||
Content = x,
|
||||
MinWidth = this.Buttons.Length <= 1 ? 80 : 65,
|
||||
Background = "white",
|
||||
BorderFill = "236,236,236",
|
||||
Height = "95%",
|
||||
MarginRight = 5,
|
||||
}).ToList().ForEach(c =>
|
||||
{
|
||||
p.Children.Add(c);
|
||||
c.Click += C_Click;
|
||||
if (c.Content.ToString() == this.DefaultButton)
|
||||
{
|
||||
c.Focus();
|
||||
}
|
||||
});
|
||||
textBox.TextChanged += TextBox_TextChanged;
|
||||
}
|
||||
|
||||
private void TextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
var textBox = sender as TextBox;
|
||||
if (textBox.Document.Lines.Count > 5)
|
||||
{
|
||||
textBox.TextAlignment = TextAlignment.Left;
|
||||
textBox.Height = "100%";
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox.TextAlignment = TextAlignment.Center;
|
||||
textBox.Height = "auto";
|
||||
}
|
||||
}
|
||||
|
||||
private void C_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.DialogResult = (sender as Button).Content;
|
||||
}
|
||||
}
|
||||
}
|
68
CPF.Toolkit/Dialogs/IDialogService.cs
Normal file
68
CPF.Toolkit/Dialogs/IDialogService.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using CPF.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CPF.Toolkit.Dialogs
|
||||
{
|
||||
public interface IDialogService
|
||||
{
|
||||
string Alert(string text, string title, DialogType dialogType, string defaultButton, params string[] buttons);
|
||||
void Alert(string text);
|
||||
void Sucess(string text);
|
||||
void Error(string text);
|
||||
void Warn(string text);
|
||||
string Ask(string text);
|
||||
}
|
||||
|
||||
public class DialogService : IDialogService
|
||||
{
|
||||
public DialogService(Window owner)
|
||||
{
|
||||
this.owner = owner;
|
||||
}
|
||||
Window owner;
|
||||
|
||||
public string Alert(string text, string title, DialogType dialogType, string defaultButton, params string[] buttons)
|
||||
{
|
||||
var view = new DialogView(text, title, dialogType, defaultButton, buttons);
|
||||
view.MarginLeft = this.owner.MarginLeft.Value - this.owner.Width.Value / 2;
|
||||
view.MarginTop = this.owner.MarginTop.Value - this.owner.Height.Value / 2;
|
||||
return view.ShowDialogSync(this.owner)?.ToString();
|
||||
}
|
||||
|
||||
public void Alert(string text)
|
||||
{
|
||||
this.Alert(text, "消息", DialogType.None, "确定", "确定");
|
||||
}
|
||||
|
||||
public string Ask(string text)
|
||||
{
|
||||
return this.Alert(text, "询问", DialogType.Ask, "确定", "确定", "取消");
|
||||
}
|
||||
|
||||
public void Error(string text)
|
||||
{
|
||||
this.Alert(text, "错误", DialogType.Error, defaultButton: "确定", "确定");
|
||||
}
|
||||
|
||||
public void Sucess(string text)
|
||||
{
|
||||
this.Alert(text, "成功", DialogType.Sucess, "确定", "确定");
|
||||
}
|
||||
|
||||
public void Warn(string text)
|
||||
{
|
||||
this.Alert(text, "警告", DialogType.Warn, "确定", "确定");
|
||||
}
|
||||
}
|
||||
|
||||
public enum DialogType
|
||||
{
|
||||
None,
|
||||
Sucess,
|
||||
Error,
|
||||
Ask,
|
||||
Warn
|
||||
}
|
||||
}
|
BIN
CPF.Toolkit/Images/ask.png
Normal file
BIN
CPF.Toolkit/Images/ask.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 679 B |
BIN
CPF.Toolkit/Images/error.png
Normal file
BIN
CPF.Toolkit/Images/error.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 879 B |
BIN
CPF.Toolkit/Images/sucess.png
Normal file
BIN
CPF.Toolkit/Images/sucess.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 834 B |
BIN
CPF.Toolkit/Images/warn.png
Normal file
BIN
CPF.Toolkit/Images/warn.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 748 B |
63
CPF.Toolkit/ObservableObject.cs
Normal file
63
CPF.Toolkit/ObservableObject.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace CPF.Toolkit
|
||||
{
|
||||
public class ObservableObject : INotifyPropertyChanged
|
||||
{
|
||||
readonly ConcurrentDictionary<string, object> Propertys = new ConcurrentDictionary<string, object> { };
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
|
||||
public T GetValue<T>(T defaultValue = default, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(propertyName))
|
||||
{
|
||||
throw new Exception("propertyName不能为空");
|
||||
}
|
||||
if (!this.Propertys.ContainsKey(propertyName))
|
||||
{
|
||||
this.Propertys.TryAdd(propertyName, defaultValue);
|
||||
}
|
||||
return (T)this.Propertys[propertyName];
|
||||
}
|
||||
|
||||
public bool SetValue<T>(T value, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(propertyName))
|
||||
{
|
||||
throw new Exception("propertyName不能为空");
|
||||
}
|
||||
|
||||
if (!this.Propertys.ContainsKey(propertyName))
|
||||
{
|
||||
this.Propertys.TryAdd(propertyName, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var v = this.GetValue<T>(propertyName: propertyName);
|
||||
if (EqualityComparer<T>.Default.Equals(value, v)) return false;
|
||||
this.Propertys[propertyName] = value;
|
||||
}
|
||||
this.RaisePropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetValue<T>(T value, Action<T> action, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (this.SetValue(value, propertyName))
|
||||
{
|
||||
action.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
12
CPF.Toolkit/ViewModelBase.cs
Normal file
12
CPF.Toolkit/ViewModelBase.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using CPF.Toolkit.Dialogs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CPF.Toolkit
|
||||
{
|
||||
public class ViewModelBase : ObservableObject
|
||||
{
|
||||
public IDialogService Dialog { get; set; }
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29324.140
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34316.72
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{ABE4ED47-CB9F-4183-9CE3-65E3E521BE2A}"
|
||||
EndProject
|
||||
@ -59,12 +59,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CPF.Demo", "CPF_Demo\CPF.De
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "蓝图重制版", "蓝图重制版\蓝图重制版.csproj", "{003E155A-8C40-41AF-A796-ED17E729E013}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Toolkit", "Toolkit", "{28FB518C-2103-4772-A245-C5F1D40E1EF5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPF.Toolkit", "CPF.Toolkit\CPF.Toolkit.csproj", "{09C160EB-D2C3-42E5-82B3-7047CF87CE6C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPF.Toolkit.Demo", "CPF.Toolkit.Demo\CPF.Toolkit.Demo.csproj", "{AEA7FF33-1621-4A0A-9C08-6C4CB10C76FF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
Private\SharedVSIX\SharedVSIX.projitems*{db53e8d7-dfb6-48eb-a7b6-d1cf762acb9b}*SharedItemsImports = 4
|
||||
Private\SharedVSIX\SharedVSIX.projitems*{df526631-d060-47f2-afd4-62c6cea2fe9a}*SharedItemsImports = 4
|
||||
Private\SharedVSIX\SharedVSIX.projitems*{f34cffee-546f-490e-a76a-2792840b284d}*SharedItemsImports = 13
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
@ -224,6 +225,18 @@ Global
|
||||
{003E155A-8C40-41AF-A796-ED17E729E013}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{003E155A-8C40-41AF-A796-ED17E729E013}.类库d|Any CPU.ActiveCfg = 类库d|Any CPU
|
||||
{003E155A-8C40-41AF-A796-ED17E729E013}.类库d|Any CPU.Build.0 = 类库d|Any CPU
|
||||
{09C160EB-D2C3-42E5-82B3-7047CF87CE6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{09C160EB-D2C3-42E5-82B3-7047CF87CE6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{09C160EB-D2C3-42E5-82B3-7047CF87CE6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{09C160EB-D2C3-42E5-82B3-7047CF87CE6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{09C160EB-D2C3-42E5-82B3-7047CF87CE6C}.类库d|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{09C160EB-D2C3-42E5-82B3-7047CF87CE6C}.类库d|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AEA7FF33-1621-4A0A-9C08-6C4CB10C76FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AEA7FF33-1621-4A0A-9C08-6C4CB10C76FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AEA7FF33-1621-4A0A-9C08-6C4CB10C76FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AEA7FF33-1621-4A0A-9C08-6C4CB10C76FF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AEA7FF33-1621-4A0A-9C08-6C4CB10C76FF}.类库d|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AEA7FF33-1621-4A0A-9C08-6C4CB10C76FF}.类库d|Any CPU.Build.0 = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -240,5 +253,15 @@ Global
|
||||
{1278A1BC-327D-4D13-AD04-C6FF2B680530} = {2B729C46-7592-425A-87E9-D769A94881F7}
|
||||
{F34CFFEE-546F-490E-A76A-2792840B284D} = {2B729C46-7592-425A-87E9-D769A94881F7}
|
||||
{DF526631-D060-47F2-AFD4-62C6CEA2FE9A} = {2B729C46-7592-425A-87E9-D769A94881F7}
|
||||
{09C160EB-D2C3-42E5-82B3-7047CF87CE6C} = {28FB518C-2103-4772-A245-C5F1D40E1EF5}
|
||||
{AEA7FF33-1621-4A0A-9C08-6C4CB10C76FF} = {28FB518C-2103-4772-A245-C5F1D40E1EF5}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E38AA5AA-8B93-40BD-8A5E-2E0D1538EB8D}
|
||||
EndGlobalSection
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
Private\SharedVSIX\SharedVSIX.projitems*{db53e8d7-dfb6-48eb-a7b6-d1cf762acb9b}*SharedItemsImports = 4
|
||||
Private\SharedVSIX\SharedVSIX.projitems*{df526631-d060-47f2-afd4-62c6cea2fe9a}*SharedItemsImports = 4
|
||||
Private\SharedVSIX\SharedVSIX.projitems*{f34cffee-546f-490e-a76a-2792840b284d}*SharedItemsImports = 13
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
Loading…
Reference in New Issue
Block a user