├── .gitignore ├── H.Framework.Aliyun.ACM ├── AliyunACMRequest.cs ├── AliyunACMResp.cs ├── AliyunRequest.cs └── H.Framework.Aliyun.ACM.csproj ├── H.Framework.Aliyun.Log ├── H.Framework.Aliyun.Log.csproj ├── LogCenter.cs └── LogCore.cs ├── H.Framework.Aliyun.MNS ├── H.Framework.Aliyun.MNS.csproj ├── MNSCenter.cs └── MNSCore.cs ├── H.Framework.Core ├── Attributes │ └── DataValidationAttribute.cs ├── H.Framework.Core.csproj ├── List │ ├── AsyncVirtualizingCollection.cs │ ├── IItemsProvider.cs │ ├── VirtualizingCollection.cs │ └── VirtualizingObservableCollection.cs ├── Log │ ├── ILogger.cs │ ├── Log4NetLogger.cs │ ├── LogHelper.cs │ └── LogMessage.cs ├── Mapping │ ├── ICustomMap.cs │ ├── MapperExtension.cs │ ├── Mapping.cs │ └── MappingSourceAttribute.cs └── Utilities │ ├── EndianExtensions.cs │ ├── EqualityComparerUtility.cs │ ├── Extensions.cs │ ├── FileHelper.cs │ ├── HashEncryptHepler.cs │ ├── JsonExtensions.cs │ ├── ProjectionExpression.cs │ ├── RegexExtensions.cs │ ├── TimeHelper.cs │ ├── TreeExtensions.cs │ ├── Utility.cs │ └── ValidationExtension.cs ├── H.Framework.Data.ORM ├── Attributes │ ├── DataFieldAttribute.cs │ ├── DataFieldIgnoreAttribute.cs │ ├── DataTableAttribute.cs │ ├── DetailListAttribute.cs │ ├── DynamicSQLFieldAttribute.cs │ ├── ForeignAttribute.cs │ ├── ForeignKeyIDAttribute.cs │ ├── LastIDConditionAttribute.cs │ ├── OnlyQueryAttribute.cs │ └── PrimaryKeyIDAttribute.cs ├── BaseBLL.cs ├── BaseDAL.cs ├── BuilderSQLHelper.cs ├── DataConvert.cs ├── Foundations │ ├── ExpressionExtensions.cs │ ├── FoundationBLL.cs │ ├── FoundationCorrelationBLL.cs │ ├── FoundationCorrelationDAL.cs │ ├── FoundationDAL.cs │ ├── IFoundationBLL.cs │ ├── IFoundationCorrelationBLL.cs │ ├── IFoundationCorrelationDAL.cs │ ├── IFoundationDAL.cs │ ├── IFoundationModel.cs │ ├── IFoundationViewModel.cs │ ├── OrderByEntity.cs │ └── SqlParamModel.cs ├── H.Framework.Data.ORM.csproj ├── MySQLUtility.cs └── MySqlFabricate.cs ├── H.Framework.NETCore.IoC ├── Autofac │ ├── IDependencyRegistrar.cs │ ├── IIoCManager.cs │ ├── ISingletonDependency.cs │ ├── ITransientDependency.cs │ └── IoCManager.cs └── H.Framework.NETCore.IoC.csproj ├── H.Framework.U-Push ├── Bases │ ├── IPush.cs │ ├── PostJsonClass.cs │ ├── ReturnJsonClass.cs │ └── SerializableDictionary.cs ├── H.Framework.UMeng.Push.csproj └── UMengMessagePush.cs ├── H.Framework.WPF.Control ├── Adorners │ ├── BusyAdorner.cs │ ├── DragAdorner.cs │ ├── SearchBoxFocusAdorner.cs │ └── WatermarkAdorner.cs ├── ControlHelpers │ └── TextBoxHelper.cs ├── Controls │ ├── BusyChrome.cs │ ├── BusyCircle.cs │ ├── BusyDecorator.cs │ ├── ButtonEx.cs │ ├── CaptionsMarquee.cs │ ├── Capture │ │ ├── BitmapCursor.cs │ │ ├── Config.cs │ │ ├── IndicatorObject.cs │ │ ├── MaskCanvas.cs │ │ ├── MaskWindow.cs │ │ ├── MoveThumb.cs │ │ ├── ResizeThumb.cs │ │ ├── ScreenCapture.cs │ │ ├── ThumbBase.cs │ │ ├── ToolBarControl.xaml │ │ └── ToolBarControl.xaml.cs │ ├── ClassicPager.cs │ ├── ComboBoxEx.cs │ ├── DownloadComponent.cs │ ├── ExpanderEx.cs │ ├── ExtendedWindows │ │ ├── ExtendedWindow.cs │ │ ├── FunctionBar.cs │ │ ├── WindowParameters.cs │ │ ├── WindowService.WindowCommandHelper.cs │ │ └── WindowService.cs │ ├── ImageButton.cs │ ├── MarketLoading.cs │ ├── Pager.cs │ ├── PasswordBox.cs │ ├── PieButton.cs │ ├── RadioButtonEx.cs │ ├── RectangleLoading.cs │ ├── RichTextEdit.cs │ ├── SearchBox.cs │ ├── SwingLoading.cs │ ├── SwitchButton.cs │ ├── TextBoxEx.cs │ ├── TipBubble.cs │ ├── UnreadTip.cs │ ├── WarnBlock.cs │ ├── WatermarkPasswordBox.cs │ └── WindowEx.cs ├── H.Framework.WPF.Control.csproj ├── H.Framework.WPF.Control.csproj.user ├── H.Framework.WPF.Control_wuiyjkcy_wpftmp.csproj ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Resources │ ├── Icons │ │ ├── close.png │ │ ├── downFile.png │ │ ├── ok.png │ │ └── save.png │ └── Styles │ │ └── BasicStyle.xaml ├── Themes │ ├── BusyChrome.generic.xaml │ ├── BusyCircle.generic.xaml │ ├── ButtonEx.generic.xaml │ ├── CaptionsMarquee.generic.xaml │ ├── ClassicPager.generic.xaml │ ├── ComboBoxEx.generic.xaml │ ├── DownloadComponent.generic.xaml │ ├── ExpanderEx.generic.xaml │ ├── ExtendedWindow.generic.xaml │ ├── Generic.xaml │ ├── ImageButton.generic.xaml │ ├── IndicatorObject.generic.xaml │ ├── MarketLoading.generic.xaml │ ├── Pager.generic.xaml │ ├── PasswordBox.generic.xaml │ ├── PieButton.generic.xaml │ ├── RadioButtonEx.generic.xaml │ ├── RectangleLoading.generic.xaml │ ├── SearchBox.generic.xaml │ ├── SwingLoading.generic.xaml │ ├── TextBoxEx.generic.xaml │ ├── TipBubble.generic.xaml │ ├── UnreadTip.generic.xaml │ ├── WarnBlock.generic.xaml │ ├── WindowEx.generic.xaml │ └── WindowFunctionBar.generic.xaml ├── Utilities │ ├── Caputre │ │ └── HelperMethods.cs │ ├── Enums.cs │ └── Extensions.cs └── packages.config ├── H.Framework.WPF.Infrastructure ├── Behaviors │ └── ControlFocusBehaviorBase.cs ├── Converters │ ├── EmptyObjectToVisibilityConverter.cs │ ├── MultiObjectConverter.cs │ ├── ObjectConverter.cs │ └── SimpleMathConverter.cs ├── H.Framework.WPF.Infrastructure.csproj ├── Lists │ └── ThreadSafeObservableCollection.cs ├── Mvvm │ ├── BasicEntity.cs │ ├── BasicViewModel.cs │ └── Command │ │ ├── CommandManager.cs │ │ ├── OperationCommand.cs │ │ └── ParameterEventArgs.cs ├── Properties │ └── AssemblyInfo.cs ├── Utilities │ ├── AppHotKey.cs │ ├── Extensions.cs │ ├── GridHelper.cs │ ├── ImageExtender.cs │ ├── ListBoxExtender.cs │ ├── PasswordBoxHelper.cs │ ├── PopupHelper.cs │ ├── ScrollViewerExtensions.cs │ └── WindowExtensions.cs └── packages.config ├── H.Framework.WPF.UI.Test ├── App.xaml ├── App.xaml.cs ├── AssemblyInfo.cs ├── DiqiuModel.cs ├── H.Framework.WPF.UI.Test.csproj ├── MainWindow.xaml ├── MainWindow.xaml.cs └── Test.cs ├── H.Framework.WPF.UITest ├── App.config ├── App.xaml ├── App.xaml.cs ├── EFCoreTest.cs ├── GWindow.xaml ├── GWindow.xaml.cs ├── H.Framework.WPF.UITest.csproj ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── RPC │ ├── ZeusCommonMsg.cs │ ├── ZeusCommonMsgGrpc.cs │ ├── ZeusFuturesCompanyMsg.cs │ ├── ZeusFuturesCompanyMsgGrpc.cs │ ├── ZeusMsg.cs │ ├── ZeusNotificationMsg.cs │ ├── ZeusNotificationMsgGrpc.cs │ ├── ZeusUserMsg.cs │ ├── ZeusUserMsgGrpc.cs │ ├── ZeusUserlogMsg.cs │ └── ZeusUserlogMsgGrpc.cs ├── SingleApp.cs ├── SplashScreenBG.png ├── SplashScreenFG.png ├── TestWindow.xaml ├── TestWindow.xaml.cs ├── i_emoji.png ├── log4net.config ├── packages.config └── s_emoji.png ├── H.Framework.sln └── _config.yml /H.Framework.Aliyun.ACM/AliyunACMRequest.cs: -------------------------------------------------------------------------------- 1 | using Aliyun.Acs.Core.Http; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace H.Framework.Aliyun.ACM 7 | { 8 | public class AliyunACMRequest : AliyunRequest 9 | { 10 | public AliyunACMRequest(string accessKey, string secretKey) : base(accessKey, secretKey) 11 | { 12 | } 13 | 14 | public AliyunACMRequest(string roleName) : base(roleName) 15 | { 16 | } 17 | 18 | public AliyunConfigurationResp GetACMConfig(string region, string dataID, string group, string namespaceID) 19 | { 20 | return RequestACM("/diamond-ops/pop/configuration", MethodType.GET, region, new Dictionary 21 | { 22 | { "DataId", dataID }, 23 | { "Group", group }, 24 | { "NamespaceId", namespaceID} 25 | }); 26 | } 27 | 28 | //public string AddListener(string region, string dataID, string group, string namespaceID) 29 | //{ 30 | // return RequestACM("/diamond-server/config.co", MethodType.POST, region, new Dictionary 31 | // { 32 | // { "Probe-Modify-Request", dataID+"^2"+group+"^2"+namespaceID+"^1" } 33 | // }); 34 | //} 35 | 36 | private T RequestACM(string url, MethodType methodType, string region, Dictionary args) 37 | { 38 | return RequestAliyun(url, "2020-02-06", methodType, region, "acm." + region + ".aliyuncs.com", args); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /H.Framework.Aliyun.ACM/AliyunACMResp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace H.Framework.Aliyun.ACM 6 | { 7 | public class AliyunConfigurationResp 8 | { 9 | public string Code { get; set; } 10 | public string Message { get; set; } 11 | public string RequestId { get; set; } 12 | public AliyunConfiguration Configuration { get; set; } 13 | } 14 | 15 | //public class AliyunConfigurationListener 16 | //{ 17 | // public string ConfigInfo { get; set; } 18 | //} 19 | 20 | public class AliyunConfiguration 21 | { 22 | public string AppName { get; set; } 23 | public string Content { get; set; } 24 | public string DataId { get; set; } 25 | public string Desc { get; set; } 26 | public string Group { get; set; } 27 | public string Md5 { get; set; } 28 | public string Tags { get; set; } 29 | public string Type { get; set; } 30 | } 31 | } -------------------------------------------------------------------------------- /H.Framework.Aliyun.ACM/AliyunRequest.cs: -------------------------------------------------------------------------------- 1 | using Aliyun.Acs.Core; 2 | using Aliyun.Acs.Core.Auth; 3 | using Aliyun.Acs.Core.Http; 4 | using Aliyun.Acs.Core.Profile; 5 | using H.Framework.Core.Utilities; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | 10 | namespace H.Framework.Aliyun.ACM 11 | { 12 | public class AliyunRequest 13 | { 14 | private readonly string _accessKey, _secretKey, _roleName; 15 | 16 | public AliyunRequest(string accessKey, string secretKey) 17 | { 18 | _accessKey = accessKey; 19 | _secretKey = secretKey; 20 | } 21 | 22 | public AliyunRequest(string roleName) 23 | { 24 | _roleName = roleName; 25 | } 26 | 27 | protected T RequestAliyun(string url, string version, MethodType methodType, string region, string domain, Dictionary args, Dictionary headers = null) 28 | { 29 | DefaultAcsClient client; 30 | if (headers == null) 31 | headers = new Dictionary { { "Content-Type", "application/x-www-form-urlencoded" } }; 32 | if (string.IsNullOrWhiteSpace(_roleName)) 33 | { 34 | if (string.IsNullOrWhiteSpace(_accessKey) || string.IsNullOrWhiteSpace(_secretKey)) 35 | throw new ArgumentException("ACK方式参数错误"); 36 | client = new DefaultAcsClient(DefaultProfile.GetProfile(region, _accessKey, _secretKey)); 37 | } 38 | else 39 | client = new DefaultAcsClient(DefaultProfile.GetProfile(region), new InstanceProfileCredentialsProvider(_roleName)); 40 | var request = new CommonRequest 41 | { 42 | Method = methodType, 43 | Domain = domain, 44 | Version = version, 45 | UriPattern = url 46 | }; 47 | // request.Protocol = ProtocolType.HTTP; 48 | foreach (var item in args) 49 | request.AddQueryParameters(item.Key, item.Value); 50 | foreach (var item in headers) 51 | request.AddHeadParameters(item.Key, item.Value); 52 | request.SetContent(System.Text.Encoding.Default.GetBytes(""), "utf-8", FormatType.JSON); 53 | var response = client.GetCommonResponse(request); 54 | return response.Data.ToJsonObj(); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /H.Framework.Aliyun.ACM/H.Framework.Aliyun.ACM.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.1 5 | 1.0.0.0 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /H.Framework.Aliyun.Log/H.Framework.Aliyun.Log.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | true 6 | AnyCPU;x64;x86 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /H.Framework.Aliyun.Log/LogCenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace H.Framework.Aliyun.Log 6 | { 7 | public sealed class LogCenter 8 | { 9 | private static readonly Lazy _lazy = new Lazy(() => new LogCenter()); 10 | public static LogCenter Instance => _lazy.Value; 11 | private static List _coreDic; 12 | private readonly object _locker = new object(); 13 | 14 | private LogCenter() 15 | { 16 | _coreDic = new List(); 17 | } 18 | 19 | public LogCore CoreInstance(string projectName, string accessKeyId = "", string secretAccessKey = "", string endpoint = "") 20 | { 21 | LogCore item = null; 22 | lock (_locker) 23 | { 24 | item = _coreDic.FirstOrDefault(x => x.ProjectName == projectName); 25 | if (item == null) 26 | { 27 | item = new LogCore(projectName, accessKeyId, secretAccessKey, endpoint); 28 | _coreDic.Add(item); 29 | } 30 | return item; 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /H.Framework.Aliyun.Log/LogCore.cs: -------------------------------------------------------------------------------- 1 | using Aliyun.Api.LogService; 2 | 3 | namespace H.Framework.Aliyun.Log 4 | { 5 | public class LogCore 6 | { 7 | public LogCore(string projectName, string accessKeyId, string secretAccessKey, string endpoint) 8 | { 9 | Client = LogServiceClientBuilders.HttpBuilder 10 | .Endpoint(endpoint, projectName) 11 | .Credential(accessKeyId, secretAccessKey) 12 | .Build(); 13 | ProjectName = projectName; 14 | } 15 | 16 | public ILogServiceClient Client { get; } 17 | 18 | public string ProjectName { get; private set; } 19 | } 20 | } -------------------------------------------------------------------------------- /H.Framework.Aliyun.MNS/H.Framework.Aliyun.MNS.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 1.0.0.1 6 | true 7 | AnyCPU;x64;x86 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /H.Framework.Aliyun.MNS/MNSCenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace H.Framework.Aliyun.MNS 6 | { 7 | public sealed class MNSCenter 8 | { 9 | private static readonly Lazy _lazy = new Lazy(() => new MNSCenter()); 10 | public static MNSCenter Instance => _lazy.Value; 11 | private static List _coreDic; 12 | private readonly object _locker = new object(); 13 | 14 | private MNSCenter() 15 | { 16 | _coreDic = new List(); 17 | } 18 | 19 | public MNSCore CoreInstance(string queueName, string accessKeyId = "", string secretAccessKey = "", string endpoint = "") 20 | { 21 | MNSCore item = null; 22 | lock (_locker) 23 | { 24 | item = _coreDic.FirstOrDefault(x => x.QueueName == queueName); 25 | if (item == null) 26 | { 27 | item = new MNSCore(queueName, accessKeyId, secretAccessKey, endpoint); 28 | _coreDic.Add(item); 29 | } 30 | return item; 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /H.Framework.Aliyun.MNS/MNSCore.cs: -------------------------------------------------------------------------------- 1 | using Aliyun.MNS; 2 | using Aliyun.MNS.Model; 3 | using System; 4 | 5 | namespace H.Framework.Aliyun.MNS 6 | { 7 | public class MNSCore 8 | { 9 | private readonly IMNS _client; 10 | private AsyncCallback _receiveMessageCallback; 11 | 12 | public MNSCore(string queueName, string accessKeyId, string secretAccessKey, string endpoint) 13 | { 14 | _client = new MNSClient(accessKeyId, secretAccessKey, endpoint); 15 | QueueName = queueName; 16 | } 17 | 18 | public string QueueName { get; private set; } 19 | 20 | public Queue Queue => _client.GetNativeQueue(QueueName); 21 | 22 | public SendMessageResponse Send(string messageContent) 23 | { 24 | try 25 | { 26 | return Queue.SendMessage(new SendMessageRequest(messageContent)); 27 | } 28 | catch (Exception ex) 29 | { 30 | Console.WriteLine("AsyncSend message failed, exception info: " + ex.Message); 31 | return null; 32 | } 33 | } 34 | 35 | public void SendAsync(string messageContent, AsyncCallback sendMessageCallback) 36 | { 37 | try 38 | { 39 | var sendMessageRequest = new SendMessageRequest(messageContent); 40 | Queue.BeginSendMessage(sendMessageRequest, sendMessageCallback, Queue); 41 | } 42 | catch (Exception ex) 43 | { 44 | Console.WriteLine("AsyncSend message failed, exception info: " + ex.Message); 45 | } 46 | } 47 | 48 | public void RegReceiveMessageCallback(AsyncCallback receiveMessageCallback) 49 | { 50 | _receiveMessageCallback += receiveMessageCallback; 51 | } 52 | 53 | public Message Receive() 54 | { 55 | try 56 | { 57 | return Queue.ReceiveMessage(30).Message; 58 | } 59 | catch (Exception ex) 60 | { 61 | Console.WriteLine("AsyncReceive message failed, exception info: " + ex.Message); 62 | return null; 63 | } 64 | } 65 | 66 | public void ReceiveAsync() 67 | { 68 | try 69 | { 70 | Queue.BeginReceiveMessage(new ReceiveMessageRequest(), _receiveMessageCallback, Queue); 71 | } 72 | catch (Exception ex) 73 | { 74 | Console.WriteLine("AsyncReceive message failed, exception info: " + ex.Message); 75 | } 76 | } 77 | 78 | public DeleteMessageResponse Delete(string receiptHandle) 79 | { 80 | try 81 | { 82 | var deleteMessageRequest = new DeleteMessageRequest(receiptHandle); 83 | return Queue.DeleteMessage(deleteMessageRequest); 84 | } 85 | catch (Exception ex) 86 | { 87 | Console.WriteLine("AsyncDeleteMessage failed, exception info: " + ex.Message); 88 | return null; 89 | } 90 | } 91 | 92 | public void DeleteAsync(string receiptHandle, AsyncCallback deleteMessageCallback) 93 | { 94 | try 95 | { 96 | var deleteMessageRequest = new DeleteMessageRequest(receiptHandle); 97 | Queue.BeginDeleteMessage(deleteMessageRequest, deleteMessageCallback, Queue); 98 | } 99 | catch (Exception ex) 100 | { 101 | Console.WriteLine("AsyncDeleteMessage failed, exception info: " + ex.Message); 102 | } 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /H.Framework.Core/Attributes/DataValidationAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace H.Framework.Core.Attributes 6 | { 7 | [AttributeUsage(AttributeTargets.Property)] 8 | public class DataValidationAttribute : ValidationAttribute 9 | { 10 | public DataValidationAttribute(Type validatorType, string method, string argProperty = null) 11 | { 12 | ValidatorType = validatorType; 13 | Method = method; 14 | ArgProperty = argProperty; 15 | } 16 | 17 | public Type ValidatorType { get; set; } 18 | 19 | public string Method { get; set; } 20 | 21 | public string ArgProperty { get; set; } 22 | 23 | protected override ValidationResult IsValid(object value, ValidationContext validationContext) 24 | { 25 | var param = new List { value }; 26 | if (!string.IsNullOrWhiteSpace(ArgProperty)) 27 | param.Add(ArgProperty == "this" ? validationContext.ObjectInstance : validationContext.ObjectInstance.GetType().GetProperty(ArgProperty)?.GetValue(validationContext.ObjectInstance)); 28 | return (ValidationResult)ValidatorType.GetMethod(Method)?.Invoke(null, param.ToArray()); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /H.Framework.Core/H.Framework.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | true 6 | H 7 | H.Framework 8 | C#整理的一些基础类库 9 | 2.0.6.5 10 | 2.0.6.5 11 | 2.0.6.5 12 | false 13 | AnyCPU;x64;x86 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /H.Framework.Core/List/IItemsProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace H.Framework.Core.List 8 | { 9 | public interface IItemsProvider 10 | { 11 | /// 12 | /// Fetches the total number of items available. 13 | /// 14 | /// 15 | int FetchCount(); 16 | 17 | /// 18 | /// Fetches a range of items. 19 | /// 20 | /// The start index. 21 | /// The number of items to fetch. 22 | /// 23 | IList FetchRange(int startIndex, int count); 24 | } 25 | } -------------------------------------------------------------------------------- /H.Framework.Core/Log/ILogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H.Framework.Core.Log 4 | { 5 | public interface ILogger 6 | { 7 | bool IsDebugEnabled { get; } 8 | 9 | void Debug(object message); 10 | 11 | void Debug(object message, Exception ex); 12 | 13 | void DebugFormat(string format, params object[] args); 14 | 15 | void DebugFormat(string format, object arg0); 16 | 17 | void DebugFormat(IFormatProvider provider, string format, params object[] args); 18 | 19 | void DebugFormat(string format, object arg0, object arg1); 20 | 21 | void DebugFormat(string format, object arg0, object arg1, object arg2); 22 | 23 | void Error(object message); 24 | 25 | void Error(object message, Exception ex); 26 | 27 | void ErrorFormat(string format, object arg0); 28 | 29 | void ErrorFormat(string format, params object[] args); 30 | 31 | void ErrorFormat(string format, object arg0, object arg1); 32 | 33 | void ErrorFormat(IFormatProvider provider, string format, params object[] args); 34 | 35 | void ErrorFormat(string format, object arg0, object arg1, object arg2); 36 | 37 | void Fatal(object message); 38 | 39 | void Fatal(object message, Exception ex); 40 | 41 | void FatalFormat(string format, params object[] args); 42 | 43 | void FatalFormat(string format, object arg0); 44 | 45 | void FatalFormat(string format, object arg0, object arg1); 46 | 47 | void FatalFormat(IFormatProvider provider, string format, params object[] args); 48 | 49 | void FatalFormat(string format, object arg0, object arg1, object arg2); 50 | 51 | void Info(object message); 52 | 53 | void Info(object message, Exception ex); 54 | 55 | void InfoFormat(string format, params object[] args); 56 | 57 | void InfoFormat(string format, object arg0); 58 | 59 | void InfoFormat(IFormatProvider provider, string format, params object[] args); 60 | 61 | void InfoFormat(string format, object arg0, object arg1); 62 | 63 | void InfoFormat(string format, object arg0, object arg1, object arg2); 64 | 65 | void Warn(object message); 66 | 67 | void Warn(object message, Exception ex); 68 | 69 | void WarnFormat(string format, params object[] args); 70 | 71 | void WarnFormat(string format, object arg0); 72 | 73 | void WarnFormat(IFormatProvider provider, string format, params object[] args); 74 | 75 | void WarnFormat(string format, object arg0, object arg1); 76 | 77 | void WarnFormat(string format, object arg0, object arg1, object arg2); 78 | } 79 | } -------------------------------------------------------------------------------- /H.Framework.Core/Log/LogHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | 5 | namespace H.Framework.Core.Log 6 | { 7 | public static class LogHelper 8 | { 9 | private static readonly object _locker = new object(); 10 | private static readonly Dictionary _loggers = new Dictionary(StringComparer.OrdinalIgnoreCase); 11 | 12 | public static void Register(ILogger logger, string name) 13 | { 14 | lock (_locker) 15 | { 16 | if (!_loggers.ContainsKey(name)) 17 | _loggers.Add(name, logger); 18 | } 19 | } 20 | 21 | public static ILogger GetLogger(string name) 22 | { 23 | lock (_locker) 24 | { 25 | return _loggers.TryGetValue(name, out ILogger result) ? result : null; 26 | } 27 | } 28 | 29 | /// 30 | /// 写入日志文件 31 | /// 32 | /// 33 | /// 34 | /// 35 | public static void WriteLogFile(LogMessage input, LogType logType, Exception innnerException = null) 36 | { 37 | GetLogger(Enum.GetName(typeof(LogType), logType)).Info(input, innnerException); 38 | } 39 | 40 | /// 41 | /// 写入日志文件 42 | /// 43 | /// 44 | /// 45 | /// 46 | public static void WriteLogFile(T input, LogType logType, Exception innnerException = null) 47 | { 48 | GetLogger(Enum.GetName(typeof(LogType), logType)).Info(input, innnerException); 49 | } 50 | 51 | ///// 52 | ///// 写入日志文件 53 | ///// 54 | ///// 55 | ///// 56 | ///// 57 | //public static void WriteLogFile(string input, LogType logType, Exception innnerException = null) 58 | //{ 59 | // WriteLogFile(input, logType, innnerException); 60 | //} 61 | 62 | public static void WriteLogFile(string title, object data, LogType logType, Exception innnerException = null) 63 | { 64 | WriteLogFile(new LogMessage { Title = title, Data = data }, logType, innnerException); 65 | } 66 | 67 | public static Task WriteLogFileAsync(LogMessage input, LogType logType, Exception innnerException = null) 68 | { 69 | return Task.Run(() => 70 | { 71 | lock (_locker) 72 | { 73 | WriteLogFile(input, logType, innnerException); 74 | } 75 | }); 76 | } 77 | 78 | public static Task WriteLogFileAsync(T input, LogType logType, Exception innnerException = null) 79 | { 80 | return Task.Run(() => 81 | { 82 | lock (_locker) 83 | { 84 | WriteLogFile(input, logType, innnerException); 85 | } 86 | }); 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /H.Framework.Core/Log/LogMessage.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | 4 | namespace H.Framework.Core.Log 5 | { 6 | public class LogMessage 7 | { 8 | public LogMessage() 9 | { 10 | TimeStamp = DateTimeOffset.Now.ToString("O"); 11 | } 12 | 13 | public string Title { get; set; } 14 | 15 | public string TimeStamp { get; set; } 16 | 17 | public T Data { get; set; } 18 | 19 | public override string ToString() 20 | { 21 | return JsonConvert.SerializeObject(this); 22 | } 23 | } 24 | 25 | public enum LogType 26 | { 27 | Error, 28 | Business, 29 | System, 30 | Other, 31 | Aliyun 32 | } 33 | } -------------------------------------------------------------------------------- /H.Framework.Core/Mapping/ICustomMap.cs: -------------------------------------------------------------------------------- 1 | namespace H.Framework.Core.Mapping 2 | { 3 | public interface ICustomMap 4 | { 5 | void MapFrom(T source); 6 | } 7 | 8 | public interface ICustomMap 9 | { 10 | void MapFrom(object source); 11 | } 12 | } -------------------------------------------------------------------------------- /H.Framework.Core/Mapping/Mapping.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace H.Framework.Core.Mapping 5 | { 6 | public class Mapping 7 | { 8 | public static implicit operator TResult(Mapping m) 9 | { 10 | return m.Result(); 11 | } 12 | 13 | public Mapping(Expression> source, Expression> target) 14 | { 15 | Source = source; 16 | } 17 | 18 | public Expression> Source { get; } 19 | 20 | public Mapping Property(Expression> property, Expression> target) 21 | { 22 | var x = property.Compile(); 23 | var source = Expression.Lambda>(property, null); 24 | var mapping = new Mapping(source, target); 25 | return this; 26 | } 27 | 28 | public Expression> Build() 29 | { 30 | //LambdaExpression>> e; 31 | return Expression.Lambda>(null, null); 32 | } 33 | 34 | public TResult Result() 35 | { 36 | return Build().Compile().Invoke(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /H.Framework.Core/Mapping/MappingSourceAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H.Framework.Core.Mapping 4 | { 5 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] 6 | public class MappingSourceAttribute : Attribute 7 | { 8 | public MappingSourceAttribute(string name) 9 | : this(null, name) 10 | { } 11 | 12 | public MappingSourceAttribute(Type type, string name) 13 | { 14 | this.SourceType = type; 15 | this.Name = name; 16 | } 17 | 18 | public Type SourceType { get; } 19 | 20 | public string Name { get; } 21 | } 22 | 23 | public class MappingIgnoreAttribute : Attribute 24 | { } 25 | } -------------------------------------------------------------------------------- /H.Framework.Core/Utilities/EndianExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace H.Framework.Core.Utilities 2 | { 3 | // 4 | /// 字节序转换扩展 5 | /// 6 | public static class EndianExtensions 7 | { 8 | public static short SwapInt16(this short n) 9 | { 10 | return (short)(((n & 0xff) << 8) | ((n >> 8) & 0xff)); 11 | } 12 | 13 | public static ushort SwapUInt16(this ushort n) 14 | { 15 | return (ushort)(((n & 0xff) << 8) | ((n >> 8) & 0xff)); 16 | } 17 | 18 | public static int SwapInt32(this int n) 19 | { 20 | return ((SwapInt16((short)n) & 0xffff) << 0x10) | 21 | (SwapInt16((short)(n >> 0x10)) & 0xffff); 22 | } 23 | 24 | public static uint SwapUInt32(this uint n) 25 | { 26 | return (uint)(((SwapUInt16((ushort)n) & 0xffff) << 0x10) | 27 | (SwapUInt16((ushort)(n >> 0x10)) & 0xffff)); 28 | } 29 | 30 | public static long SwapInt64(this long n) 31 | { 32 | return ((SwapInt32((int)n) & 0xffffffffL) << 0x20) | 33 | (SwapInt32((int)(n >> 0x20)) & 0xffffffffL); 34 | } 35 | 36 | public static ulong SwapUInt64(this ulong n) 37 | { 38 | return (ulong)(((SwapUInt32((uint)n) & 0xffffffffL) << 0x20) | 39 | (SwapUInt32((uint)(n >> 0x20)) & 0xffffffffL)); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /H.Framework.Core/Utilities/EqualityComparerUtility.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace H.Framework.Core.Utilities 8 | { 9 | public class EqualityComparerUtility : IEqualityComparer 10 | { 11 | private string _propName; 12 | 13 | public EqualityComparerUtility(string propName) 14 | { 15 | _propName = propName; 16 | if (string.IsNullOrWhiteSpace(_propName)) 17 | throw new ArgumentException("_propName不能为空"); 18 | } 19 | 20 | public bool Equals(T x, T y) 21 | { 22 | var property = x.GetType().GetProperty(_propName); 23 | if (property == null) 24 | throw new ArgumentException("找不到这个" + _propName + "属性"); 25 | return property?.GetValue(x) == property?.GetValue(y); 26 | } 27 | 28 | public int GetHashCode(T obj) 29 | { 30 | if (obj == null) 31 | return 0; 32 | return obj.GetType().GetProperty(_propName).GetHashCode(); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /H.Framework.Core/Utilities/TimeHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace H.Framework.Core.Utilities 5 | { 6 | public static class TimeHelper 7 | { 8 | static TimeHelper() 9 | { 10 | Watch = new Stopwatch(); 11 | } 12 | 13 | /// 14 | /// 服务器初始化时间 15 | /// 16 | public static DateTime ServerInitTime 17 | { 18 | private get => _serverInitTime; 19 | set 20 | { 21 | _serverInitTime = value; 22 | Watch.Restart(); 23 | } 24 | } 25 | 26 | /// 27 | /// 本地Stopwatch 28 | /// 29 | public static Stopwatch Watch { get; } 30 | 31 | private static DateTime _serverInitTime; 32 | 33 | /// 34 | /// 服务器当前时间 35 | /// 36 | public static DateTime CurrentServerTime => ServerInitTime.AddMilliseconds(Watch.ElapsedMilliseconds); 37 | 38 | public static long UtcSeconds() 39 | { 40 | return DateTime.UtcNow.ToLong(); 41 | } 42 | 43 | //public static long UtcSeconds(this DateTime time) 44 | //{ 45 | // return (time.ToUniversalTime().Ticks - 621355968000000000) / 10000000; 46 | //} 47 | 48 | public static DateTime ToDateTime(this long d, bool isMillisecond = false) 49 | { 50 | var start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 51 | var resultTime = isMillisecond ? start.AddMilliseconds(d) : start.AddSeconds(d); 52 | return resultTime.AddHours(8); 53 | } 54 | 55 | public static long ToLong(this DateTime dt, bool isMillisecond = false) 56 | { 57 | //var dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); 58 | //var toNow = dt.Subtract(dtStart); 59 | //var timeStamp = toNow.Ticks; 60 | //var len = isMillisecond ? 4 : 7; 61 | //timeStamp = long.Parse(timeStamp.ToString().Substring(0, timeStamp.ToString().Length - len)); 62 | //return timeStamp; 63 | var jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 64 | var result = dt.AddHours(-8) - jan1st1970; 65 | if (isMillisecond) 66 | return (long)result.TotalMilliseconds; 67 | else 68 | return (long)result.TotalSeconds; 69 | } 70 | 71 | } 72 | } -------------------------------------------------------------------------------- /H.Framework.Core/Utilities/Utility.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H.Framework.Core.Utilities 4 | { 5 | public class Utility 6 | { 7 | public static string ObjectID => Guid.NewGuid().ToString("N"); 8 | } 9 | } -------------------------------------------------------------------------------- /H.Framework.Core/Utilities/ValidationExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | 6 | namespace H.Framework.Core.Utilities 7 | { 8 | public static class ValidationExtension 9 | { 10 | public static string ValidateProperty(this object obj, string columnName) 11 | { 12 | var vc = new ValidationContext(obj); 13 | vc.MemberName = columnName; 14 | var res = new List(); 15 | Validator.TryValidateProperty(obj.GetType().GetProperty(columnName).GetValue(obj, null), vc, res); 16 | if (res.Count > 0) 17 | { 18 | return string.Join(Environment.NewLine, res.Select(r => r.ErrorMessage).ToArray()); 19 | } 20 | return string.Empty; 21 | } 22 | 23 | //public static string ValidateProperty(this object obj, string propertyName) 24 | //{ 25 | // if (string.IsNullOrEmpty(propertyName)) 26 | // return string.Empty; 27 | 28 | // var targetType = obj.GetType(); 29 | // //也可以利用 MetadataType 在分离类上声明 30 | // //var targetMetadataAttr = targetType.GetCustomAttributes(false) 31 | // // .FirstOrDefault(a => a.GetType() == typeof(MetadataTypeAttribute)) as MetadataTypeAttribute; 32 | // //if (targetMetadataAttr != null && targetType != targetMetadataAttr.MetadataClassType) 33 | // //{ 34 | // // TypeDescriptor.AddProviderTransparent( 35 | // // new AssociatedMetadataTypeTypeDescriptionProvider(targetType, targetMetadataAttr.MetadataClassType), targetType); 36 | // //} 37 | // if (targetType != typeof(MetaDataType)) 38 | // { 39 | // TypeDescriptor.AddProviderTransparent( 40 | // new AssociatedMetadataTypeTypeDescriptionProvider(targetType, typeof(MetaDataType)), targetType); 41 | // } 42 | 43 | // var propertyValue = targetType.GetProperty(propertyName).GetValue(obj, null); 44 | // var validationContext = new ValidationContext(obj, null, null); 45 | // validationContext.MemberName = propertyName; 46 | // var validationResults = new List(); 47 | 48 | // Validator.TryValidateProperty(propertyValue, validationContext, validationResults); 49 | 50 | // if (validationResults.Count > 0) 51 | // { 52 | // return validationResults.First().ErrorMessage; 53 | // } 54 | // return string.Empty; 55 | //} 56 | } 57 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Attributes/DataFieldAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H.Framework.Data.ORM.Attributes 4 | { 5 | [AttributeUsage(AttributeTargets.Property)] 6 | public sealed class DataFieldAttribute : Attribute 7 | { 8 | /// 9 | /// 表映射的字段名 10 | /// 11 | public string ColumnName { set; get; } 12 | 13 | /// 14 | /// 构造函数 15 | /// 16 | /// 表映射的字段名 17 | public DataFieldAttribute(string columnName) 18 | { 19 | ColumnName = columnName; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Attributes/DataFieldIgnoreAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H.Framework.Data.ORM.Attributes 4 | { 5 | [AttributeUsage(AttributeTargets.Property)] 6 | public sealed class DataFieldIgnoreAttribute : Attribute 7 | { 8 | /// 9 | /// 表对应的字段名 10 | /// 11 | public string ColumnName { set; get; } 12 | 13 | public DataFieldIgnoreAttribute(string columnName) 14 | { 15 | ColumnName = columnName; 16 | } 17 | 18 | public DataFieldIgnoreAttribute() 19 | { 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Attributes/DataTableAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace H.Framework.Data.ORM.Attributes 6 | { 7 | [AttributeUsage(AttributeTargets.Class)] 8 | public class DataTableAttribute : Attribute 9 | { 10 | /// 11 | /// 表映射的表名 12 | /// 13 | public string TableName { set; get; } 14 | 15 | /// 16 | /// 构造函数 17 | /// 18 | /// 表映射的表名 19 | public DataTableAttribute(string tableName) 20 | { 21 | TableName = tableName; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Attributes/DetailListAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H.Framework.Data.ORM.Attributes 4 | { 5 | /// 6 | /// 三个参数为多对多用,一对多,在外键表设置ForeignKeyID,三个参数不设置 7 | /// 8 | [AttributeUsage(AttributeTargets.Property)] 9 | public sealed class DetailListAttribute : Attribute 10 | { 11 | /// 12 | /// 多对多中间表名 13 | /// 14 | public string TableName { set; get; } 15 | 16 | /// 17 | /// 多对多中间表对应的字段名 18 | /// 19 | public string ForeignKeyIDName { set; get; } 20 | 21 | /// 22 | /// 多对多中间表对应的字段名 23 | /// 24 | public string ForeignKeyIDName2 { set; get; } 25 | 26 | /// 27 | /// 构造函数 28 | /// 29 | /// 多对多中间表名 30 | /// 多对多中间表对应的字段名 31 | /// 多对多中间表对应的字段名 32 | public DetailListAttribute(string tableName = "", string foreignKeyIDName = "", string foreignKeyIDName2 = "") 33 | { 34 | TableName = tableName; 35 | ForeignKeyIDName = foreignKeyIDName; 36 | ForeignKeyIDName2 = foreignKeyIDName2; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Attributes/DynamicSQLFieldAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace H.Framework.Data.ORM.Attributes 6 | { 7 | [AttributeUsage(AttributeTargets.Property)] 8 | public class DynamicSQLFieldAttribute : Attribute 9 | { 10 | /// 11 | /// 动态sql语句 12 | /// 13 | public string SQLString { set; get; } 14 | 15 | /// 16 | /// 构造函数 17 | /// 18 | /// 动态sql语句 19 | public DynamicSQLFieldAttribute(string sqlString) 20 | { 21 | SQLString = sqlString; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Attributes/ForeignAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H.Framework.Data.ORM.Attributes 4 | { 5 | [AttributeUsage(AttributeTargets.Property)] 6 | public sealed class ForeignAttribute : Attribute 7 | { 8 | /// 9 | /// 对应的关联表名 10 | /// 11 | public string TableName { set; get; } 12 | 13 | /// 14 | /// 对应的外键属性名 15 | /// 16 | public string ForeignKeyIDPropName { set; get; } 17 | 18 | /// 19 | /// 关联表主键名 20 | /// 21 | public string ForeignPrimaryKeyIDName { set; get; } 22 | 23 | /// 24 | /// 构造函数 25 | /// 26 | /// 对应的关联表名 27 | /// 对应的外键属性名 28 | /// 关联表主键名 29 | public ForeignAttribute(string tableName, string foreignKeyIDPropName, string foreignPrimaryKeyIDName = "") 30 | { 31 | TableName = tableName; 32 | ForeignKeyIDPropName = foreignKeyIDPropName; 33 | ForeignPrimaryKeyIDName = foreignPrimaryKeyIDName; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Attributes/ForeignKeyIDAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H.Framework.Data.ORM.Attributes 4 | { 5 | /// 6 | /// 一对多,在外键表设置ForeignKeyID 7 | /// 8 | [AttributeUsage(AttributeTargets.Property)] 9 | public sealed class ForeignKeyIDAttribute : Attribute 10 | { 11 | /// 12 | /// 表对应的字段名 13 | /// 14 | public string TableName { set; get; } 15 | 16 | /// 17 | /// 构造函数 18 | /// 19 | /// 表对应的字段名 20 | public ForeignKeyIDAttribute(string tableName = "") 21 | { 22 | TableName = tableName; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Attributes/LastIDConditionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H.Framework.Data.ORM.Attributes 4 | { 5 | /// 6 | /// 查询最新自增ID的条件 7 | /// 8 | [AttributeUsage(AttributeTargets.Property)] 9 | public class LastIDConditionAttribute : Attribute 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Attributes/OnlyQueryAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace H.Framework.Data.ORM.Attributes 6 | { 7 | [AttributeUsage(AttributeTargets.Property)] 8 | public class OnlyQueryAttribute : Attribute 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Attributes/PrimaryKeyIDAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H.Framework.Data.ORM.Attributes 4 | { 5 | [AttributeUsage(AttributeTargets.Property)] 6 | public class PrimaryKeyIDAttribute : Attribute 7 | { 8 | /// 9 | /// 主键对应的字段名 10 | /// 11 | public string KeyName { set; get; } 12 | 13 | /// 14 | /// 构造函数 15 | /// 16 | /// 主键对应的字段名 17 | public PrimaryKeyIDAttribute(string keyName = "") 18 | { 19 | keyName = KeyName; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/BaseBLL.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.Data.ORM.Foundations; 2 | 3 | namespace H.Framework.Data.ORM 4 | { 5 | public abstract class BaseBLL : FoundationBLL where TViewModel : IFoundationViewModel, new() where TModel : IFoundationModel, new() where TDAL : BaseDAL, new() 6 | { 7 | } 8 | 9 | public abstract class BaseBLL : FoundationBLL where TViewModel : IFoundationViewModel, new() where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TDAL : BaseDAL, new() 10 | { 11 | } 12 | 13 | public abstract class BaseBLL : FoundationBLL where TViewModel : IFoundationViewModel, new() where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TForeignModel1 : IFoundationModel, new() where TDAL : BaseDAL, new() 14 | { 15 | } 16 | 17 | public abstract class BaseBLL : FoundationBLL where TViewModel : IFoundationViewModel, new() where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TForeignModel1 : IFoundationModel, new() where TForeignModel2 : IFoundationModel, new() where TDAL : BaseDAL, new() 18 | { 19 | } 20 | 21 | public abstract class BaseBLL : FoundationBLL where TViewModel : IFoundationViewModel, new() where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TForeignModel1 : IFoundationModel, new() where TForeignModel2 : IFoundationModel, new() where TForeignModel3 : IFoundationModel, new() where TDAL : BaseDAL, new() 22 | { 23 | } 24 | 25 | public abstract class BaseBLL : FoundationBLL where TViewModel : IFoundationViewModel, new() where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TForeignModel1 : IFoundationModel, new() where TForeignModel2 : IFoundationModel, new() where TForeignModel3 : IFoundationModel, new() where TForeignModel4 : IFoundationModel, new() where TDAL : BaseDAL, new() 26 | { 27 | } 28 | 29 | public abstract class BaseBLL : FoundationBLL where TViewModel : IFoundationViewModel, new() where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TForeignModel1 : IFoundationModel, new() where TForeignModel2 : IFoundationModel, new() where TForeignModel3 : IFoundationModel, new() where TForeignModel4 : IFoundationModel, new() where TForeignModel5 : IFoundationModel, new() where TDAL : BaseDAL, new() 30 | { 31 | } 32 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/BaseDAL.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.Data.ORM.Foundations; 2 | 3 | namespace H.Framework.Data.ORM 4 | { 5 | public abstract class BaseDAL : FoundationDAL where TModel : IFoundationModel, new() 6 | { 7 | public BaseDAL() 8 | { } 9 | } 10 | 11 | public abstract class BaseDAL : FoundationDAL where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() 12 | { 13 | public BaseDAL() 14 | { } 15 | } 16 | 17 | public abstract class BaseDAL : FoundationDAL where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TForeignModel1 : IFoundationModel, new() 18 | { 19 | public BaseDAL() 20 | { } 21 | } 22 | 23 | public abstract class BaseDAL : FoundationDAL where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TForeignModel1 : IFoundationModel, new() where TForeignModel2 : IFoundationModel, new() 24 | { 25 | public BaseDAL() 26 | { } 27 | } 28 | 29 | public abstract class BaseDAL : FoundationDAL where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TForeignModel1 : IFoundationModel, new() where TForeignModel2 : IFoundationModel, new() where TForeignModel3 : IFoundationModel, new() 30 | { 31 | public BaseDAL() 32 | { } 33 | } 34 | 35 | public abstract class BaseDAL : FoundationDAL where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TForeignModel1 : IFoundationModel, new() where TForeignModel2 : IFoundationModel, new() where TForeignModel3 : IFoundationModel, new() where TForeignModel4 : IFoundationModel, new() 36 | { 37 | public BaseDAL() 38 | { } 39 | } 40 | 41 | public abstract class BaseDAL : FoundationDAL where TModel : IFoundationModel, new() where TForeignModel : IFoundationModel, new() where TForeignModel1 : IFoundationModel, new() where TForeignModel2 : IFoundationModel, new() where TForeignModel3 : IFoundationModel, new() where TForeignModel4 : IFoundationModel, new() where TForeignModel5 : IFoundationModel, new() 42 | { 43 | public BaseDAL() 44 | { } 45 | } 46 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Foundations/IFoundationBLL.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Threading.Tasks; 5 | 6 | namespace H.Framework.Data.ORM.Foundations 7 | { 8 | public interface IFoundationBLL where TViewModel : IFoundationViewModel, new() 9 | { 10 | Task AddAsync(List list); 11 | 12 | Task AddAsync(TViewModel model); 13 | 14 | Task DeleteAsync(List ids); 15 | 16 | Task DeleteAsync(string id); 17 | 18 | Task DeleteLogicAsync(string id); 19 | 20 | Task UpdateAsync(List list, string include = ""); 21 | 22 | Task UpdateAsync(TViewModel model, string include = ""); 23 | 24 | Task GetAsync(Expression> whereSelector, string include = "", IEnumerable orderBy = null); 25 | 26 | Task> GetListAsync(Expression> whereSelector, string include = "", IEnumerable orderBy = null); 27 | 28 | Task> GetListAsync(Expression> whereSelector, int pageSize, int pageNum, string include = "", IEnumerable orderBy = null); 29 | 30 | //List ExecuteQuerySQL(string sqlText); 31 | 32 | Task CountAsync(Expression> whereSelector); 33 | 34 | Task> GetListAsync(WhereQueryable whereSelector, string include = "", IEnumerable orderBy = null); 35 | 36 | Task> GetListAsync(WhereQueryable whereSelector, int pageSize, int pageNum, string include = "", IEnumerable orderBy = null); 37 | 38 | Task CountAsync(WhereQueryable whereSelector); 39 | } 40 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Foundations/IFoundationDAL.cs: -------------------------------------------------------------------------------- 1 | using MySql.Data.MySqlClient; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq.Expressions; 5 | using System.Threading.Tasks; 6 | 7 | namespace H.Framework.Data.ORM.Foundations 8 | { 9 | public interface IFoundationDAL where TModel : IFoundationModel, new() 10 | { 11 | Task> GetListAsync(Expression> whereSelector, int pageSize, int pageNum, string include = "", IEnumerable orderBy = null); 12 | 13 | Task> GetListAsync(Expression> whereSelector, string include = "", IEnumerable orderBy = null); 14 | 15 | Task GetAsync(Expression> whereSelector, string include = "", IEnumerable orderBy = null); 16 | 17 | Task DeleteAsync(string id); 18 | 19 | Task DeleteAsync(List ids); 20 | 21 | Task DeleteLogicAsync(TModel model); 22 | 23 | Task UpdateAsync(IEnumerable list, string include = ""); 24 | 25 | Task AddAsync(IEnumerable list); 26 | 27 | Task> ExecuteQuerySQLAsync(string sqlText, params MySqlParameter[] param) where T : new(); 28 | 29 | Task>> ExecuteQueryMutiSQLAsync(string sqlText, string[] keys, params MySqlParameter[] param) where T : new(); 30 | 31 | Task CountAsync(Expression> whereSelector); 32 | } 33 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Foundations/IFoundationModel.cs: -------------------------------------------------------------------------------- 1 | namespace H.Framework.Data.ORM.Foundations 2 | { 3 | public interface IFoundationModel 4 | { 5 | string ID { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Foundations/IFoundationViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace H.Framework.Data.ORM.Foundations 2 | { 3 | public interface IFoundationViewModel 4 | { 5 | string ID { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Foundations/OrderByEntity.cs: -------------------------------------------------------------------------------- 1 | namespace H.Framework.Data.ORM.Foundations 2 | { 3 | public class OrderByEntity 4 | { 5 | public string KeyWord { get; set; } 6 | public bool IsAsc { get; set; } 7 | public bool IsMainTable { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/Foundations/SqlParamModel.cs: -------------------------------------------------------------------------------- 1 | using MySql.Data.MySqlClient; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace H.Framework.Data.ORM.Foundations 7 | { 8 | public class SqlParamModel 9 | { 10 | public SqlParamModel(string mainTableName, string joinTableName, string columnName, string simpleColumnName, string joinColumnName, List listDynamicSQLField = null) 11 | { 12 | MainTableName = mainTableName; 13 | JoinTableName = joinTableName; 14 | SimpleColumnName = simpleColumnName; 15 | JoinColumnName = joinColumnName; 16 | ColumnName = columnName.TrimEnd(','); 17 | 18 | ListSqlParams = new List(); 19 | ListDynamicSQLField = listDynamicSQLField; 20 | } 21 | 22 | public string MainTableName { get; set; } 23 | public string JoinTableName { get; set; } 24 | 25 | public string TableName => MainTableName + JoinTableName; 26 | 27 | public string ColumnName { get; set; } 28 | 29 | public string PageColumnName { get; set; } 30 | 31 | public string SimpleColumnName { get; set; } 32 | 33 | public string MainColumnName { get; set; } 34 | public string JoinColumnName { get; set; } 35 | 36 | public string WhereSQL { get; set; } 37 | public string JoinWhereSQL { get; set; } 38 | 39 | public string MainWhereSQL { get; set; } 40 | 41 | public List ListSqlParams { get; set; } 42 | 43 | public List ListTableMap { get; set; } 44 | 45 | public List ListDynamicSQLField { get; set; } 46 | } 47 | } -------------------------------------------------------------------------------- /H.Framework.Data.ORM/H.Framework.Data.ORM.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.1 5 | 1.0.9.0 6 | true 7 | 1.0.7.0 8 | 1.0.7.0 9 | H 10 | Alvin Huang 11 | H.Framework 12 | AnyCPU;x64;x86 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /H.Framework.NETCore.IoC/Autofac/IDependencyRegistrar.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace H.Framework.NETCore.IoC.Autofac 6 | { 7 | public interface IDependencyRegistrar 8 | { 9 | /// 10 | /// Register services and interfaces 11 | /// 12 | /// Container builder 13 | /// Config 14 | void Register(ContainerBuilder builder, List listType); 15 | 16 | /// 17 | /// Order of this dependency registrar implementation 18 | /// 19 | int Order { get; } 20 | } 21 | } -------------------------------------------------------------------------------- /H.Framework.NETCore.IoC/Autofac/IIoCManager.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Core; 3 | using System; 4 | 5 | namespace H.Framework.NETCore.IoC.Autofac 6 | { 7 | public interface IIoCManager 8 | { 9 | IContainer Container { get; } 10 | 11 | bool IsRegistered(Type serviceType); 12 | 13 | object Resolve(Type type); 14 | 15 | T Resolve(string key = "") where T : class; 16 | 17 | T Resolve(params Parameter[] parameters) where T : class; 18 | 19 | T[] ResolveAll(string key = ""); 20 | 21 | object ResolveOptional(Type serviceType); 22 | 23 | object ResolveUnregistered(Type type); 24 | 25 | T ResolveUnregistered() where T : class; 26 | 27 | void InitScope(); 28 | 29 | ILifetimeScope Scope { get; set; } 30 | 31 | bool TryResolve(Type serviceType, out object instance); 32 | } 33 | } -------------------------------------------------------------------------------- /H.Framework.NETCore.IoC/Autofac/ISingletonDependency.cs: -------------------------------------------------------------------------------- 1 | namespace H.Framework.NETCore.IoC.Autofac 2 | { 3 | public interface ISingletonDependency 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /H.Framework.NETCore.IoC/Autofac/ITransientDependency.cs: -------------------------------------------------------------------------------- 1 | namespace H.Framework.NETCore.IoC.Autofac 2 | { 3 | public interface ITransientDependency 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /H.Framework.NETCore.IoC/H.Framework.NETCore.IoC.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | 1.0.0.5 6 | 1.0.0.5 7 | false 8 | true 9 | AnyCPU;x64;x86 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /H.Framework.U-Push/Bases/IPush.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace H.Framework.UMeng.Push.Bases 6 | { 7 | public interface IPush 8 | { 9 | ReturnJsonClass SendMessage(PostUMengJson paramsJsonObj) where T : class, new(); 10 | 11 | void AsynSendMessage(PostUMengJson paramsJsonObj, Action callback) where T : class, new(); 12 | } 13 | } -------------------------------------------------------------------------------- /H.Framework.U-Push/Bases/ReturnJsonClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace H.Framework.UMeng.Push.Bases 6 | { 7 | public class ReturnJsonClass 8 | { 9 | /// 10 | /// 返回结果,"SUCCESS"或者"FAIL" 11 | /// 12 | public string Ret { get; set; } 13 | 14 | /// 15 | /// 结果具体信息 16 | /// 17 | public ResultInfo Data { get; set; } 18 | } 19 | 20 | public class ResultInfo 21 | { 22 | /// 23 | /// 当"ret"为"SUCCESS"时,包含如下参数: 24 | /// 当type为unicast、listcast或者customizedcast且alias不为空时: 25 | /// 26 | public string Msg_Id { get; set; } 27 | 28 | /// 29 | /// 当type为于broadcast、groupcast、filecast、customizedcast且file_id不为空的情况(任务) 30 | /// 31 | public string Task_id { get; set; } 32 | 33 | /// 34 | /// 当"ret"为"FAIL"时,包含如下参数:错误码详见附录I。 35 | /// 36 | public int Error_Code { get; set; } 37 | 38 | /// 39 | /// 当"ret"为"FAIL"时,包含如下参数:错误信息 40 | /// 41 | public string Error_Msg { get; set; } 42 | 43 | /// 44 | /// 如果开发者填写了thirdparty_id, 接口也会返回该值。 45 | /// 46 | public string Thirdparty_Id { get; set; } 47 | } 48 | } -------------------------------------------------------------------------------- /H.Framework.U-Push/Bases/SerializableDictionary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Xml; 5 | using System.Xml.Schema; 6 | using System.Xml.Serialization; 7 | 8 | namespace H.Framework.UMeng.Push.Bases 9 | { 10 | #region 序列化及反序列化对象 11 | 12 | [Serializable] 13 | public class SerializableDictionary : Dictionary, IXmlSerializable 14 | { 15 | public SerializableDictionary() 16 | { 17 | } 18 | 19 | public void WriteXml(XmlWriter write) 20 | { 21 | var keySerializer = new XmlSerializer(typeof(TKey)); 22 | var valueSerializer = new XmlSerializer(typeof(TValue)); 23 | 24 | foreach (KeyValuePair kv in this) 25 | { 26 | write.WriteStartElement("SerializableDictionary"); 27 | write.WriteStartElement("key"); 28 | keySerializer.Serialize(write, kv.Key); 29 | write.WriteEndElement(); 30 | write.WriteStartElement("value"); 31 | valueSerializer.Serialize(write, kv.Value); 32 | write.WriteEndElement(); 33 | write.WriteEndElement(); 34 | } 35 | } 36 | 37 | public void ReadXml(XmlReader reader) 38 | { 39 | reader.Read(); 40 | var keySerializer = new XmlSerializer(typeof(TKey)); 41 | var valueSerializer = new XmlSerializer(typeof(TValue)); 42 | 43 | while (reader.NodeType != XmlNodeType.EndElement) 44 | { 45 | reader.ReadStartElement("SerializableDictionary"); 46 | reader.ReadStartElement("key"); 47 | TKey tk = (TKey)keySerializer.Deserialize(reader); 48 | reader.ReadEndElement(); 49 | reader.ReadStartElement("value"); 50 | TValue vl = (TValue)valueSerializer.Deserialize(reader); 51 | reader.ReadEndElement(); 52 | reader.ReadEndElement(); 53 | this.Add(tk, vl); 54 | reader.MoveToContent(); 55 | } 56 | reader.ReadEndElement(); 57 | } 58 | 59 | public XmlSchema GetSchema() 60 | { 61 | return null; 62 | } 63 | } 64 | 65 | #endregion 序列化及反序列化对象 66 | } -------------------------------------------------------------------------------- /H.Framework.U-Push/H.Framework.UMeng.Push.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.1 5 | H.Framework.UMeng.Push 6 | 1.0.0.5 7 | true 8 | 1.0.0.5 9 | AnyCPU;x64;x86 10 | 1.0.0.5 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Adorners/BusyAdorner.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.WPF.Control.Controls; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Documents; 9 | using System.Windows.Media; 10 | 11 | namespace H.Framework.WPF.Control.Adorners 12 | { 13 | public class BusyAdorner : Adorner 14 | { 15 | public event EventHandler Cancel; 16 | 17 | protected override int VisualChildrenCount 18 | { 19 | get { return 1; } 20 | } 21 | 22 | public BusyAdorner(UIElement adornedElement) 23 | : base(adornedElement) 24 | { 25 | this.IsHitTestVisible = true; 26 | 27 | this.chrome = new BusyChrome(); 28 | chrome.DataContext = adornedElement; 29 | this.AddVisualChild(chrome); 30 | } 31 | 32 | public void FireCancel() 33 | { 34 | if (Cancel != null) { Cancel(this, EventArgs.Empty); } 35 | } 36 | 37 | protected override Visual GetVisualChild(int index) 38 | { 39 | return this.chrome; 40 | } 41 | 42 | protected override Size ArrangeOverride(Size arrangeBounds) 43 | { 44 | this.chrome.Arrange(new Rect(arrangeBounds)); 45 | return arrangeBounds; 46 | } 47 | 48 | private BusyChrome chrome; 49 | } 50 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Adorners/DragAdorner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Documents; 9 | using System.Windows.Media; 10 | 11 | namespace H.Framework.WPF.Control.Adorners 12 | { 13 | public class DragAdorner : Adorner 14 | { 15 | public DragAdorner(UIElement parent) 16 | : base(parent) 17 | { 18 | IsHitTestVisible = false; // Seems Adorner is hit test visible? 19 | mDraggedElement = parent as FrameworkElement; 20 | } 21 | 22 | protected override void OnRender(DrawingContext drawingContext) 23 | { 24 | base.OnRender(drawingContext); 25 | 26 | if (mDraggedElement != null) 27 | { 28 | Win32.POINT screenPos = new Win32.POINT(); 29 | if (Win32.GetCursorPos(ref screenPos)) 30 | { 31 | Point pos = PointFromScreen(new Point(screenPos.X, screenPos.Y)); 32 | Rect rect = new Rect(pos.X - mDraggedElement.ActualWidth / 2, pos.Y - mDraggedElement.ActualHeight / 2, mDraggedElement.ActualWidth, mDraggedElement.ActualHeight); 33 | drawingContext.PushOpacity(1.0); 34 | Brush highlight = mDraggedElement.TryFindResource(SystemColors.HighlightBrushKey) as Brush; 35 | if (highlight != null) 36 | drawingContext.DrawRectangle(highlight, new Pen(Brushes.Transparent, 0), rect); 37 | drawingContext.DrawRectangle(new VisualBrush(mDraggedElement), 38 | new Pen(Brushes.Transparent, 0), rect); 39 | drawingContext.Pop(); 40 | } 41 | } 42 | } 43 | 44 | private FrameworkElement mDraggedElement = null; 45 | } 46 | 47 | public static class Win32 48 | { 49 | public struct POINT { public Int32 X; public Int32 Y; } 50 | 51 | // During drag-and-drop operations, the position of the mouse cannot be 52 | // reliably determined through GetPosition. This is because control of 53 | // the mouse (possibly including capture) is held by the originating 54 | // element of the drag until the drop is completed, with much of the 55 | // behavior controlled by underlying Win32 calls. As a workaround, you 56 | // might need to use Win32 externals such as GetCursorPos. 57 | [DllImport("user32.dll")] 58 | public static extern bool GetCursorPos(ref POINT point); 59 | } 60 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Adorners/SearchBoxFocusAdorner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Documents; 8 | using System.Windows.Media; 9 | 10 | namespace H.Framework.WPF.Control.Adorners 11 | { 12 | public class SearchBoxFocusAdorner : Adorner 13 | { 14 | public SearchBoxFocusAdorner(UIElement arg) 15 | : base(arg) 16 | { 17 | this.IsHitTestVisible = false; 18 | } 19 | 20 | protected override void OnRender(DrawingContext dc) 21 | { 22 | if (pen == null) 23 | { 24 | pen = new Pen(new SolidColorBrush(Color.FromRgb(218, 216, 215)), .6); 25 | pen.Freeze(); 26 | } 27 | 28 | dc.DrawRoundedRectangle(null, pen, new Rect(this.RenderSize), 12, 12); 29 | } 30 | 31 | private Pen pen; 32 | } 33 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/ControlHelpers/TextBoxHelper.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.WPF.Control.Controls; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace H.Framework.WPF.Control.ControlHelpers 10 | { 11 | public static class TextBoxHelper 12 | { 13 | public static readonly DependencyProperty IsOnFocusProperty = 14 | DependencyProperty.RegisterAttached("IsOnFocus", 15 | typeof(bool), 16 | typeof(TextBoxHelper), 17 | new FrameworkPropertyMetadata(OnIsOnFocusChanged)); 18 | 19 | public static bool GetIsOnFocus(DependencyObject d) 20 | { 21 | return (bool)d.GetValue(IsOnFocusProperty); 22 | } 23 | 24 | public static void SetIsOnFocus(DependencyObject d, bool value) 25 | { 26 | d.SetValue(IsOnFocusProperty, value); 27 | } 28 | 29 | private static void OnIsOnFocusChanged( 30 | DependencyObject d, 31 | DependencyPropertyChangedEventArgs e) 32 | { 33 | if (!(d is TextBoxEx box)) 34 | return; 35 | var b = (bool)e.NewValue; 36 | 37 | if (b) 38 | { 39 | box.Focus(); 40 | } 41 | } 42 | 43 | public static readonly DependencyProperty BoundPasswordProperty = 44 | DependencyProperty.RegisterAttached("BoundPassword", 45 | typeof(string), 46 | typeof(TextBoxHelper), 47 | new FrameworkPropertyMetadata(string.Empty, OnBoundPasswordChanged)); 48 | 49 | public static string GetBoundPassword(DependencyObject d) 50 | { 51 | if (d is WatermarkPasswordBox box) 52 | { 53 | box.PasswordChanged -= PasswordChanged; 54 | box.PasswordChanged += PasswordChanged; 55 | } 56 | 57 | return (string)d.GetValue(BoundPasswordProperty); 58 | } 59 | 60 | public static void SetBoundPassword(DependencyObject d, string value) 61 | { 62 | if (string.Equals(value, GetBoundPassword(d))) 63 | return; 64 | 65 | d.SetValue(BoundPasswordProperty, value); 66 | } 67 | 68 | private static void OnBoundPasswordChanged( 69 | DependencyObject d, 70 | DependencyPropertyChangedEventArgs e) 71 | { 72 | if (!(d is WatermarkPasswordBox box)) 73 | return; 74 | 75 | box.Password = GetBoundPassword(d); 76 | } 77 | 78 | private static void PasswordChanged(object sender, RoutedEventArgs e) 79 | { 80 | var password = sender as WatermarkPasswordBox; 81 | 82 | SetBoundPassword(password, password.Password); 83 | 84 | //password.GetType().GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(password, new object[] { password.Password.Length, 0 }); 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/BusyChrome.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.WPF.Control.Adorners; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | using System.Windows.Media; 10 | 11 | namespace H.Framework.WPF.Control.Controls 12 | { 13 | [TemplatePart(Name = "PART_Cancel", Type = typeof(Button))] 14 | public class BusyChrome : System.Windows.Controls.Control 15 | { 16 | public override void OnApplyTemplate() 17 | { 18 | base.OnApplyTemplate(); 19 | 20 | var cancelButton = GetTemplateChild("PART_Cancel") as Button; 21 | if (cancelButton != null) 22 | { 23 | cancelButton.Click += new RoutedEventHandler(cancelButton_Click); 24 | } 25 | } 26 | 27 | private void cancelButton_Click(object sender, RoutedEventArgs e) 28 | { 29 | var parent = VisualTreeHelper.GetParent(this) as BusyAdorner; 30 | parent.FireCancel(); 31 | } 32 | 33 | static BusyChrome() 34 | { 35 | DefaultStyleKeyProperty.OverrideMetadata(typeof(BusyChrome), new FrameworkPropertyMetadata(typeof(BusyChrome))); 36 | } 37 | 38 | public static void OnAllowCancelPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) 39 | { 40 | var self = d as BusyChrome; 41 | bool allow = (bool)e.NewValue; 42 | var cancelButton = self.GetTemplateChild("PART_Cancel") as Button; 43 | 44 | if (cancelButton != null) 45 | { 46 | if (allow) 47 | { 48 | cancelButton.Visibility = Visibility.Visible; 49 | } 50 | else 51 | { 52 | cancelButton.Visibility = Visibility.Collapsed; 53 | } 54 | } 55 | } 56 | 57 | public bool AllowCancel 58 | { 59 | get { return (bool)GetValue(AllowCancelProperty); } 60 | set { SetValue(AllowCancelProperty, value); } 61 | } 62 | 63 | public static readonly DependencyProperty AllowCancelProperty = 64 | DependencyProperty.Register("AllowCancel", typeof(bool), typeof(BusyChrome), new UIPropertyMetadata(true, OnAllowCancelPropertyChangedCallback)); 65 | } 66 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/BusyCircle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | using System.Windows.Media; 10 | using System.Windows.Shapes; 11 | 12 | namespace H.Framework.WPF.Control.Controls 13 | { 14 | [TemplatePart(Name = "PART_Panel", Type = typeof(Canvas))] 15 | public class BusyCircle : System.Windows.Controls.Control 16 | { 17 | private Canvas _partPanel; 18 | 19 | static BusyCircle() 20 | { 21 | DefaultStyleKeyProperty.OverrideMetadata(typeof(BusyCircle), new FrameworkPropertyMetadata(typeof(BusyCircle))); 22 | ClipToBoundsProperty.OverrideMetadata(typeof(BusyCircle), new FrameworkPropertyMetadata(false)); 23 | } 24 | 25 | public static readonly DependencyProperty BrushColorProperty = DependencyProperty.Register("BrushColor", typeof(Brush), typeof(BusyCircle), new PropertyMetadata(new SolidColorBrush(Colors.GreenYellow), null)); 26 | 27 | /// 28 | /// 整体颜色 29 | /// 30 | [Description("获取或设置整体颜色")] 31 | [Category("Defined Properties")] 32 | public Brush BrushColor 33 | { 34 | get => (Brush)GetValue(BrushColorProperty); 35 | set => SetValue(BrushColorProperty, value); 36 | } 37 | 38 | public static readonly DependencyProperty DiameterProperty = DependencyProperty.Register("Diameter", typeof(double), typeof(BusyCircle), new PropertyMetadata(20.0, null)); 39 | 40 | /// 41 | /// 直径大小 42 | /// 43 | [Description("获取或设置直径大小")] 44 | [Category("Defined Properties")] 45 | public double Diameter 46 | { 47 | get { return (double)GetValue(DiameterProperty); } 48 | set { SetValue(DiameterProperty, value); } 49 | } 50 | 51 | public BusyCircle() 52 | { 53 | IsVisibleChanged += BusyCircle_IsVisibleChanged; 54 | Loaded += BusyCircle_Loaded; 55 | Unloaded += BusyCircle_Unloaded; 56 | } 57 | 58 | private void BusyCircle_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) 59 | { 60 | if ((bool)e.NewValue) 61 | Start(); 62 | else 63 | Stop(); 64 | } 65 | 66 | public override void OnApplyTemplate() 67 | { 68 | base.OnApplyTemplate(); 69 | _partPanel = (Canvas)GetTemplateChild("PART_Panel"); 70 | } 71 | 72 | private void BusyCircle_Unloaded(object sender, RoutedEventArgs e) 73 | { 74 | Stop(); 75 | } 76 | 77 | private const double _offset = Math.PI; 78 | private const double _step = Math.PI * 2 / 10.0; 79 | 80 | private void BusyCircle_Loaded(object sender, RoutedEventArgs e) 81 | { 82 | for (double i = 0; i < 9; i++) 83 | { 84 | var ellipse = new Ellipse 85 | { 86 | Width = Diameter / 5, 87 | Height = Diameter / 5, 88 | Fill = BrushColor, 89 | Opacity = 1 - (i / 10) 90 | }; 91 | SetPosition(ellipse, _offset, i, _step); 92 | _partPanel?.Children.Add(ellipse); 93 | } 94 | } 95 | 96 | private void Start() 97 | { 98 | //Mouse.OverrideCursor = Cursors.Wait; 99 | } 100 | 101 | private void Stop() 102 | { 103 | //Mouse.OverrideCursor = Cursors.Arrow; 104 | } 105 | 106 | private void SetPosition(DependencyObject ellipse, double offset, 107 | double posOffSet, double step) 108 | { 109 | var value = Diameter * 5 / 12; 110 | ellipse.SetValue(Canvas.LeftProperty, value 111 | + Math.Sin(offset + posOffSet * step) * value); 112 | 113 | ellipse.SetValue(Canvas.TopProperty, value 114 | + Math.Cos(offset + posOffSet * step) * value); 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/BusyDecorator.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.WPF.Control.Adorners; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | using System.Windows.Documents; 10 | 11 | namespace H.Framework.WPF.Control.Controls 12 | { 13 | public class BusyDecorator : System.Windows.Controls.Control 14 | { 15 | public event EventHandler Cancel; 16 | 17 | public BusyDecorator() 18 | { 19 | this.Loaded += ControlBusyDecorator_Loaded; 20 | } 21 | 22 | private void ControlBusyDecorator_Loaded(object sender, RoutedEventArgs e) 23 | { 24 | var parent = this.Parent as Panel; 25 | } 26 | 27 | private void ShowAdorner() 28 | { 29 | if (this.adorner != null) 30 | { 31 | this.adorner.Visibility = Visibility.Visible; 32 | } 33 | else 34 | { 35 | var adornerLayer = AdornerLayer.GetAdornerLayer(this); 36 | 37 | if (adornerLayer != null) 38 | { 39 | var parent = this.Parent as Panel; 40 | this.adorner = new BusyAdorner(parent); 41 | this.adorner.Cancel += (s1, e1) => { if (Cancel != null) { Cancel(s1, e1); } }; 42 | adornerLayer.Add(this.adorner); 43 | } 44 | } 45 | } 46 | 47 | private void HideAdorner() 48 | { 49 | if (this.adorner != null) 50 | { 51 | this.adorner.Visibility = Visibility.Hidden; 52 | } 53 | } 54 | 55 | public bool IsBusy 56 | { 57 | get { return (bool)GetValue(IsBusyProperty); } 58 | set { SetValue(IsBusyProperty, value); } 59 | } 60 | 61 | public static void OnIsBusyPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) 62 | { 63 | var self = d as BusyDecorator; 64 | bool showDecorator = (bool)e.NewValue; 65 | 66 | if (showDecorator) 67 | { 68 | self.ShowAdorner(); 69 | } 70 | else 71 | { 72 | self.HideAdorner(); 73 | } 74 | } 75 | 76 | public static readonly DependencyProperty IsBusyProperty = 77 | DependencyProperty.Register("IsBusy", typeof(bool), typeof(BusyDecorator), new UIPropertyMetadata(false, OnIsBusyPropertyChangedCallback)); 78 | 79 | private BusyAdorner adorner; 80 | } 81 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/ButtonEx.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Controls.Primitives; 5 | 6 | namespace H.Framework.WPF.Control.Controls 7 | { 8 | public class ButtonEx : Button 9 | { 10 | static ButtonEx() 11 | { 12 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ButtonEx), new FrameworkPropertyMetadata(typeof(ButtonEx))); 13 | } 14 | 15 | public static readonly DependencyProperty CornerProperty = DependencyProperty.Register("Corner", typeof(CornerRadius), typeof(ButtonEx), new UIPropertyMetadata(new CornerRadius(0, 0, 0, 0), null)); 16 | 17 | /// 18 | /// 圆角 19 | /// 20 | [Description("获取或设置圆角")] 21 | [Category("Defined Properties")] 22 | public CornerRadius Corner 23 | { 24 | get => (CornerRadius)GetValue(CornerProperty); 25 | set => SetValue(CornerProperty, value); 26 | } 27 | 28 | public static readonly DependencyProperty ErrorMsgProperty = DependencyProperty.Register("ErrorMsg", typeof(string), typeof(ButtonEx), new UIPropertyMetadata(null, ErrorMsgPropertyChangedCallback)); 29 | 30 | /// 31 | /// 错误信息 32 | /// 33 | [Description("获取或设置错误信息")] 34 | [Category("Defined Properties")] 35 | public string ErrorMsg 36 | { 37 | get => (string)GetValue(ErrorMsgProperty); 38 | set => SetValue(ErrorMsgProperty, value); 39 | } 40 | 41 | public static void ErrorMsgPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) 42 | { 43 | var ctrl = (ButtonEx)d; 44 | ctrl._tip.IsShow = !string.IsNullOrWhiteSpace(e.NewValue.ToString()); 45 | } 46 | 47 | private TipBubble _tip; 48 | 49 | public override void OnApplyTemplate() 50 | { 51 | base.OnApplyTemplate(); 52 | _tip = GetTemplateChild("PART_ErrorTip") as TipBubble; 53 | if (_tip != null) 54 | { 55 | _tip.CustomPopupPlacementChanged -= CustomPopupPlacementChanged; 56 | _tip.CustomPopupPlacementChanged += CustomPopupPlacementChanged; 57 | } 58 | } 59 | 60 | private CustomPopupPlacement[] CustomPopupPlacementChanged(Size popupSize, Size targetSize, Point offset) 61 | { 62 | return new CustomPopupPlacement[] { new CustomPopupPlacement(new Point(5, offset.Y + 15), PopupPrimaryAxis.Vertical) }; 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/Capture/BitmapCursor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Drawing.Drawing2D; 4 | using System.Runtime.InteropServices; 5 | using System.Windows.Input; 6 | using System.Windows.Interop; 7 | 8 | namespace H.Framework.WPF.Control.Controls.Capture 9 | { 10 | internal class BitmapCursor : SafeHandle 11 | { 12 | public override bool IsInvalid => handle == (IntPtr)(-1); 13 | 14 | public static Cursor CreateBmpCursor(Bitmap cursorBitmap) 15 | { 16 | var c = new BitmapCursor(cursorBitmap); 17 | 18 | return CursorInteropHelper.Create(c); 19 | } 20 | 21 | protected BitmapCursor(Bitmap cursorBitmap) 22 | : base((IntPtr)(-1), true) 23 | { 24 | handle = cursorBitmap.GetHicon(); 25 | } 26 | 27 | protected override bool ReleaseHandle() 28 | { 29 | bool result = DestroyIcon(handle); 30 | 31 | handle = (IntPtr)(-1); 32 | 33 | return result; 34 | } 35 | 36 | [DllImport("user32.dll")] 37 | public static extern bool DestroyIcon(IntPtr hIcon); 38 | 39 | public static Cursor CreateCrossCursor() 40 | { 41 | const int w = 25; 42 | const int h = 25; 43 | 44 | var bmp = new Bitmap(w, h); 45 | 46 | Graphics g = Graphics.FromImage(bmp); 47 | g.SmoothingMode = SmoothingMode.Default; 48 | g.InterpolationMode = InterpolationMode.High; 49 | 50 | var pen = new Pen(Brushes.Black, 2); 51 | g.DrawLine(pen, new Point(12, 0), new Point(12, 8)); // vertical line 52 | g.DrawLine(pen, new Point(12, 17), new Point(12, 25)); // vertical line 53 | g.DrawLine(pen, new Point(0, 12), new Point(8, 12)); // horizontal line 54 | g.DrawLine(pen, new Point(16, 12), new Point(24, 12)); // horizontal line 55 | g.DrawLine(pen, new Point(12, 12), new Point(12, 13)); // Middle dot 56 | 57 | g.Flush(); 58 | g.Dispose(); 59 | pen.Dispose(); 60 | 61 | var c = CreateBmpCursor(bmp); 62 | 63 | bmp.Dispose(); 64 | 65 | return c; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/Capture/Config.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Media; 3 | 4 | namespace H.Framework.WPF.Control.Controls.Capture 5 | { 6 | internal static class Config 7 | { 8 | public static Brush SelectionBorderBrush = new SolidColorBrush(Color.FromArgb(255, 49, 106, 196)); 9 | public static Thickness SelectionBorderThickness = new Thickness(2.0); 10 | public static Brush MaskWindowBackground = new SolidColorBrush(Color.FromArgb(45, 255, 255, 255)); 11 | } 12 | 13 | internal enum ResizeThumbPlacement 14 | { 15 | None, 16 | LeftTop, 17 | TopCenter, 18 | RightTop, 19 | RightCenter, 20 | RightBottom, 21 | BottomCenter, 22 | LeftBottom, 23 | LeftCenter 24 | } 25 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/Capture/IndicatorObject.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | 4 | namespace H.Framework.WPF.Control.Controls.Capture 5 | { 6 | internal class IndicatorObject : ContentControl 7 | { 8 | private MaskCanvas canvasOwner; 9 | 10 | public IndicatorObject(MaskCanvas canvasOwner) 11 | { 12 | this.canvasOwner = canvasOwner; 13 | } 14 | 15 | static IndicatorObject() 16 | { 17 | var ownerType = typeof(IndicatorObject); 18 | 19 | FocusVisualStyleProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(null)); 20 | DefaultStyleKeyProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(ownerType)); 21 | MinWidthProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(5.0)); 22 | MinHeightProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(5.0)); 23 | } 24 | 25 | public void Resize(Rect region) 26 | { 27 | Canvas.SetLeft(this, region.X); 28 | Canvas.SetTop(this, region.Y); 29 | 30 | Width = region.Width; 31 | Height = region.Height; 32 | 33 | canvasOwner.UpdateSelectionRegion(region); 34 | } 35 | 36 | public void Move(Point offset) 37 | { 38 | var x = Canvas.GetLeft(this) + offset.X; 39 | var y = Canvas.GetTop(this) + offset.Y; 40 | Canvas.SetLeft(this, x); 41 | Canvas.SetTop(this, y); 42 | 43 | canvasOwner.UpdateSelectionRegion(new Rect(x, y, Width, Height)); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/Capture/MoveThumb.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.WPF.Control.Utilities.Capture; 2 | using System.Windows; 3 | using System.Windows.Controls.Primitives; 4 | 5 | namespace H.Framework.WPF.Control.Controls.Capture 6 | { 7 | internal class MoveThumb : ThumbBase 8 | { 9 | /// 10 | /// usually, the move thumb is beyond the left(right, top, bottom) side of target, 11 | /// however, some of targets can be moved by drag the center of it. 12 | /// 13 | public bool IsMoveByTargetCenter 14 | { 15 | get => (bool)GetValue(IsMoveByTargetCenterProperty); 16 | set => SetValue(IsMoveByTargetCenterProperty, value); 17 | } 18 | 19 | public static readonly DependencyProperty IsMoveByTargetCenterProperty = 20 | DependencyProperty.Register("IsMoveByTargetCenter", typeof(bool), typeof(MoveThumb), new UIPropertyMetadata(false)); 21 | 22 | protected override void OnDragStarted(object sender, DragStartedEventArgs e) 23 | { 24 | } 25 | 26 | protected override void OnDragDelta(object sender, DragDeltaEventArgs e) 27 | { 28 | if (Target != null) 29 | { 30 | var delta = new Point(e.HorizontalChange, e.VerticalChange); 31 | Target.Move(delta); 32 | } 33 | } 34 | 35 | protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e) 36 | { 37 | base.OnMouseLeftButtonDown(e); 38 | 39 | if (IsMoveByTargetCenter) 40 | { 41 | var canvas = this.GetAncestor(); 42 | if (canvas != null) 43 | { 44 | canvas.HandleIndicatorMouseDown(e); 45 | } 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/Capture/ScreenCapture.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.WPF.Control.Utilities.Capture; 2 | using System; 3 | using System.Threading; 4 | using System.Windows; 5 | using System.Windows.Media.Imaging; 6 | 7 | namespace H.Framework.WPF.Control.Controls.Capture 8 | { 9 | public class ScreenCapture 10 | { 11 | public void StartCapture(int timeOutSeconds) 12 | { 13 | Thread.Sleep(150); 14 | StartCapture(timeOutSeconds, null); 15 | } 16 | 17 | private MaskWindow _mask; 18 | 19 | public void StartCapture(int timeOutSeconds, Size? defaultSize) 20 | { 21 | if (_mask == null) 22 | { 23 | _mask = new MaskWindow(this, timeOutSeconds); 24 | _mask.Show(defaultSize); 25 | } 26 | else 27 | { 28 | _mask.GetScreenShoot(); 29 | _mask.Visibility = Visibility.Visible; 30 | } 31 | } 32 | 33 | public event EventHandler ScreenCaptured; 34 | 35 | public event EventHandler ScreenCaptureCancelled; 36 | 37 | internal void OnScreenCaptured(object sender, BitmapSource caputredBmp) 38 | { 39 | var filePath = Environment.GetEnvironmentVariable("TEMP") + @"\" + Guid.NewGuid().ToString("N") + ".png"; 40 | caputredBmp.SaveImageToFile(filePath); 41 | //Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { filePath }); 42 | var dataObject = new DataObject(); 43 | dataObject.SetData(DataFormats.FileDrop, new string[] { filePath }); 44 | Clipboard.SetDataObject(dataObject, true); 45 | //Clipboard.SetImage(e.Bmp);直接保存图片到剪贴板 46 | ScreenCaptured?.Invoke(sender, new ScreenCapturedEventArgs(caputredBmp)); 47 | } 48 | 49 | internal void OnScreenCaptureCancelled(object sender) 50 | { 51 | ScreenCaptureCancelled?.Invoke(sender, EventArgs.Empty); 52 | } 53 | } 54 | 55 | public class ScreenCapturedBitmapEventArgs : EventArgs 56 | { 57 | public System.Drawing.Bitmap BitMapArg 58 | { 59 | get; 60 | private set; 61 | } 62 | 63 | public ScreenCapturedBitmapEventArgs(System.Drawing.Bitmap bmp) 64 | { 65 | BitMapArg = bmp; 66 | } 67 | } 68 | 69 | public class ScreenCapturedEventArgs : EventArgs 70 | { 71 | public BitmapSource Bmp 72 | { 73 | get; 74 | private set; 75 | } 76 | 77 | public ScreenCapturedEventArgs(BitmapSource bmp) 78 | { 79 | Bmp = bmp; 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/Capture/ThumbBase.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.WPF.Control.Utilities.Capture; 2 | using System.Windows; 3 | using System.Windows.Controls.Primitives; 4 | 5 | namespace H.Framework.WPF.Control.Controls.Capture 6 | { 7 | internal class ThumbBase : Thumb 8 | { 9 | /// 10 | /// Get the target which this thumb is created for. 11 | /// 12 | public IndicatorObject Target 13 | { 14 | get; 15 | private set; 16 | } 17 | 18 | public ThumbBase() 19 | { 20 | FocusVisualStyle = null; 21 | DragStarted += OnDragStarted; 22 | DragDelta += OnDragDelta; 23 | DragCompleted += OnDragCompleted; 24 | } 25 | 26 | //usually, you should override this method to do some clear up work. 27 | //Add push current operation into undo-redo manager 28 | protected virtual void OnDragCompleted(object sender, DragCompletedEventArgs e) 29 | { 30 | } 31 | 32 | //usually, you should override this method to drag 33 | protected virtual void OnDragDelta(object sender, DragDeltaEventArgs e) 34 | { 35 | } 36 | 37 | //usually, you should override this method to do some prepare work for dragging 38 | protected virtual void OnDragStarted(object sender, DragStartedEventArgs e) 39 | { 40 | } 41 | 42 | protected override void OnVisualParentChanged(DependencyObject oldParent) 43 | { 44 | base.OnVisualParentChanged(oldParent); 45 | 46 | Target = this.GetAncestor(); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/Capture/ToolBarControl.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 16 | 30 | 44 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/Capture/ToolBarControl.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | 4 | namespace H.Framework.WPF.Control.Controls.Capture 5 | { 6 | /// 7 | /// ToolBarControl.xaml 的交互逻辑 8 | /// 9 | public partial class ToolBarControl : UserControl 10 | { 11 | //确定事件 12 | public delegate void OKEventHander(); 13 | 14 | public event OKEventHander OnOK; 15 | 16 | //取消事件 17 | public delegate void CancelEventHander(); 18 | 19 | public event CancelEventHander OnCancel; 20 | 21 | //保存事件 22 | public delegate void SaveCaptureEventHander(); 23 | 24 | public event SaveCaptureEventHander OnSaveCapture; 25 | 26 | public ToolBarControl() 27 | { 28 | InitializeComponent(); 29 | } 30 | 31 | private void buttonSave_Click(object sender, RoutedEventArgs e) 32 | { 33 | OnSaveCapture?.Invoke(); 34 | buttonComplete_Click(sender, e); 35 | } 36 | 37 | private void buttonCancel_Click(object sender, RoutedEventArgs e) 38 | { 39 | OnCancel?.Invoke(); 40 | } 41 | 42 | private void buttonComplete_Click(object sender, RoutedEventArgs e) 43 | { 44 | OnOK?.Invoke(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/ExpanderEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | 10 | namespace H.Framework.WPF.Control.Controls 11 | { 12 | public class ExpanderEx : Expander 13 | { 14 | static ExpanderEx() 15 | { 16 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ExpanderEx), new FrameworkPropertyMetadata(typeof(ExpanderEx))); 17 | ClipToBoundsProperty.OverrideMetadata(typeof(ExpanderEx), new FrameworkPropertyMetadata(false)); 18 | } 19 | 20 | //public static readonly DependencyProperty HeaderHeightProperty = DependencyProperty.Register("HeaderHeight", typeof(double), typeof(ExpanderEx), new PropertyMetadata(12.0, null)); 21 | 22 | ///// 23 | ///// Header高度 24 | ///// 25 | //[Description("获取或设置Header高度")] 26 | //[Category("Defined Properties")] 27 | //public double HeaderHeight 28 | //{ 29 | // get => (double)GetValue(HeaderHeightProperty); 30 | // set => SetValue(HeaderHeightProperty, value); 31 | //} 32 | 33 | public static readonly DependencyProperty ShowPathProperty = DependencyProperty.Register("ShowPath", typeof(bool), typeof(ExpanderEx), new PropertyMetadata(true, null)); 34 | 35 | /// 36 | /// ShowPath 37 | /// 38 | [Description("获取或设置ShowPath")] 39 | [Category("Defined Properties")] 40 | public bool ShowPath 41 | { 42 | get => (bool)GetValue(ShowPathProperty); 43 | set => SetValue(ShowPathProperty, value); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/ExtendedWindows/ExtendedWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Interop; 8 | using System.Windows.Shell; 9 | 10 | namespace H.Framework.WPF.Control.Controls.ExtendedWindows 11 | { 12 | public class ExtendedWindow : Window 13 | { 14 | /// 15 | /// 标识 FunctionBar 依赖属性。 16 | /// 17 | public static readonly DependencyProperty FunctionBarProperty = 18 | DependencyProperty.Register(nameof(FunctionBar), typeof(WindowFunctionBar), typeof(ExtendedWindow), new PropertyMetadata(default(WindowFunctionBar), OnFunctionBarChanged)); 19 | 20 | private static readonly DependencyPropertyKey IsNonClientActivePropertyKey = 21 | DependencyProperty.RegisterReadOnly("IsNonClientActive", typeof(bool), typeof(ExtendedWindow), new FrameworkPropertyMetadata(false)); 22 | 23 | #pragma warning disable SA1202 // Elements must be ordered by access 24 | public static readonly DependencyProperty IsNonClientActiveProperty = IsNonClientActivePropertyKey.DependencyProperty; 25 | #pragma warning restore SA1202 // Elements must be ordered by access 26 | 27 | private readonly IntPtr _trueValue = new IntPtr(1); 28 | 29 | static ExtendedWindow() 30 | { 31 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ExtendedWindow), new FrameworkPropertyMetadata(typeof(ExtendedWindow))); 32 | } 33 | 34 | /// 35 | /// 获取或设置FunctionBar的值 36 | /// 37 | public WindowFunctionBar FunctionBar 38 | { 39 | get => (WindowFunctionBar)GetValue(FunctionBarProperty); 40 | set => SetValue(FunctionBarProperty, value); 41 | } 42 | 43 | public bool IsNonClientActive 44 | { 45 | get 46 | { 47 | return (bool)GetValue(IsNonClientActiveProperty); 48 | } 49 | } 50 | 51 | protected override void OnSourceInitialized(EventArgs e) 52 | { 53 | base.OnSourceInitialized(e); 54 | if (SizeToContent == SizeToContent.WidthAndHeight && WindowChrome.GetWindowChrome(this) != null) 55 | { 56 | InvalidateMeasure(); 57 | } 58 | 59 | IntPtr handle = new WindowInteropHelper(this).Handle; 60 | HwndSource.FromHwnd(handle).AddHook(new HwndSourceHook(WndProc)); 61 | } 62 | 63 | /// 64 | /// FunctionBar 属性更改时调用此方法。 65 | /// 66 | /// FunctionBar 属性的旧值。 67 | /// FunctionBar 属性的新值。 68 | protected virtual void OnFunctionBarChanged(WindowFunctionBar oldValue, WindowFunctionBar newValue) 69 | { 70 | } 71 | 72 | protected override void OnActivated(EventArgs e) 73 | { 74 | base.OnActivated(e); 75 | SetValue(IsNonClientActivePropertyKey, true); 76 | } 77 | 78 | protected override void OnDeactivated(EventArgs e) 79 | { 80 | base.OnDeactivated(e); 81 | SetValue(IsNonClientActivePropertyKey, false); 82 | } 83 | 84 | private static void OnFunctionBarChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 85 | { 86 | var oldValue = (WindowFunctionBar)args.OldValue; 87 | var newValue = (WindowFunctionBar)args.NewValue; 88 | if (oldValue == newValue) 89 | { 90 | return; 91 | } 92 | 93 | var target = obj as ExtendedWindow; 94 | target?.OnFunctionBarChanged(oldValue, newValue); 95 | } 96 | 97 | private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) 98 | { 99 | if (msg == WindowNotifications.WM_NCACTIVATE) 100 | SetValue(IsNonClientActivePropertyKey, wParam == _trueValue); 101 | 102 | return IntPtr.Zero; 103 | } 104 | } 105 | 106 | /// 107 | /// Window Notifications 108 | /// 109 | public class WindowNotifications 110 | { 111 | /// 112 | /// Sent to a window when its nonclient area needs to be changed to indicate an active or inactive state. 113 | /// 114 | public const int WM_NCACTIVATE = 0x0086; 115 | } 116 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/ExtendedWindows/FunctionBar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | 10 | namespace H.Framework.WPF.Control.Controls.ExtendedWindows 11 | { 12 | public class FunctionBar : HeaderedItemsControl 13 | { 14 | public FunctionBar() 15 | { 16 | } 17 | 18 | public ObservableCollection Options { get; } = new ObservableCollection(); 19 | } 20 | 21 | public class WindowFunctionBar : FunctionBar 22 | { 23 | static WindowFunctionBar() 24 | { 25 | DefaultStyleKeyProperty.OverrideMetadata(typeof(WindowFunctionBar), new FrameworkPropertyMetadata(typeof(WindowFunctionBar))); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/ExtendedWindows/WindowService.WindowCommandHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Input; 8 | using System.Windows.Media; 9 | 10 | namespace H.Framework.WPF.Control.Controls.ExtendedWindows 11 | { 12 | public partial class WindowService 13 | { 14 | public class WindowCommandHelper 15 | { 16 | private readonly Window _window; 17 | 18 | public WindowCommandHelper(Window window) 19 | { 20 | _window = window; 21 | } 22 | 23 | public void ActiveCommands() 24 | { 25 | _window.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, CloseWindow)); 26 | _window.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, MaximizeWindow, CanResizeWindow)); 27 | _window.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, MinimizeWindow, CanMinimizeWindow)); 28 | _window.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, RestoreWindow, CanResizeWindow)); 29 | _window.CommandBindings.Add(new CommandBinding(SystemCommands.ShowSystemMenuCommand, ShowSystemMenu)); 30 | } 31 | 32 | private void CanResizeWindow(object sender, CanExecuteRoutedEventArgs e) 33 | { 34 | e.CanExecute = _window.ResizeMode == ResizeMode.CanResize || _window.ResizeMode == ResizeMode.CanResizeWithGrip; 35 | } 36 | 37 | private void CanMinimizeWindow(object sender, CanExecuteRoutedEventArgs e) 38 | { 39 | e.CanExecute = _window.ResizeMode != ResizeMode.NoResize; 40 | } 41 | 42 | private void CloseWindow(object sender, ExecutedRoutedEventArgs e) 43 | { 44 | _window.Close(); 45 | } 46 | 47 | private void MaximizeWindow(object sender, ExecutedRoutedEventArgs e) 48 | { 49 | SystemCommands.MaximizeWindow(_window); 50 | e.Handled = true; 51 | } 52 | 53 | private void MinimizeWindow(object sender, ExecutedRoutedEventArgs e) 54 | { 55 | SystemCommands.MinimizeWindow(_window); 56 | e.Handled = true; 57 | } 58 | 59 | private void RestoreWindow(object sender, ExecutedRoutedEventArgs e) 60 | { 61 | SystemCommands.RestoreWindow(_window); 62 | e.Handled = true; 63 | } 64 | 65 | private void ShowSystemMenu(object sender, ExecutedRoutedEventArgs e) 66 | { 67 | Point point = _window.PointToScreen(new Point(0, 0)); 68 | var dipScale = WindowParameters.GetDpi() / 96d; 69 | if (_window.WindowState == WindowState.Maximized) 70 | { 71 | // 因为不想在最大化时改变标题高度,所以这里的计算方式和标准计算方式不一样 72 | point.X += (SystemParameters.WindowNonClientFrameThickness.Left + WindowParameters.PaddedBorderThickness.Left) * dipScale; 73 | point.Y += (SystemParameters.WindowNonClientFrameThickness.Top + 74 | WindowParameters.PaddedBorderThickness.Top + 75 | SystemParameters.WindowResizeBorderThickness.Top - 76 | _window.BorderThickness.Top) 77 | * dipScale; 78 | } 79 | else 80 | { 81 | point.X += _window.BorderThickness.Left * dipScale; 82 | point.Y += SystemParameters.WindowNonClientFrameThickness.Top * dipScale; 83 | } 84 | 85 | var compositionTarget = PresentationSource.FromVisual(_window).CompositionTarget; 86 | SystemCommands.ShowSystemMenu(_window, compositionTarget.TransformFromDevice.Transform(point)); 87 | e.Handled = true; 88 | } 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/ImageButton.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Windows; 3 | using System.Windows.Controls.Primitives; 4 | using System.Windows.Media; 5 | 6 | namespace H.Framework.WPF.Control.Controls 7 | { 8 | public class ImageButton : ButtonBase 9 | { 10 | static ImageButton() 11 | { 12 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), new FrameworkPropertyMetadata(typeof(ImageButton))); 13 | ClipToBoundsProperty.OverrideMetadata(typeof(ImageButton), new FrameworkPropertyMetadata(false)); 14 | } 15 | 16 | public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ImageButton), new PropertyMetadata(null, OnImageSourceChangedCallback)); 17 | 18 | /// 19 | /// 背景图片路径 20 | /// 21 | [Description("获取或设置背景图片路径")] 22 | [Category("Defined Properties")] 23 | public ImageSource ImageSource 24 | { 25 | get => (ImageSource)GetValue(ImageSourceProperty); 26 | set => SetValue(ImageSourceProperty, value); 27 | } 28 | 29 | public static void OnImageSourceChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) 30 | { 31 | var c = d as ImageButton; 32 | if (e.NewValue != e.OldValue) 33 | { 34 | var value = (ImageSource)e.NewValue; 35 | if (c.CoverImageSource == null) 36 | c.CoverImageSource = value; 37 | if (c.PressImageSource == null) 38 | c.PressImageSource = value; 39 | } 40 | } 41 | 42 | public static readonly DependencyProperty CoverImageSourceProperty = DependencyProperty.Register("CoverImageSource", typeof(ImageSource), typeof(ImageButton), new PropertyMetadata(null, OnCoverImageSourceChangedCallback)); 43 | 44 | /// 45 | /// 鼠标over图片路径 46 | /// 47 | [Description("获取或设置鼠标over图片路径")] 48 | [Category("Defined Properties")] 49 | public ImageSource CoverImageSource 50 | { 51 | get => (ImageSource)GetValue(CoverImageSourceProperty); 52 | set => SetValue(CoverImageSourceProperty, value); 53 | } 54 | 55 | public static void OnCoverImageSourceChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) 56 | { 57 | //var c = d as ImageButton; 58 | //if (e.NewValue != null) 59 | //{ 60 | // var trigger = new Trigger(); 61 | // trigger.Property = IsMouseOverProperty; 62 | // trigger.Value = true; 63 | // trigger.Setters.Add(new Setter(ImageSourceProperty, e.NewValue, "PART_Image")); 64 | // c.Triggers.Add(trigger); 65 | //} 66 | //else 67 | // c.Triggers.Clear(); 68 | } 69 | 70 | public static readonly DependencyProperty PressImageSourceProperty = DependencyProperty.Register("PressImageSource", typeof(ImageSource), typeof(ImageButton), new PropertyMetadata(null, null)); 71 | 72 | /// 73 | /// 鼠标Press图片路径 74 | /// 75 | [Description("获取或设置鼠标Press图片路径")] 76 | [Category("Defined Properties")] 77 | public ImageSource PressImageSource 78 | { 79 | get => (ImageSource)GetValue(PressImageSourceProperty); 80 | set => SetValue(PressImageSourceProperty, value); 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/MarketLoading.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | 5 | namespace H.Framework.WPF.Control.Controls 6 | { 7 | public class MarketLoading : System.Windows.Controls.Control 8 | { 9 | static MarketLoading() 10 | { 11 | DefaultStyleKeyProperty.OverrideMetadata(typeof(MarketLoading), new FrameworkPropertyMetadata(typeof(MarketLoading))); 12 | ClipToBoundsProperty.OverrideMetadata(typeof(MarketLoading), new FrameworkPropertyMetadata(false)); 13 | BackgroundProperty.OverrideMetadata(typeof(MarketLoading), new FrameworkPropertyMetadata(new SolidColorBrush(Colors.Transparent))); 14 | } 15 | 16 | public static readonly DependencyProperty ShowUpProperty = DependencyProperty.Register("ShowUp", typeof(Visibility), typeof(MarketLoading), new PropertyMetadata(Visibility.Hidden, null)); 17 | 18 | /// 19 | /// 是否ShowUp 20 | /// 21 | [Description("获取或设置是否ShowUp")] 22 | [Category("Defined Properties")] 23 | public Visibility ShowUp 24 | { 25 | get => (Visibility)GetValue(ShowUpProperty); 26 | set => SetValue(ShowUpProperty, value); 27 | } 28 | 29 | public static readonly DependencyProperty AnimationColorProperty = DependencyProperty.Register("AnimationColor", typeof(Brush), typeof(MarketLoading), new PropertyMetadata(new SolidColorBrush(Colors.Blue), null)); 30 | 31 | /// 32 | /// AnimationColor 33 | /// 34 | [Description("获取或设置AnimationColor")] 35 | [Category("Defined Properties")] 36 | public Brush AnimationColor 37 | { 38 | get => (Brush)GetValue(AnimationColorProperty); 39 | set => SetValue(AnimationColorProperty, value); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/RadioButtonEx.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Media; 5 | 6 | namespace H.Framework.WPF.Control.Controls 7 | { 8 | public class RadioButtonEx : RadioButton 9 | { 10 | static RadioButtonEx() 11 | { 12 | DefaultStyleKeyProperty.OverrideMetadata(typeof(RadioButtonEx), new FrameworkPropertyMetadata(typeof(RadioButtonEx))); 13 | } 14 | 15 | public static readonly DependencyProperty CornerProperty = DependencyProperty.Register("Corner", typeof(CornerRadius), typeof(RadioButtonEx), new UIPropertyMetadata(new CornerRadius(0, 0, 0, 0), null)); 16 | 17 | /// 18 | /// 圆角 19 | /// 20 | [Description("获取或设置圆角")] 21 | [Category("Defined Properties")] 22 | public CornerRadius Corner 23 | { 24 | get => (CornerRadius)GetValue(CornerProperty); 25 | set => SetValue(CornerProperty, value); 26 | } 27 | 28 | public static readonly DependencyProperty CheckedColorProperty = DependencyProperty.Register("CheckedColor", typeof(Brush), typeof(RadioButtonEx), new UIPropertyMetadata(new SolidColorBrush(Colors.AliceBlue), null)); 29 | 30 | /// 31 | /// 选中色 32 | /// 33 | [Description("获取或设置选中色")] 34 | [Category("Defined Properties")] 35 | public Brush CheckedColor 36 | { 37 | get => (Brush)GetValue(CheckedColorProperty); 38 | set => SetValue(CheckedColorProperty, value); 39 | } 40 | 41 | public static readonly DependencyProperty IsChangedBackgroundProperty = DependencyProperty.Register("IsChangedBackground", typeof(bool), typeof(RadioButtonEx), new UIPropertyMetadata(false, IsChangedBackgroundPropertyChangedCallback)); 42 | 43 | /// 44 | /// 选中色 45 | /// 46 | [Description("获取或设置选中色")] 47 | [Category("Defined Properties")] 48 | public bool IsChangedBackground 49 | { 50 | get => (bool)GetValue(IsChangedBackgroundProperty); 51 | set => SetValue(IsChangedBackgroundProperty, value); 52 | } 53 | 54 | public static void IsChangedBackgroundPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) 55 | { 56 | //var btn = (RadioButtonEx)d; 57 | //if ((bool)e.NewValue) 58 | //{ 59 | // btn.Background = btn.CheckedColor; 60 | // btn.Foreground = new SolidColorBrush(Colors.White); 61 | //} 62 | //else 63 | //{ 64 | // btn.Background = btn.CheckedColor; 65 | // btn.Foreground = new SolidColorBrush(Colors.White); 66 | //} 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/RectangleLoading.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | 10 | namespace H.Framework.WPF.Control.Controls 11 | { 12 | [TemplatePart(Name = "MainGrid", Type = typeof(Grid))] 13 | public class RectangleLoading : System.Windows.Controls.Control 14 | { 15 | static RectangleLoading() 16 | { 17 | DefaultStyleKeyProperty.OverrideMetadata(typeof(RectangleLoading), new FrameworkPropertyMetadata(typeof(RectangleLoading))); 18 | ClipToBoundsProperty.OverrideMetadata(typeof(RectangleLoading), new FrameworkPropertyMetadata(true)); 19 | } 20 | 21 | public RectangleLoading() 22 | { 23 | } 24 | 25 | public static readonly DependencyProperty ShowUpProperty = DependencyProperty.Register("ShowUp", typeof(Visibility), typeof(RectangleLoading), new PropertyMetadata(Visibility.Hidden, new PropertyChangedCallback(OnShowUpPropertyChanged))); 26 | 27 | /// 28 | /// 是否ShowUp 29 | /// 30 | [Description("获取或设置是否ShowUp")] 31 | [Category("Defined Properties")] 32 | public Visibility ShowUp 33 | { 34 | get { return (Visibility)GetValue(ShowUpProperty); } 35 | set { SetValue(ShowUpProperty, value); } 36 | } 37 | 38 | private static void OnShowUpPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 39 | { 40 | RectangleLoading obj = (RectangleLoading)d; 41 | if ((Visibility)e.NewValue == Visibility.Visible) 42 | { 43 | //Storyboard sb = (Storyboard)obj.FindResource("leftAnimation"); 44 | //sb.Begin(); 45 | } 46 | else 47 | { 48 | } 49 | } 50 | 51 | public static readonly DependencyProperty LoadingTextProperty = DependencyProperty.Register("LoadingText", typeof(string), typeof(RectangleLoading), new PropertyMetadata("Loading...", null)); 52 | 53 | /// 54 | /// 显示的LoadingText 55 | /// 56 | [Description("获取或设置是否LoadingText")] 57 | [Category("Defined Properties")] 58 | public string LoadingText 59 | { 60 | get { return (string)GetValue(LoadingTextProperty); } 61 | set { SetValue(LoadingTextProperty, value); } 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/SwingLoading.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.ComponentModel; 8 | using System.Windows.Media.Animation; 9 | 10 | namespace H.Framework.WPF.Control.Controls 11 | { 12 | public class SwingLoading : System.Windows.Controls.Control 13 | { 14 | static SwingLoading() 15 | { 16 | DefaultStyleKeyProperty.OverrideMetadata(typeof(SwingLoading), new FrameworkPropertyMetadata(typeof(SwingLoading))); 17 | ClipToBoundsProperty.OverrideMetadata(typeof(SwingLoading), new FrameworkPropertyMetadata(false)); 18 | } 19 | 20 | public static readonly DependencyProperty ShowUpProperty = DependencyProperty.Register("ShowUp", typeof(Visibility), typeof(SwingLoading), new PropertyMetadata(Visibility.Hidden, null)); 21 | 22 | /// 23 | /// 是否ShowUp 24 | /// 25 | [Description("获取或设置是否ShowUp")] 26 | [Category("Defined Properties")] 27 | public Visibility ShowUp 28 | { 29 | get { return (Visibility)GetValue(ShowUpProperty); } 30 | set { SetValue(ShowUpProperty, value); } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Controls/UnreadTip.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Media; 6 | using System.Windows.Shapes; 7 | 8 | namespace H.Framework.WPF.Control.Controls 9 | { 10 | [TemplatePart(Name = "mPanel", Type = typeof(Grid))] 11 | [TemplatePart(Name = "PART_Ellipse", Type = typeof(Ellipse))] 12 | [TemplatePart(Name = "PART_TextBlock", Type = typeof(TextBlock))] 13 | [TemplatePart(Name = "PART_TextBlockLong", Type = typeof(TextBlock))] 14 | public class UnreadTip : System.Windows.Controls.Control 15 | { 16 | private TextBlock _longBlock, _block; 17 | 18 | static UnreadTip() 19 | { 20 | DefaultStyleKeyProperty.OverrideMetadata(typeof(UnreadTip), new FrameworkPropertyMetadata(typeof(UnreadTip))); 21 | ClipToBoundsProperty.OverrideMetadata(typeof(UnreadTip), new FrameworkPropertyMetadata(true)); 22 | VisibilityProperty.OverrideMetadata(typeof(UnreadTip), new FrameworkPropertyMetadata(Visibility.Collapsed)); 23 | HeightProperty.OverrideMetadata(typeof(UnreadTip), new FrameworkPropertyMetadata(10.00)); 24 | WidthProperty.OverrideMetadata(typeof(UnreadTip), new FrameworkPropertyMetadata(15.00)); 25 | FontSizeProperty.OverrideMetadata(typeof(UnreadTip), new FrameworkPropertyMetadata(8.00)); 26 | BackgroundProperty.OverrideMetadata(typeof(UnreadTip), new FrameworkPropertyMetadata(new SolidColorBrush(Colors.Red))); 27 | } 28 | 29 | public string Value 30 | { 31 | get => (string)GetValue(ValueProperty); 32 | set => SetValue(ValueProperty, value); 33 | } 34 | 35 | public static readonly DependencyProperty ValueProperty = 36 | DependencyProperty.Register("Value", typeof(string), typeof(UnreadTip), new PropertyMetadata("0", new PropertyChangedCallback(OnTextPropertyChanged))); 37 | 38 | private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 39 | { 40 | var obj = (UnreadTip)d; 41 | if (e.NewValue?.ToString() == "0") 42 | obj.Visibility = Visibility.Collapsed; 43 | else 44 | obj.Visibility = Visibility.Visible; 45 | if (obj._longBlock != null && obj._block != null) 46 | if (e.NewValue.ToString().Length > 2) 47 | { 48 | obj._longBlock.Visibility = Visibility.Visible; 49 | obj._longBlock.FontSize = obj.FontSize - 2; 50 | obj._block.Visibility = Visibility.Hidden; 51 | } 52 | else 53 | { 54 | obj._longBlock.Visibility = Visibility.Hidden; 55 | obj._block.Visibility = Visibility.Visible; 56 | } 57 | obj.OnTextChanged(e.OldValue, e.NewValue); 58 | } 59 | 60 | public bool IsShowText 61 | { 62 | get => (bool)GetValue(IsShowTextProperty); 63 | set => SetValue(IsShowTextProperty, value); 64 | } 65 | 66 | public static readonly DependencyProperty IsShowTextProperty = 67 | DependencyProperty.Register("IsShowText", typeof(bool), typeof(UnreadTip), new PropertyMetadata(true, null)); 68 | 69 | public static readonly RoutedEvent TextChangedEvent = EventManager.RegisterRoutedEvent("TextChangedChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler), typeof(UnreadTip)); 70 | 71 | [Description("Text更改后触发")] 72 | public event RoutedPropertyChangedEventHandler TextChanged 73 | { 74 | add 75 | { 76 | this.AddHandler(TextChangedEvent, value); 77 | } 78 | remove 79 | { 80 | this.RemoveHandler(TextChangedEvent, value); 81 | } 82 | } 83 | 84 | protected virtual void OnTextChanged(object oldValue, object newValue) 85 | { 86 | RoutedPropertyChangedEventArgs arg = 87 | new RoutedPropertyChangedEventArgs(oldValue, newValue, TextChangedEvent); 88 | this.RaiseEvent(arg); 89 | } 90 | 91 | public override void OnApplyTemplate() 92 | { 93 | base.OnApplyTemplate(); 94 | _longBlock = GetTemplateChild("PART_TextBlockLong") as TextBlock; 95 | _block = GetTemplateChild("PART_TextBlock") as TextBlock; 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/H.Framework.WPF.Control.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Project 5 | 6 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using System.Windows; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("H.Framework.WPF.Control")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("H.Framework.WPF.Control")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | //若要开始生成可本地化的应用程序,请设置 23 | //.csproj 文件中的 CultureYouAreCodingWith 24 | //例如,如果您在源文件中使用的是美国英语, 25 | //使用的是美国英语,请将 设置为 en-US。 然后取消 26 | //对以下 NeutralResourceLanguage 特性的注释。 更新 27 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 28 | 29 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 30 | 31 | [assembly: ThemeInfo( 32 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置 33 | //(未在页面中找到资源时使用, 34 | //或应用程序资源字典中找到时使用) 35 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 36 | //(未在页面中找到资源时使用, 37 | //、应用程序或任何主题专用资源字典中找到时使用) 38 | )] 39 | 40 | // 程序集的版本信息由下列四个值组成: 41 | // 42 | // 主版本 43 | // 次版本 44 | // 生成号 45 | // 修订号 46 | // 47 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 48 | // 方法是按如下所示使用“*”: : 49 | // [assembly: AssemblyVersion("1.0.*") 50 | 51 | [assembly: AssemblyVersion("1.0.7.2")] 52 | [assembly: AssemblyFileVersion("1.0.7.2")] -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace H.Framework.WPF.Control.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("H.Framework.WPF.Control.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace H.Framework.WPF.Control.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Resources/Icons/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.Control/Resources/Icons/close.png -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Resources/Icons/downFile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.Control/Resources/Icons/downFile.png -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Resources/Icons/ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.Control/Resources/Icons/ok.png -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Resources/Icons/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.Control/Resources/Icons/save.png -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Themes/BusyCircle.generic.xaml: -------------------------------------------------------------------------------- 1 |  5 | 50 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Themes/ButtonEx.generic.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 11 | 12 | 17 | 23 | 24 | 30 | 31 | 32 | 85 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Themes/CaptionsMarquee.generic.xaml: -------------------------------------------------------------------------------- 1 |  5 | 26 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Themes/ExpanderEx.generic.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 13 | 21 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 68 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Themes/Generic.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Themes/ImageButton.generic.xaml: -------------------------------------------------------------------------------- 1 |  5 | 38 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Themes/PieButton.generic.xaml: -------------------------------------------------------------------------------- 1 |  5 | 15 | 19 | 23 | 27 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Themes/RadioButtonEx.generic.xaml: -------------------------------------------------------------------------------- 1 |  5 | 42 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Themes/UnreadTip.generic.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 71 | -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Utilities/Enums.cs: -------------------------------------------------------------------------------- 1 | namespace H.Framework.WPF.Control.Utilities 2 | { 3 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/Utilities/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Media; 8 | using System.Windows.Media.Animation; 9 | 10 | namespace H.Framework.WPF.Control.Utilities 11 | { 12 | public static class Extensions 13 | { 14 | /// 15 | /// 弹簧式放大 16 | /// 17 | /// 18 | public static void ScaleEasingInAnimation(this FrameworkElement element, bool isActivated = true) 19 | { 20 | ScaleTransform scale = new ScaleTransform(); 21 | 22 | if (element.RenderTransform is TransformGroup) 23 | { 24 | TransformGroup group = element.RenderTransform as TransformGroup; 25 | var item = group.Children.SingleOrDefault(entity => entity is ScaleTransform); 26 | if (item != null) 27 | group.Children.Remove(item); 28 | RotateTransform itemRotate = group.Children.SingleOrDefault(entity => entity is RotateTransform) as RotateTransform; 29 | scale.CenterX = itemRotate.CenterX; 30 | scale.CenterY = itemRotate.CenterY; 31 | group.Children.Add(scale); 32 | } 33 | else 34 | { 35 | element.RenderTransform = scale; 36 | element.RenderTransformOrigin = new Point(0.5, 0.5); 37 | } 38 | if (!isActivated) 39 | { 40 | scale.ScaleX = 1.2; 41 | scale.ScaleY = 1.2; 42 | return; 43 | } 44 | EasingFunctionBase easing = new ElasticEase() 45 | { 46 | EasingMode = EasingMode.EaseOut, 47 | Oscillations = 10, 48 | Springiness = 15 49 | }; 50 | DoubleAnimation scaleAnimation = new DoubleAnimation() 51 | { 52 | //From = 1, 53 | To = 1.2, 54 | EasingFunction = easing, 55 | Duration = new TimeSpan(0, 0, 0, 1, 500), 56 | FillBehavior = FillBehavior.HoldEnd 57 | }; 58 | AnimationClock clock = scaleAnimation.CreateClock(); 59 | scale.ApplyAnimationClock(ScaleTransform.ScaleXProperty, clock, HandoffBehavior.Compose); 60 | scale.ApplyAnimationClock(ScaleTransform.ScaleYProperty, clock, HandoffBehavior.Compose); 61 | } 62 | 63 | /// 64 | /// 弹簧式缩小 65 | /// 66 | /// 67 | public static void ScaleEasingOutAnimation(this FrameworkElement element) 68 | { 69 | ScaleTransform scale = new ScaleTransform(); 70 | if (element.RenderTransform is TransformGroup) 71 | { 72 | TransformGroup group = element.RenderTransform as TransformGroup; 73 | var item = group.Children.SingleOrDefault(entity => entity is ScaleTransform); 74 | group.Children.Remove(item); 75 | RotateTransform itemRotate = group.Children.SingleOrDefault(entity => entity is RotateTransform) as RotateTransform; 76 | scale.CenterX = itemRotate.CenterX; 77 | scale.CenterY = itemRotate.CenterY; 78 | group.Children.Add(scale); 79 | } 80 | else 81 | { 82 | element.RenderTransform = scale; 83 | element.RenderTransformOrigin = new Point(0.5, 0.5); 84 | } 85 | DoubleAnimation scaleAnimation = new DoubleAnimation() 86 | { 87 | To = 1, 88 | Duration = new TimeSpan(0, 0, 0, 1, 0) 89 | }; 90 | AnimationClock clock = scaleAnimation.CreateClock(); 91 | scale.ApplyAnimationClock(ScaleTransform.ScaleXProperty, clock, HandoffBehavior.Compose); 92 | scale.ApplyAnimationClock(ScaleTransform.ScaleYProperty, clock, HandoffBehavior.Compose); 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Control/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Behaviors/ControlFocusBehaviorBase.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | using System.Windows.Interactivity; 4 | 5 | namespace H.Framework.WPF.Infrastructure.Behaviors 6 | { 7 | public class ControlFocusBehaviorBase : Behavior 8 | { 9 | public static readonly DependencyProperty IsFocusedProperty = DependencyProperty.RegisterAttached( 10 | "IsFocused", typeof(bool), typeof(ControlFocusBehaviorBase), 11 | new PropertyMetadata(IsFocusedPropertyChanged)); 12 | 13 | private static void IsFocusedPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) 14 | { 15 | if (!(dependencyObject is Control p)) return; 16 | if ((bool)e.NewValue) 17 | { 18 | p.Focus(); 19 | } 20 | } 21 | 22 | public static bool GetIsFocused(DependencyObject p) 23 | { 24 | return (bool)p.GetValue(IsFocusedProperty); 25 | } 26 | 27 | public static void SetIsFocused(DependencyObject p, bool value) 28 | { 29 | p.SetValue(IsFocusedProperty, value); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Converters/EmptyObjectToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Data; 9 | 10 | namespace H.Framework.WPF.Infrastructure.Converters 11 | { 12 | public class EmptyObjectToVisibilityConverter : DependencyObject, IValueConverter 13 | { 14 | /// 15 | /// 标识 EmptyValue 依赖属性。 16 | /// 17 | public static readonly DependencyProperty EmptyValueProperty = 18 | DependencyProperty.Register(nameof(EmptyValue), typeof(Visibility), typeof(EmptyObjectToVisibilityConverter), new PropertyMetadata(default(Visibility))); 19 | 20 | /// 21 | /// 标识 NotEmptyValue 依赖属性。 22 | /// 23 | public static readonly DependencyProperty NotEmptyValueProperty = 24 | DependencyProperty.Register(nameof(NotEmptyValue), typeof(Visibility), typeof(EmptyObjectToVisibilityConverter), new PropertyMetadata(default(Visibility))); 25 | 26 | public EmptyObjectToVisibilityConverter() 27 | { 28 | EmptyValue = Visibility.Collapsed; 29 | NotEmptyValue = Visibility.Visible; 30 | } 31 | 32 | /// 33 | /// 获取或设置EmptyValue的值 34 | /// 35 | public Visibility EmptyValue 36 | { 37 | get => (Visibility)GetValue(EmptyValueProperty); 38 | set => SetValue(EmptyValueProperty, value); 39 | } 40 | 41 | /// 42 | /// 获取或设置NotEmptyValue的值 43 | /// 44 | public Visibility NotEmptyValue 45 | { 46 | get => (Visibility)GetValue(NotEmptyValueProperty); 47 | set => SetValue(NotEmptyValueProperty, value); 48 | } 49 | 50 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 51 | { 52 | if (value == null) 53 | return EmptyValue; 54 | else 55 | return NotEmptyValue; 56 | } 57 | 58 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 59 | { 60 | throw new NotImplementedException(); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Converters/MultiObjectConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Data; 8 | 9 | namespace H.Framework.WPF.Infrastructure.Converters 10 | { 11 | public class MultiObjectConverter : IMultiValueConverter 12 | { 13 | /// 14 | /// 多值转换器 15 | /// 16 | /// 参数值数组 17 | /// 18 | /// 参数 19 | /// 各组比较值:比较条件(&或|):true返回值:false返回值:返回值类型枚举 20 | /// v1;v2-1|v2-2;v3:&:Visible:Collapsed:1 21 | /// 22 | /// 23 | public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) 24 | { 25 | string[] param = parameter.ToString().ToLower().Split(':'); //将参数字符串分段 26 | string[] compareValues = param[0].Split(';'); //将比较值段分割为数组 27 | if (values.Length != compareValues.Length) //比较源数据和比较参数个数是否一致 28 | return ConvertValue(param[3], param[4]); 29 | var trueCount = 0; //满足条件的结果数量 30 | string currentValue; 31 | IList currentParamArray; 32 | for (var i = 0; i < values.Length; i++) 33 | { 34 | currentValue = values[i] != null ? values[i].ToString().ToLower() : string.Empty; 35 | if (compareValues[i].Contains("|")) 36 | { 37 | //当前比较值段包含多个比较值 38 | currentParamArray = compareValues[i].Split('|'); 39 | trueCount += currentParamArray.Contains(currentValue) ? 1 : 0; //满足条件,结果+1 40 | } 41 | else 42 | { 43 | trueCount += compareValues[i].Equals(currentValue) ? 1 : 0; //满足条件,结果+1 44 | } 45 | } 46 | var compareResult = param[1].Equals("&") ? 47 | trueCount == values.Length : 48 | trueCount > 0; //判断比较结果 49 | return ConvertValue(compareResult ? param[2] : param[3], param[4]); 50 | } 51 | 52 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) 53 | { 54 | throw new NotImplementedException(); 55 | } 56 | 57 | private object ConvertValue(string result, string enumStr) 58 | { 59 | var convertResult = (ConvertResult)int.Parse(enumStr); 60 | if (convertResult == ConvertResult.Visibility) 61 | return result.Equals("collapsed") ? Visibility.Collapsed : Visibility.Visible; 62 | if (convertResult == ConvertResult.Boolean) 63 | return System.Convert.ToBoolean(result); 64 | return null; //后续自行扩展 65 | } 66 | 67 | private enum ConvertResult 68 | { 69 | Visibility = 1, 70 | Boolean = 2, 71 | String = 3, 72 | Int = 4, 73 | Double = 5, 74 | Brush = 6, 75 | Style = 7, 76 | Template = 8 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Converters/ObjectConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Data; 8 | 9 | namespace H.Framework.WPF.Infrastructure.Converters 10 | { 11 | public class ObjectConverter : IValueConverter 12 | { 13 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 14 | { 15 | string[] parray = parameter.ToString().ToLower().Split(':'); //将参数字符分段 parray[0]为比较值,parray[1]为true返回值,parray[2]为false返回值 16 | if (value == null) 17 | return parray[2]; //如果数据源为空,默认返回false返回值 18 | if (parray[0].Contains("|")) //判断有多个比较值的情况 19 | return parray[0].Split('|').Contains(value.ToString().ToLower()) ? parray[1] : parray[2]; //多值比较 20 | return parray[0].Equals(value.ToString().ToLower()) ? parray[1] : parray[2]; //单值比较 21 | } 22 | 23 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 24 | { 25 | var returnValue = "otherValue"; 26 | string[] parray = parameter.ToString().ToLower().Split(':'); 27 | if (value == null) 28 | return returnValue; 29 | var valueStr = value.ToString().ToLower(); 30 | if (valueStr != parray[1]) 31 | return returnValue; 32 | else 33 | return parray[0].Contains('|') ? parray[0].Split('|')[0] : parray[0]; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Converters/SimpleMathConverter.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.Core.Utilities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Data; 9 | 10 | namespace H.Framework.WPF.Infrastructure.Converters 11 | { 12 | public class SimpleMathConverter : IValueConverter 13 | { 14 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | return (value.ToString() + parameter.ToString()).Calc(); 17 | } 18 | 19 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 20 | { 21 | throw new NotImplementedException(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Mvvm/BasicEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Linq.Expressions; 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace H.Framework.WPF.Infrastructure.Mvvm 8 | { 9 | [ComVisible(false)] 10 | public abstract class BasicEntity : INotifyPropertyChanged, IDisposable 11 | { 12 | #region Constructor 13 | 14 | protected BasicEntity() 15 | { 16 | } 17 | 18 | #endregion Constructor 19 | 20 | #region DisplayName 21 | 22 | /// 23 | /// Returns the user-friendly name of this object. 24 | /// Child classes can set this property to a new value, 25 | /// or override it to determine the value on-demand. 26 | /// 27 | public virtual string DisplayName { get; protected set; } 28 | 29 | #endregion DisplayName 30 | 31 | #region NotifyPropertyChanged 32 | 33 | public event PropertyChangedEventHandler PropertyChanged; 34 | 35 | protected void NotifyPropertyChanged(string info) 36 | { 37 | if (PropertyChanged != null) 38 | { 39 | PropertyChanged(this, new PropertyChangedEventArgs(info)); 40 | } 41 | } 42 | 43 | protected void NotifyPropertyChanged(params string[] propertyNames) 44 | { 45 | if (propertyNames == null) throw new ArgumentNullException("propertyNames"); 46 | 47 | foreach (var name in propertyNames) 48 | { 49 | this.NotifyPropertyChanged(name); 50 | } 51 | } 52 | 53 | protected void NotifyPropertyChanged(Expression> propertyExpression) 54 | { 55 | var propertyName = ExtractPropertyName(propertyExpression); 56 | this.NotifyPropertyChanged(propertyName); 57 | } 58 | 59 | public static string ExtractPropertyName(Expression> propertyExpression) 60 | { 61 | if (propertyExpression == null) 62 | { 63 | throw new ArgumentNullException("propertyExpression"); 64 | } 65 | 66 | var memberExpression = propertyExpression.Body as MemberExpression; 67 | if (memberExpression == null) 68 | { 69 | throw new ArgumentException("The expression is not a member access expression.", "propertyExpression"); 70 | } 71 | 72 | var property = memberExpression.Member as PropertyInfo; 73 | if (property == null) 74 | { 75 | throw new ArgumentException("The member access expression does not access a property.", "propertyExpression"); 76 | } 77 | 78 | var getMethod = property.GetGetMethod(true); 79 | if (getMethod.IsStatic) 80 | { 81 | throw new ArgumentException("The referenced property is a static property.", "propertyExpression"); 82 | } 83 | 84 | return memberExpression.Member.Name; 85 | } 86 | 87 | #endregion NotifyPropertyChanged 88 | 89 | #region IDisposable Members 90 | 91 | /// 92 | /// Invoked when this object is being removed from the application 93 | /// and will be subject to garbage collection. 94 | /// 95 | public void Dispose() 96 | { 97 | this.OnDispose(); 98 | } 99 | 100 | /// 101 | /// Child classes can override this method to perform 102 | /// clean-up logic, such as removing event handlers. 103 | /// 104 | protected virtual void OnDispose() 105 | { 106 | } 107 | 108 | #endregion IDisposable Members 109 | } 110 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Mvvm/BasicViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Threading; 8 | 9 | namespace H.Framework.WPF.Infrastructure.Mvvm 10 | { 11 | public class BasicViewModel : BasicEntity 12 | { 13 | private string _WarnText; 14 | private bool _isShowWarn; 15 | private bool _isLoadingBusy; 16 | 17 | public string WarnText 18 | { 19 | get { return _WarnText; } 20 | set 21 | { 22 | _WarnText = value; 23 | NotifyPropertyChanged("WarnText"); 24 | ShowWarn(); 25 | } 26 | } 27 | 28 | public bool IsLoadingBusy 29 | { 30 | get { return _isLoadingBusy; } 31 | set 32 | { 33 | if (_isLoadingBusy != value) 34 | { 35 | _isLoadingBusy = value; 36 | NotifyPropertyChanged("IsLoadingBusy"); 37 | } 38 | } 39 | } 40 | 41 | public bool IsShowWarn 42 | { 43 | get { return _isShowWarn; } 44 | set 45 | { 46 | if (_isShowWarn != value) 47 | { 48 | _isShowWarn = value; 49 | NotifyPropertyChanged("IsShowWarn"); 50 | } 51 | } 52 | } 53 | 54 | private void ShowWarn() 55 | { 56 | IsShowWarn = true; 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Mvvm/Command/OperationCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Input; 7 | 8 | namespace H.Framework.WPF.Infrastructure.Mvvm.Command 9 | { 10 | public class OperationCommand : ICommand 11 | { 12 | public bool CanExecute(object parameter) 13 | { 14 | CanExecuteChanged?.Invoke(this, new ParameterEventArgs() { Parameter = parameter }); 15 | return true; 16 | } 17 | 18 | public event EventHandler CanExecuteChanged; 19 | 20 | public void Execute(object parameter) 21 | { 22 | Executing?.Invoke(this, new ParameterEventArgs() { Parameter = parameter }); 23 | } 24 | 25 | public event EventHandler Executing; 26 | } 27 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Mvvm/Command/ParameterEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace H.Framework.WPF.Infrastructure.Mvvm.Command 8 | { 9 | public class ParameterEventArgs : EventArgs 10 | { 11 | public object Parameter; 12 | } 13 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // 有关程序集的一般信息由以下 5 | // 控制。更改这些特性值可修改 6 | // 与程序集关联的信息。 7 | [assembly: AssemblyTitle("H.Framework.WPF.Infrastructure")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("H.Framework.WPF.Infrastructure")] 12 | [assembly: AssemblyCopyright("Copyright © 2018")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // 将 ComVisible 设置为 false 会使此程序集中的类型 17 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 18 | //请将此类型的 ComVisible 特性设置为 true。 19 | [assembly: ComVisible(false)] 20 | 21 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 22 | [assembly: Guid("aa9cc67b-d7a2-49ae-87df-be6edb72e5eb")] 23 | 24 | // 程序集的版本信息由下列四个值组成: 25 | // 26 | // 主版本 27 | // 次版本 28 | // 生成号 29 | // 修订号 30 | // 31 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 32 | //通过使用 "*",如下所示: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.1.6")] 35 | [assembly: AssemblyFileVersion("1.0.1.6")] -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Utilities/ImageExtender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Media.Imaging; 6 | 7 | namespace H.Framework.WPF.Infrastructure.Utilities 8 | { 9 | public class ImageExtender : DependencyObject 10 | { 11 | //public static readonly DependencyProperty ImageSourceURIProperty = DependencyProperty.RegisterAttached("ImageSourceURI", 12 | // typeof(string), typeof(ImageExtender), new UIPropertyMetadata(null 13 | // , ImageSourceURIChanged)); 14 | 15 | //public static string GetImageSourceURI(DependencyObject obj) 16 | //{ 17 | // return (string)obj.GetValue(ImageSourceURIProperty); 18 | //} 19 | 20 | //public static void SetImageSourceURI(DependencyObject obj, DependencyObject value) 21 | //{ 22 | // obj.SetValue(ImageSourceURIProperty, value); 23 | //} 24 | 25 | //public static void ImageSourceURIChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) 26 | //{ 27 | // var image = (Image)sender; 28 | 29 | // var myBitmapImage = new BitmapImage(); 30 | 31 | // myBitmapImage.BeginInit(); 32 | // myBitmapImage.UriSource = new Uri(e.NewValue.ToString(), UriKind.RelativeOrAbsolute); 33 | // myBitmapImage.CacheOption = BitmapCacheOption.OnLoad;//图像缓存到内存中,不会占用文件,没有被引用时会被自动回收。 34 | 35 | // myBitmapImage.EndInit(); 36 | // myBitmapImage.Freeze(); 37 | // image.Source = myBitmapImage; 38 | // image.Height = (myBitmapImage.Height / 3) < 10 ? 100 : myBitmapImage.Height / 3; 39 | // image.Width = (myBitmapImage.Width / 3) < 10 ? 100 : myBitmapImage.Width / 3; 40 | //} 41 | 42 | public static readonly DependencyProperty WeakSourceUriProperty = DependencyProperty.RegisterAttached("WeakSourceUri", 43 | typeof(string), typeof(ImageExtender), new UIPropertyMetadata(null 44 | , WeakSourceUriChanged)); 45 | 46 | public static string GetWeakSourceUri(DependencyObject obj) 47 | { 48 | return (string)obj.GetValue(WeakSourceUriProperty); 49 | } 50 | 51 | public static void SetWeakSourceUri(DependencyObject obj, DependencyObject value) 52 | { 53 | obj.SetValue(WeakSourceUriProperty, value); 54 | } 55 | 56 | public static void WeakSourceUriChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) 57 | { 58 | try 59 | { 60 | var image = (Image)sender; 61 | var myBitmapImage = new BitmapImage(); 62 | myBitmapImage.BeginInit(); 63 | var uri = e.NewValue?.ToString(); 64 | MemoryStream ms = null; 65 | var isFile = File.Exists(uri); 66 | if (isFile) 67 | { 68 | ms = new MemoryStream(File.ReadAllBytes(uri)); 69 | myBitmapImage.StreamSource = ms; 70 | } 71 | else 72 | myBitmapImage.UriSource = new Uri(uri, UriKind.RelativeOrAbsolute); 73 | //myBitmapImage.DecodePixelWidth = 550; 74 | //myBitmapImage.DecodePixelHeight = 550; 75 | myBitmapImage.CreateOptions = BitmapCreateOptions.IgnoreColorProfile; 76 | myBitmapImage.CacheOption = BitmapCacheOption.OnLoad;//图像缓存到内存中,不会占用文件,没有被引用时会被自动回收。 77 | myBitmapImage.EndInit(); 78 | if (isFile) 79 | { 80 | myBitmapImage.Freeze(); 81 | ms?.Close(); 82 | ms?.Dispose(); 83 | } 84 | image.Source = myBitmapImage; 85 | image.Height = (myBitmapImage.Height / 3) < 10 ? 100 : myBitmapImage.Height / 3; 86 | image.Width = (myBitmapImage.Width / 3) < 10 ? 100 : myBitmapImage.Width / 3; 87 | } 88 | catch 89 | { } 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Utilities/PasswordBoxHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | 5 | namespace H.Framework.WPF.Infrastructure.Utilities 6 | { 7 | public static class PasswordBoxHelper 8 | { 9 | public static readonly DependencyProperty BoundPasswordProperty = 10 | DependencyProperty.RegisterAttached("BoundPassword", 11 | typeof(string), 12 | typeof(PasswordBoxHelper), 13 | new FrameworkPropertyMetadata(string.Empty, OnBoundPasswordChanged)); 14 | 15 | public static string GetBoundPassword(DependencyObject d) 16 | { 17 | var box = d as PasswordBox; 18 | if (box != null) 19 | { 20 | box.PasswordChanged -= PasswordChanged; 21 | box.PasswordChanged += PasswordChanged; 22 | } 23 | 24 | return (string)d.GetValue(BoundPasswordProperty); 25 | } 26 | 27 | public static void SetBoundPassword(DependencyObject d, string value) 28 | { 29 | if (string.Equals(value, GetBoundPassword(d))) 30 | return; 31 | 32 | d.SetValue(BoundPasswordProperty, value); 33 | } 34 | 35 | private static void OnBoundPasswordChanged( 36 | DependencyObject d, 37 | DependencyPropertyChangedEventArgs e) 38 | { 39 | var box = d as PasswordBox; 40 | 41 | if (box == null) 42 | return; 43 | 44 | box.Password = GetBoundPassword(d); 45 | } 46 | 47 | private static void PasswordChanged(object sender, RoutedEventArgs e) 48 | { 49 | var password = sender as PasswordBox; 50 | 51 | SetBoundPassword(password, password.Password); 52 | 53 | password.GetType().GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(password, new object[] { password.Password.Length, 0 }); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Utilities/PopupHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls.Primitives; 8 | 9 | namespace H.Framework.WPF.Infrastructure.Utilities 10 | { 11 | public class PopupHelper 12 | { 13 | public static DependencyObject GetPopupPlacementTarget(DependencyObject obj) 14 | { 15 | return (DependencyObject)obj.GetValue(PopupPlacementTargetProperty); 16 | } 17 | 18 | public static void SetPopupPlacementTarget(DependencyObject obj, DependencyObject value) 19 | { 20 | obj.SetValue(PopupPlacementTargetProperty, value); 21 | } 22 | 23 | // Using a DependencyProperty as the backing store for PopupPlacementTarget. This enables animation, styling, binding, etc... 24 | public static readonly DependencyProperty PopupPlacementTargetProperty = 25 | DependencyProperty.RegisterAttached("PopupPlacementTarget", typeof(DependencyObject), typeof(PopupHelper), new PropertyMetadata(null, OnPopupPlacementTargetChanged)); 26 | 27 | private static void OnPopupPlacementTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 28 | { 29 | if (e.NewValue != null) 30 | { 31 | var pop = d as Popup; 32 | var w = Window.GetWindow(e.NewValue as DependencyObject); 33 | if (null != w) 34 | { 35 | w.LocationChanged += delegate 36 | { 37 | var offset = pop.HorizontalOffset; 38 | pop.HorizontalOffset = offset + 1; 39 | pop.HorizontalOffset = offset; 40 | }; 41 | } 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/Utilities/ScrollViewerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | 9 | namespace H.Framework.WPF.Infrastructure.Utilities 10 | { 11 | public class ScrollViewerExtensions 12 | { 13 | public static readonly DependencyProperty AlwaysScrollToEndProperty = DependencyProperty.RegisterAttached("AlwaysScrollToEnd", typeof(bool), typeof(ScrollViewerExtensions), new PropertyMetadata(false, AlwaysScrollToEndChanged)); 14 | private static bool _autoScroll; 15 | 16 | private static void AlwaysScrollToEndChanged(object sender, DependencyPropertyChangedEventArgs e) 17 | { 18 | var scroll = sender as ScrollViewer; 19 | if (scroll != null) 20 | { 21 | bool alwaysScrollToEnd = (e.NewValue != null) && (bool)e.NewValue; 22 | if (alwaysScrollToEnd) 23 | { 24 | scroll.ScrollToEnd(); 25 | scroll.ScrollChanged += ScrollChanged; 26 | // scroll.SizeChanged += Scroll_SizeChanged; 27 | } 28 | else { scroll.ScrollChanged -= ScrollChanged; /*scroll.ScrollChanged -= ScrollChanged; */} 29 | } 30 | else { throw new InvalidOperationException("The attached AlwaysScrollToEnd property can only be applied to ScrollViewer instances."); } 31 | } 32 | 33 | //private static void Scroll_SizeChanged(object sender, SizeChangedEventArgs e) 34 | //{ 35 | // ScrollViewer scroll = sender as ScrollViewer; 36 | // if (scroll == null) { throw new InvalidOperationException("The attached AlwaysScrollToEnd property can only be applied to ScrollViewer instances."); } 37 | // double d = scroll.ActualHeight + scroll.ViewportHeight + scroll.ExtentHeight; 38 | // scroll.ScrollToVerticalOffset(d); 39 | //} 40 | 41 | public static bool GetAlwaysScrollToEnd(ScrollViewer scroll) 42 | { 43 | if (scroll == null) { throw new ArgumentNullException("scroll"); } 44 | return (bool)scroll.GetValue(AlwaysScrollToEndProperty); 45 | } 46 | 47 | public static void SetAlwaysScrollToEnd(ScrollViewer scroll, bool alwaysScrollToEnd) 48 | { 49 | if (scroll == null) { throw new ArgumentNullException("scroll"); } 50 | scroll.SetValue(AlwaysScrollToEndProperty, alwaysScrollToEnd); 51 | } 52 | 53 | private static void ScrollChanged(object sender, ScrollChangedEventArgs e) 54 | { 55 | ScrollViewer scroll = sender as ScrollViewer; 56 | if (scroll == null) { throw new InvalidOperationException("The attached AlwaysScrollToEnd property can only be applied to ScrollViewer instances."); } 57 | 58 | if (e.ExtentHeightChange == 0) { _autoScroll = scroll.VerticalOffset == scroll.ScrollableHeight; } 59 | if (_autoScroll && e.ExtentHeightChange != 0) { scroll.ScrollToVerticalOffset(scroll.ExtentHeight); } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /H.Framework.WPF.Infrastructure/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /H.Framework.WPF.UI.Test/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /H.Framework.WPF.UI.Test/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace H.Framework.WPF.UI.Test 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /H.Framework.WPF.UI.Test/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] 11 | -------------------------------------------------------------------------------- /H.Framework.WPF.UI.Test/H.Framework.WPF.UI.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net5.0-windows 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /H.Framework.WPF.UI.Test/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/App.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 13 | 14 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.WPF.Infrastructure.Utilities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Configuration; 5 | using System.Data; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using System.Windows; 9 | 10 | namespace H.Framework.WPF.UITest 11 | { 12 | /// 13 | /// App.xaml 的交互逻辑 14 | /// 15 | public partial class App : Application, ISingleInstanceApp 16 | { 17 | public bool SignalExternalCommandLineArgs(IList args) 18 | { 19 | if (MainWindow.WindowState == WindowState.Minimized) 20 | { 21 | MainWindow.WindowState = WindowState.Normal; 22 | } 23 | 24 | MainWindow.Activate(); 25 | return true; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/EFCoreTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using static H.Framework.WPF.UITest.EFCoreTest; 9 | 10 | namespace H.Framework.WPF.UITest 11 | { 12 | public class EFCoreTest 13 | { 14 | public class User 15 | { 16 | public int ID { set; get; } 17 | 18 | public string Username { set; get; } 19 | 20 | public List Attachments { set; get; } 21 | } 22 | 23 | public class UserAttachment 24 | { 25 | public int ID { set; get; } 26 | public string AttachmentUrl { set; get; } 27 | public int UserID { set; get; } 28 | } 29 | } 30 | 31 | public class DBDiqiuContext : DbContext 32 | { 33 | public DbSet user { set; get; } 34 | 35 | public DbSet userattachment { set; get; } 36 | 37 | //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 38 | // => optionsBuilder.mysq.UseMySQL(@"Server=192.168.99.108;Database=diqiu_crm;User ID=root;Password=Dasong@;Port=3306;TreatTinyAsBoolean=false;SslMode=none;Allow User Variables=True;charset=utf8"); 39 | } 40 | 41 | public class UserDB 42 | { 43 | private readonly DBDiqiuContext _db; 44 | 45 | public UserDB() 46 | { 47 | _db = new DBDiqiuContext(); 48 | } 49 | 50 | public decimal? GetUsersTotal(int id) 51 | { 52 | if (_db.user.FirstOrDefault(x => x.ID == id) == null) 53 | return null; 54 | return _db.user.Count(); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // 有关程序集的一般信息由以下 8 | // 控制。更改这些特性值可修改 9 | // 与程序集关联的信息。 10 | [assembly: AssemblyTitle("H.Framework.WPF.UITest")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("H.Framework.WPF.UITest")] 15 | [assembly: AssemblyCopyright("Copyright © 2018")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // 将 ComVisible 设置为 false 会使此程序集中的类型 20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 21 | //请将此类型的 ComVisible 特性设置为 true。 22 | [assembly: ComVisible(false)] 23 | 24 | //若要开始生成可本地化的应用程序,请设置 25 | //.csproj 文件中的 CultureYouAreCodingWith 26 | //例如,如果您在源文件中使用的是美国英语, 27 | //使用的是美国英语,请将 设置为 en-US。 然后取消 28 | //对以下 NeutralResourceLanguage 特性的注释。 更新 29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置 36 | //(未在页面中找到资源时使用, 37 | //或应用程序资源字典中找到时使用) 38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 39 | //(未在页面中找到资源时使用, 40 | //、应用程序或任何主题专用资源字典中找到时使用) 41 | )] 42 | 43 | 44 | // 程序集的版本信息由下列四个值组成: 45 | // 46 | // 主版本 47 | // 次版本 48 | // 生成号 49 | // 修订号 50 | // 51 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 52 | // 方法是按如下所示使用“*”: : 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace H.Framework.WPF.UITest.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("H.Framework.WPF.UITest.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace H.Framework.WPF.UITest.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/RPC/ZeusCommonMsg.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.UITest/RPC/ZeusCommonMsg.cs -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/RPC/ZeusNotificationMsg.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.UITest/RPC/ZeusNotificationMsg.cs -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/RPC/ZeusUserMsg.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.UITest/RPC/ZeusUserMsg.cs -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/SingleApp.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.WPF.Infrastructure.Utilities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace H.Framework.WPF.UITest 9 | { 10 | internal class SingleApp 11 | { 12 | [STAThread] 13 | public static void Main() 14 | { 15 | if (SingleInstance.InitializeAsFirstInstance("888666555")) 16 | { 17 | var application = new App(); 18 | application.InitializeComponent(); 19 | application.Run(); 20 | 21 | // Allow single instance code to perform cleanup operations 22 | SingleInstance.Cleanup(); 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/SplashScreenBG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.UITest/SplashScreenBG.png -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/SplashScreenFG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.UITest/SplashScreenFG.png -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/TestWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using H.Framework.WPF.Control.Controls; 2 | 3 | namespace H.Framework.WPF.UITest 4 | { 5 | /// 6 | /// TestWindow.xaml 的交互逻辑 7 | /// 8 | public partial class TestWindow : WindowEx 9 | { 10 | public TestWindow() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/i_emoji.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.UITest/i_emoji.png -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /H.Framework.WPF.UITest/s_emoji.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjj28810/H.Framework/d4540e31fe8ca1f60df33bd752fe471209bc1787/H.Framework.WPF.UITest/s_emoji.png -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-leap-day --------------------------------------------------------------------------------