将以往的代码复制到代码库
This commit is contained in:
33
Future.Contract/Extensions/BubbleHelper.cs
Normal file
33
Future.Contract/Extensions/BubbleHelper.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Future.Contract
|
||||
{
|
||||
/// <summary>
|
||||
/// 为气泡提示窗口提供辅助扩展类
|
||||
/// </summary>
|
||||
public static partial class FutureHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 显示一个纯文本气泡提示
|
||||
/// </summary>
|
||||
/// <param name="infoContent">提示信息</param>
|
||||
/// <param name="placement">焦点丢失关闭功能的辅助器定位位置</param>
|
||||
/// <param name="delayTime">自动关闭延时</param>
|
||||
/// <param name="autoClose">是否自动关闭</param>
|
||||
public static void ShowBubble(this string infoContent, FrameworkElement placement = null, int delayTime = 1, bool autoClose = true) => BubbleWindow.ShowBubble(infoContent, placement, delayTime, autoClose);
|
||||
/// <summary>
|
||||
/// 显示一个UI元素气泡提示
|
||||
/// </summary>
|
||||
/// <param name="infoContent">提示信息</param>
|
||||
/// <param name="placement">焦点丢失关闭功能的辅助器定位位置</param>
|
||||
/// <param name="delayTime">自动关闭延时</param>
|
||||
/// <param name="autoClose">是否自动关闭</param>
|
||||
public static void ShowBubble(this UIElement infoContent, FrameworkElement placement = null, int delayTime = 1, bool autoClose = true) => BubbleWindow.ShowBubble(infoContent, placement, delayTime, autoClose);
|
||||
}
|
||||
}
|
||||
166
Future.Contract/Extensions/ControlHelper.cs
Normal file
166
Future.Contract/Extensions/ControlHelper.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Globalization;
|
||||
using Shapes= System.Windows.Shapes;
|
||||
using System.Windows;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Future.Contract
|
||||
{
|
||||
public static partial class FutureHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于同步ComboBox的背景与边框画刷,同时设置下拉按钮的宽度与高度相同;也可以用选择的设置下拉按钮的内容UIElement。
|
||||
/// </summary>
|
||||
/// <param name="comboBox">要进行设置的ComboBox对象</param>
|
||||
/// <param name="hoverBrush">鼠标悬停时的下拉按钮背景画刷</param>
|
||||
/// <param name="handle">下拉按钮的内容UI元素</param>
|
||||
/// <param name="openedHandle">待选列表展开时下拉列表的内容UI元素</param>
|
||||
/// <param name="handleWidth">下拉按钮宽度</param>
|
||||
public static void RefreshBrushAddHandle(this ComboBox comboBox, Brush hoverBrush = null, UIElement handle = null, UIElement openedHandle = null, double handleWidth = 0)
|
||||
{
|
||||
if (comboBox == null) return;
|
||||
Brush background = comboBox.Background;
|
||||
Brush borderBrush = comboBox.BorderBrush;
|
||||
Thickness thickness = comboBox.BorderThickness;
|
||||
|
||||
ToggleButton toggleButton = comboBox.Template.FindName("toggleButton", comboBox) as ToggleButton;
|
||||
Border toggleBorder = toggleButton.Template.FindName("templateRoot", toggleButton) as Border;
|
||||
toggleBorder.Background = background;
|
||||
toggleBorder.BorderBrush = borderBrush;
|
||||
toggleBorder.BorderThickness = thickness;
|
||||
|
||||
if (comboBox.IsEditable)
|
||||
{
|
||||
TextBox textBox = comboBox.Template.FindName("PART_EditableTextBox", comboBox) as TextBox;
|
||||
Border textboxBorder = textBox.Parent as Border;
|
||||
textboxBorder.Background = new SolidColorBrush(Colors.Transparent);
|
||||
textboxBorder.BorderThickness = new Thickness(0);
|
||||
}
|
||||
|
||||
Grid grid = toggleButton.Parent as Grid; //TODO:ComboBox重置按钮插入:可以在这个布局面板中插入
|
||||
grid.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
grid.ClearValue(Grid.HeightProperty);
|
||||
grid.ColumnDefinitions[1].Width = new GridLength((handleWidth == 0) ? comboBox.ActualHeight : handleWidth);
|
||||
Border splitBorder = toggleBorder.Child as Border;
|
||||
splitBorder.Width = (handleWidth == 0) ? comboBox.ActualHeight : handleWidth;
|
||||
splitBorder.BorderThickness = new Thickness(0.5, 0, 0, 0);//在下拉按钮左侧画一条线
|
||||
splitBorder.BorderBrush = borderBrush;
|
||||
|
||||
if (hoverBrush != null)
|
||||
{
|
||||
splitBorder.MouseEnter += (s, e) => splitBorder.Background = hoverBrush;
|
||||
splitBorder.MouseLeave += (s, e) => splitBorder.Background = background;
|
||||
}
|
||||
if (handle != null)
|
||||
{
|
||||
splitBorder.Child = handle;
|
||||
if (openedHandle != null)
|
||||
{
|
||||
comboBox.DropDownOpened += (s, e) => { splitBorder.Child = openedHandle; };
|
||||
comboBox.DropDownClosed += (s, e) => { splitBorder.Child = handle; };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于同步DatePicker的背景与边框画刷,同时设置下拉按钮的宽度与高度相同;也可以用选择的设置下拉按钮的内容UIElement。
|
||||
/// </summary>
|
||||
/// <param name="datePicker">要进行画笔与布局重设的DatePicker对象</param>
|
||||
/// <param name="waterMark">水印信息</param>
|
||||
/// <param name="hoverBrush">鼠标悬停在下拉按钮上时的背景色</param>
|
||||
/// <param name="handle">用于更换下拉按钮上的图案</param>
|
||||
/// <param name="handleWidth">下拉按钮的宽度值</param>
|
||||
public static void RefreshBrushAddHandle(this DatePicker datePicker, string waterMark = "", Brush hoverBrush = null, UIElement handle = null, int handleWidth = 0)
|
||||
{
|
||||
DatePickerTextBox dpTextBox = datePicker.Template.FindName("PART_TextBox", datePicker) as DatePickerTextBox;
|
||||
dpTextBox.Background = datePicker.Background;
|
||||
dpTextBox.BorderBrush = new SolidColorBrush(Colors.Transparent);
|
||||
//处理水印区域边框
|
||||
(dpTextBox.Template.FindName("ContentElement", dpTextBox) as Border).BorderBrush = new SolidColorBrush(Colors.Transparent);
|
||||
(dpTextBox.Template.FindName("watermark_decorator", dpTextBox) as Border).BorderBrush = new SolidColorBrush(Colors.Transparent);
|
||||
//处理水印容器控件
|
||||
if (!string.IsNullOrEmpty(waterMark))
|
||||
{
|
||||
ContentControl watermarkControl = dpTextBox.Template.FindName("PART_Watermark", dpTextBox) as ContentControl;
|
||||
watermarkControl.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
watermarkControl.Content = waterMark;
|
||||
}
|
||||
|
||||
//PART_Root : [Grid]次一级布局容器,内部的布局结构由这个Grid控制;其父节点[Border]的Padding属性继承自DatePicket的Padding(默认2px);可以向其内部插入重置按钮
|
||||
//PART_Button : [Button]下拉按钮,决定按钮的高度,间接决定输入框的高度;清除模板后可替换成自定义显示样式
|
||||
//PART_DisabledVisual : [Grid]内部第二个[Rectangle]元素决定了按钮的宽度,间接决定输入框的宽度
|
||||
|
||||
//让编辑区与按钮尺寸随控件高度变化
|
||||
datePicker.VerticalContentAlignment = VerticalAlignment.Center;
|
||||
Grid partRoot = datePicker.Template.FindName("PART_Root", datePicker) as Grid;//TODO:选择重置按钮可以在这里插入
|
||||
partRoot.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
partRoot.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
partRoot.ColumnDefinitions[1].Width = new GridLength((handleWidth == 0) ? datePicker.ActualHeight : handleWidth);
|
||||
dpTextBox.VerticalContentAlignment = VerticalAlignment.Center;
|
||||
Button partButton = datePicker.Template.FindName("PART_Button", datePicker) as Button;
|
||||
partButton.ClearValue(Button.WidthProperty);
|
||||
partButton.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
partButton.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
|
||||
//处理鼠标悬浮于日期面板展开按钮上时的背景变化
|
||||
if (hoverBrush != null)
|
||||
{
|
||||
Border hoverBorder = new Border()
|
||||
{
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
BorderBrush = new SolidColorBrush(Colors.Gray),
|
||||
BorderThickness = new Thickness(0.5, 0, 0, 0),
|
||||
Visibility = Visibility.Visible
|
||||
};
|
||||
partRoot.Children.Insert(0, hoverBorder);
|
||||
Grid.SetColumn(hoverBorder, 1);
|
||||
|
||||
partButton.Width = hoverBorder.Width;
|
||||
partButton.MouseEnter += (s, e) => { hoverBorder.Background = hoverBrush; };
|
||||
partButton.MouseLeave += (s, e) => { hoverBorder.Background = new SolidColorBrush(Colors.Transparent); };
|
||||
}
|
||||
|
||||
//处理更换日期面板展开按钮的内容
|
||||
if (handle != null)
|
||||
{
|
||||
string templateString = "" +
|
||||
"<ResourceDictionary xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\r\n" +
|
||||
" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\r\n" +
|
||||
" <ControlTemplate x:Key=\"dpButtonTemplate\" TargetType=\"Button\">\r\n" +
|
||||
" <Border BorderBrush=\"{TemplateBinding BorderBrush}\" Background=\"{TemplateBinding Background}\" BorderThickness=\"{TemplateBinding BorderThickness}\">\r\n" +
|
||||
" <ContentPresenter/>\r\n" +
|
||||
" </Border>\r\n" +
|
||||
" </ControlTemplate>\r\n" +
|
||||
"</ResourceDictionary>\r\n";
|
||||
|
||||
ResourceDictionary dictionary = XamlReader.Parse(templateString) as ResourceDictionary;
|
||||
ControlTemplate template = dictionary["dpButtonTemplate"] as ControlTemplate;
|
||||
partButton.Template = template;
|
||||
partButton.Content = handle;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 将一个Path矢量图进行深拷贝后封装于ViewBox中
|
||||
/// </summary>
|
||||
/// <param name="pathGeometry">要封装的Path矢量图</param>
|
||||
/// <param name="fillBrush">填充画笔,不设置则使用源Path的画笔</param>
|
||||
/// <param name="strokeBrush">描边画笔,不设置则使用源Path的画笔</param>
|
||||
/// <returns>封装好的ViewBox对象</returns>
|
||||
public static Viewbox BoxingToViewBox(this Shapes.Path pathGeometry, Brush fillBrush = null, Brush strokeBrush = null)
|
||||
{
|
||||
if (pathGeometry == null) return null;
|
||||
string pathData = pathGeometry.Data.ToString();
|
||||
Shapes.Path targetPath = new Shapes.Path() { Data = Geometry.Parse(pathData), Fill = fillBrush ?? pathGeometry.Fill, Stroke = strokeBrush ?? pathGeometry.Stroke, Width = pathGeometry.Width, Height = pathGeometry.Height };
|
||||
|
||||
return new Viewbox() { Child = targetPath, Stretch = Stretch.Uniform };
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Future.Contract/Extensions/DrawerHelper.cs
Normal file
12
Future.Contract/Extensions/DrawerHelper.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Future.Contract
|
||||
{
|
||||
public static partial class FutureHelper
|
||||
{
|
||||
}
|
||||
}
|
||||
149
Future.Contract/Extensions/FutureHelper.cs
Normal file
149
Future.Contract/Extensions/FutureHelper.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Windows.Markup;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.IO;
|
||||
using System.Windows.Controls;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using Shapes = System.Windows.Shapes;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Future.Contract
|
||||
{
|
||||
/// <summary>
|
||||
/// 通用扩展方法承载类型
|
||||
/// </summary>
|
||||
public static partial class FutureHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于构建扩展方法的执行环境
|
||||
/// </summary>
|
||||
static FutureHelper()
|
||||
{
|
||||
KnownTypes.Add(typeof(List<object>)); //JsonArray
|
||||
KnownTypes.Add(typeof(Dictionary<string, object>)); //JsonObject
|
||||
|
||||
//TODO:对象的序列化=>为序列化器装载可感知类型清单
|
||||
}
|
||||
/// <summary>
|
||||
/// 序列化器可感知类型清单
|
||||
/// </summary>
|
||||
private readonly static List<Type> KnownTypes = new List<Type>();
|
||||
/// <summary>
|
||||
/// 从流中读取一个Json格式表示的对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要读取的对象的类型</typeparam>
|
||||
/// <param name="origin">存放数据的原始数据流</param>
|
||||
/// <returns>被读出的数据对象</returns>
|
||||
public static T Decode4Json<T>(this System.IO.Stream origin)
|
||||
{
|
||||
if (origin == null) return default(T);
|
||||
return (T)new DataContractJsonSerializer(typeof(T), knownTypes: KnownTypes).ReadObject(origin);
|
||||
}
|
||||
public static T Decode4Json<T>(this string origin)
|
||||
{
|
||||
if (origin == null) return default(T);
|
||||
MemoryStream memoryStream = new MemoryStream(Encoding.Default.GetBytes(origin));
|
||||
return (T)new DataContractJsonSerializer(typeof(T), knownTypes: KnownTypes).ReadObject(memoryStream);
|
||||
}
|
||||
/// <summary>
|
||||
/// 向流中以Json格式写入一个对象
|
||||
/// </summary>
|
||||
/// <param name="graph">要写入的源对象</param>
|
||||
/// <param name="target">准备写入的流</param>
|
||||
public static void Encode2Json(this object graph, System.IO.Stream target)
|
||||
{
|
||||
DataContractJsonSerializer mSerializer = new DataContractJsonSerializer(graph.GetType(), knownTypes: KnownTypes);
|
||||
mSerializer.WriteObject(target, graph);
|
||||
}
|
||||
/// <summary>
|
||||
/// 从Xaml文档中读取一个对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要读取的对象类型</typeparam>
|
||||
/// <param name="xaml">存储对象的Xaml文档</param>
|
||||
/// <returns>被读取出的数据对象</returns>
|
||||
public static T Decode4Xaml<T>(this string xaml) => (T)XamlReader.Parse(xaml);
|
||||
/// <summary>
|
||||
/// 将一个对象编译成Xaml文档
|
||||
/// </summary>
|
||||
/// <param name="graph">要进行编译的源数据对象</param>
|
||||
/// <returns>编译完成的Xaml文档</returns>
|
||||
public static string Encode2Xaml(this object graph) => XamlWriter.Save(graph);
|
||||
/// <summary>
|
||||
/// 在确定目标类型的前提下,根据文本表示的值表达式获取真实的值对象
|
||||
/// </summary>
|
||||
/// <param name="type">目标类型枚举值</param>
|
||||
/// <param name="vExp">值表达式</param>
|
||||
/// <returns>如果值表达式有效则返回表达式代表的值,否则返回目标类型的默认值</returns>
|
||||
public static object Evaluate(this EParameterType type, string vExp)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取参数类型枚举的中文名称与简要说明
|
||||
/// </summary>
|
||||
/// <param name="type">预置参数类型</param>
|
||||
/// <returns>参数类型的描述字符串</returns>
|
||||
public static string GetParameterTypeNameAndRemark(this EParameterType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EParameterType.Boolean: return "布尔类型:真实值为 bool 类型;即,true/false";
|
||||
case EParameterType.DateTime: { } return "时间日期:掩码格式为 yyyy-mm-dd HH:mm:ss";
|
||||
case EParameterType.Enums: { } return "枚举类型:真实值为 Int 类型数值";
|
||||
case EParameterType.Integer: { } return "整数类型:真实值为 Int 类型数值";
|
||||
case EParameterType.Number: { } return "数值类型:真实值为 Double 类型数值";
|
||||
case EParameterType.String: { } return "文本类型:真实值为 String 类型";
|
||||
case EParameterType.RichText: { } return "富文本型:真实值为 String 类型";
|
||||
case EParameterType.Variant: { } return "可变类型:真实值可以为 Json 支持的各种基本类型";//所有引擎需要的类型也是使用这个类型存储的
|
||||
case EParameterType.IntArray: return "整数集合:真实值为 Int[] 类型";
|
||||
case EParameterType.NumArray: return "数值集合:真实值为 Double[] 类型";
|
||||
case EParameterType.TxtArray: return "文本集合:真实值为 String[] 类型";
|
||||
case EParameterType.ValArray: { } return "变量集合:真实值为 Object[] 类型";
|
||||
case EParameterType.Byte: return "字节类型:真实值为 Byte 类型";
|
||||
case EParameterType.Word: return "单字类型:真实值为 Byte[2] 类型";
|
||||
case EParameterType.DWord: return "双字类型:真实值为 Byte[4] 类型";
|
||||
case EParameterType.LWord: return "长字类型:真实值为 Byte[8] 类型";
|
||||
case EParameterType.ByteArray: return "字节数组:真实值为 Byte[?] 类型";
|
||||
default: return "未知类型:枚举值超界,出现未定义的类型!";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取参数类型枚举的中文名称
|
||||
/// </summary>
|
||||
/// <param name="type">预置参数类型</param>
|
||||
/// <returns>参数类型的描述字符串</returns>
|
||||
public static string GetParameterTypeName(this EParameterType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EParameterType.Boolean: return "布尔类型";
|
||||
case EParameterType.DateTime: { } return "时间日期";
|
||||
case EParameterType.Enums: { } return "枚举类型";
|
||||
case EParameterType.Integer: { } return "整数类型";
|
||||
case EParameterType.Number: { } return "数值类型";
|
||||
case EParameterType.String: { } return "文本类型";
|
||||
case EParameterType.RichText: { } return "富文本型";
|
||||
case EParameterType.Variant: { } return "可变类型";//所有引擎需要的类型也是使用这个类型存储的
|
||||
case EParameterType.IntArray: return "整数集合";
|
||||
case EParameterType.NumArray: return "数值集合";
|
||||
case EParameterType.TxtArray: return "文本集合";
|
||||
case EParameterType.ValArray: { } return "变量集合";
|
||||
case EParameterType.Byte: return "字节类型";
|
||||
case EParameterType.Word: return "单字类型";
|
||||
case EParameterType.DWord: return "双字类型";
|
||||
case EParameterType.LWord: return "长字类型";
|
||||
case EParameterType.ByteArray: return "字节数组";
|
||||
default: return "???类型";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Future.Contract/Extensions/LoadingHelper.cs
Normal file
27
Future.Contract/Extensions/LoadingHelper.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows;
|
||||
|
||||
namespace Future.Contract
|
||||
{
|
||||
public static partial class FutureHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 开始装载:可以保证每个控件上方只会出现一个加载遮罩层
|
||||
/// </summary>
|
||||
/// <param name="adornedElement">加载目标</param>
|
||||
/// <param name="feedback">反馈信息</param>
|
||||
/// <param name="progress">进度信息</param>
|
||||
/// <returns>加载遮罩装饰器</returns>
|
||||
public static LoadingAdorner LoadingBegin(this UIElement adornedElement, string feedback = "", double progress = -1) => LoadingAdorner.BeginLoading(adornedElement, feedback, progress);
|
||||
/// <summary>
|
||||
/// 结束加载:清除一个控件上方所有的加载遮罩层
|
||||
/// </summary>
|
||||
/// <param name="adornedElement">用标元素</param>
|
||||
public static void LoadingEnded(this UIElement adornedElement)=>LoadingAdorner.FinishLoading(adornedElement);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user