跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

提交记录
新增Core/App.config+27 −0看文件
@@ -0,0 +1,27 @@
1新增:<?xml version="1.0" encoding="utf-8"?>
2新增:<configuration>
3新增: <configSections>
4新增: <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
5新增: <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6新增: </configSections>
7新增: <entityFramework>
8新增: <providers>
9新增: <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
10新增: <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
11新增: </providers>
12新增: </entityFramework>
13新增: <system.data>
14新增: <DbProviderFactories>
15新增: <remove invariant="System.Data.SQLite.EF6" />
16新增: <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
17新增: </DbProviderFactories>
18新增: </system.data>
19新增: <runtime>
20新增: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
21新增: <dependentAssembly>
22新增: <assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" />
23新增: <bindingRedirect oldVersion="0.0.0.0-1.0.115.5" newVersion="1.0.115.5" />
24新增: </dependentAssembly>
25新增: </assemblyBinding>
26新增: </runtime>
27新增:</configuration>
文件末尾没有换行
修改Core/Core.csproj+101 −0看文件
@@ -1,6 +1,13 @@
11<?xml version="1.0" encoding="utf-8"?>
22<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3新增: <Import Project="..\packages\EntityFramework.6.3.0\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.props')" />
34 <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5新增: <PropertyGroup>
6新增: <ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
7新增: <CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
8新增: <CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
9新增: <CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
10新增: </PropertyGroup>
411 <PropertyGroup>
512 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
613 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -13,6 +20,8 @@
1320 <FileAlignment>512</FileAlignment>
1421 <Deterministic>true</Deterministic>
1522 <TargetFrameworkProfile />
23新增: <NuGetPackageImportStamp>
24新增: </NuGetPackageImportStamp>
1625 </PropertyGroup>
1726 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1827 <DebugSymbols>true</DebugSymbols>
@@ -31,24 +40,116 @@
3140 <ErrorReport>prompt</ErrorReport>
3241 <WarningLevel>4</WarningLevel>
3342 </PropertyGroup>
43新增: <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
44新增: <DebugSymbols>true</DebugSymbols>
45新增: <OutputPath>bin\x64\Debug\</OutputPath>
46新增: <DefineConstants>DEBUG;TRACE</DefineConstants>
47新增: <DebugType>full</DebugType>
48新增: <PlatformTarget>x64</PlatformTarget>
49新增: <LangVersion>7.3</LangVersion>
50新增: <ErrorReport>prompt</ErrorReport>
51新增: </PropertyGroup>
52新增: <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
53新增: <OutputPath>bin\x64\Release\</OutputPath>
54新增: <DefineConstants>TRACE</DefineConstants>
55新增: <Optimize>true</Optimize>
56新增: <DebugType>pdbonly</DebugType>
57新增: <PlatformTarget>x64</PlatformTarget>
58新增: <LangVersion>7.3</LangVersion>
59新增: <ErrorReport>prompt</ErrorReport>
60新增: </PropertyGroup>
3461 <ItemGroup>
62新增: <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
63新增: <HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.dll</HintPath>
64新增: </Reference>
65新增: <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
66新增: <HintPath>..\packages\EntityFramework.6.3.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
67新增: </Reference>
68新增: <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
69新增: <HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
70新增: </Reference>
71新增: <Reference Include="PresentationCore" />
72新增: <Reference Include="SQLitePCLRaw.core, Version=2.0.6.1341, Culture=neutral, PublicKeyToken=1488e028ca7ab535, processorArchitecture=MSIL">
73新增: <HintPath>..\packages\SQLitePCLRaw.core.2.0.6\lib\netstandard2.0\SQLitePCLRaw.core.dll</HintPath>
74新增: </Reference>
3575 <Reference Include="System" />
76新增: <Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
77新增: <HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
78新增: </Reference>
79新增: <Reference Include="System.ComponentModel.DataAnnotations" />
3680 <Reference Include="System.Core" />
81新增: <Reference Include="System.Data.SQLite, Version=1.0.115.5, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
82新增: <HintPath>..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.115.5\lib\net46\System.Data.SQLite.dll</HintPath>
83新增: </Reference>
84新增: <Reference Include="System.Data.SQLite.EF6, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
85新增: <HintPath>..\packages\System.Data.SQLite.EF6.1.0.113.0\lib\net46\System.Data.SQLite.EF6.dll</HintPath>
86新增: </Reference>
87新增: <Reference Include="System.Data.SQLite.Linq, Version=1.0.115.5, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
88新增: <HintPath>..\packages\System.Data.SQLite.Linq.1.0.115.5\lib\net46\System.Data.SQLite.Linq.dll</HintPath>
89新增: </Reference>
90新增: <Reference Include="System.Drawing" />
91新增: <Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
92新增: <HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
93新增: </Reference>
94新增: <Reference Include="System.Numerics" />
95新增: <Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
96新增: <HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
97新增: </Reference>
98新增: <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
99新增: <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
100新增: </Reference>
37101 <Reference Include="System.Xml.Linq" />
38102 <Reference Include="System.Data.DataSetExtensions" />
39103 <Reference Include="Microsoft.CSharp" />
40104 <Reference Include="System.Data" />
41105 <Reference Include="System.Net.Http" />
42106 <Reference Include="System.Xml" />
107新增: <Reference Include="WindowsBase" />
43108 </ItemGroup>
44109 <ItemGroup>
110新增: <Compile Include="Enums\SleepStatus.cs" />
111新增: <Compile Include="Event\EventHandler.cs" />
112新增: <Compile Include="Event\ObserverEventHandler.cs" />
113新增: <Compile Include="Librarys\Shortcut.cs" />
114新增: <Compile Include="Librarys\Iconer.cs" />
115新增: <Compile Include="Librarys\SQLite\SQLiteBuilder.cs" />
116新增: <Compile Include="Librarys\SQLite\SQLiteConfiguration.cs" />
117新增: <Compile Include="Librarys\SQLite\StatisticContext.cs" />
45118 <Compile Include="Librarys\Win32API.cs" />
119新增: <Compile Include="Models\Config\ConfigAttribute.cs" />
120新增: <Compile Include="Models\Config\ConfigModel.cs" />
121新增: <Compile Include="Models\Config\GeneralModel.cs" />
122新增: <Compile Include="Models\Config\Link\LinkModel.cs" />
123新增: <Compile Include="Models\DailyLogModel.cs" />
46124 <Compile Include="Properties\AssemblyInfo.cs" />
125新增: <Compile Include="Servicers\Instances\AppConfig.cs" />
126新增: <Compile Include="Servicers\Instances\Data.cs" />
127新增: <Compile Include="Librarys\Logger.cs" />
128新增: <Compile Include="Servicers\Instances\DateObserver.cs" />
47129 <Compile Include="Servicers\Instances\Main.cs" />
48130 <Compile Include="Servicers\Instances\Observer.cs" />
131新增: <Compile Include="Servicers\Instances\Sleepdiscover.cs" />
132新增: <Compile Include="Servicers\Interfaces\IAppConfig.cs" />
133新增: <Compile Include="Servicers\Interfaces\IData.cs" />
134新增: <Compile Include="Servicers\Interfaces\IDateObserver.cs" />
49135 <Compile Include="Servicers\Interfaces\IMain.cs" />
50136 <Compile Include="Servicers\Interfaces\IObserver.cs" />
137新增: <Compile Include="Servicers\Interfaces\ISleepdiscover.cs" />
138新增: </ItemGroup>
139新增: <ItemGroup>
140新增: <None Include="App.config" />
141新增: <None Include="packages.config" />
51142 </ItemGroup>
52143 <ItemGroup />
53144 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
145新增: <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
146新增: <PropertyGroup>
147新增: <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
148新增: </PropertyGroup>
149新增: <Error Condition="!Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.115.5\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.115.5\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets'))" />
150新增: <Error Condition="!Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.3.0\build\EntityFramework.props'))" />
151新增: <Error Condition="!Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.3.0\build\EntityFramework.targets'))" />
152新增: </Target>
153新增: <Import Project="..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.115.5\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets" Condition="Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.115.5\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" />
154新增: <Import Project="..\packages\EntityFramework.6.3.0\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.3.0\build\EntityFramework.targets')" />
54155</Project>
文件末尾没有换行
新增Core/Enums/SleepStatus.cs+23 −0看文件
@@ -0,0 +1,23 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace Core.Enums
8新增:{
9新增: /// <summary>
10新增: /// 休眠状态
11新增: /// </summary>
12新增: public enum SleepStatus
13新增: {
14新增: /// <summary>
15新增: /// 醒着
16新增: /// </summary>
17新增: Wake,
18新增: /// <summary>
19新增: /// 睡眠
20新增: /// </summary>
21新增: Sleep,
22新增: }
23新增:}
新增Core/Event/EventHandler.cs+14 −0看文件
@@ -0,0 +1,14 @@
1新增:using Core.Enums;
2新增:using Core.Models.Config;
3新增:using System;
4新增:using System.Collections.Generic;
5新增:using System.Linq;
6新增:using System.Text;
7新增:using System.Threading.Tasks;
8新增:
9新增:namespace Core.Event
10新增:{
11新增: public delegate void SleepdiscoverEventHandler(SleepStatus sleepStatus);
12新增:
13新增: public delegate void AppConfigEventHandler(ConfigModel oldConfig, ConfigModel newConfig);
14新增:}
新增Core/Event/ObserverEventHandler.cs+10 −0看文件
@@ -0,0 +1,10 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace Core.Event
8新增:{
9新增: public delegate void ObserverEventHandler(string processName, string description, string file);
10新增:}
新增Core/Librarys/Iconer.cs+148 −0看文件
@@ -0,0 +1,148 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Diagnostics;
4新增:using System.Drawing;
5新增:using System.IO;
6新增:using System.Linq;
7新增:using System.Text;
8新增:using System.Text.RegularExpressions;
9新增:using System.Threading.Tasks;
10新增:using System.Windows;
11新增:using System.Windows.Interop;
12新增:using System.Windows.Media;
13新增:using System.Windows.Media.Imaging;
14新增:using System.Xml;
15新增:using System.Xml.Serialization;
16新增:
17新增:namespace Core.Librarys
18新增:{
19新增: public class Iconer
20新增: {
21新增: public static string Get(string processname, string desc)
22新增: {
23新增: string iconName = (processname + desc).Replace(" ", "") + ".png";
24新增: string iconPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
25新增: "AppIcons", iconName);
26新增: if (!File.Exists(iconPath))
27新增: {
28新增: return "pack://application:,,,/Tai;component/Resources/Icons/defaultIcon.png";
29新增: }
30新增: return iconPath;
31新增: }
32新增: /// <summary>
33新增: /// 提取icon为Png格式并保存到程序目录下
34新增: /// </summary>
35新增: /// <param name="file"></param>
36新增: /// <param name="processname"></param>
37新增: /// <param name="desc"></param>
38新增: /// <returns>返回提取到程序目录下的路径</returns>
39新增: public static string ExtractFromFile(string file, string processname, string desc, bool isCheck = true)
40新增: {
41新增: try
42新增: {
43新增: string iconName = (processname + desc).Replace(" ", "") + ".png";
44新增: string iconPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
45新增: "AppIcons", iconName);
46新增: if (isCheck && File.Exists(iconPath))
47新增: {
48新增: return iconPath;
49新增: }
50新增: string dir = Path.GetDirectoryName(iconPath);
51新增: if (!Directory.Exists(dir))
52新增: {
53新增: Directory.CreateDirectory(dir);
54新增: }
55新增:
56新增: // uwp app icon handle
57新增:
58新增: if (file.IndexOf("WindowsApps") != -1)
59新增: {
60新增: // 只有在包含此关键字时才去处理
61新增:
62新增: // 继续判断是否是uwp程序
63新增: string appdir = file.Substring(0, file.Length - file.Split('\\').Last().Length);
64新增: string appxManifestPath = appdir + "AppxManifest.xml";
65新增: if (File.Exists(appxManifestPath))
66新增: {
67新增: // 是uwp程序
68新增: Debug.WriteLine("is uwp!" + appxManifestPath);
69新增: // 读取描述文件
70新增: string manifestText = File.ReadAllText(appxManifestPath);
71新增: var match = Regex.Match(manifestText, @"<Logo>(.*?)</Logo>");
72新增: string logoName = match.Groups[1].Value;
73新增:
74新增: string iconFile = string.Empty;
75新增:
76新增: string logo100 = logoName.Replace(".png", ".scale-100.png");
77新增: string logo125 = logoName.Replace(".png", ".scale-125.png");
78新增: string logo150 = logoName.Replace(".png", ".scale-150.png");
79新增: string logo200 = logoName.Replace(".png", ".scale-200.png");
80新增: string logo400 = logoName.Replace(".png", ".scale-400.png");
81新增:
82新增: if (File.Exists(appdir + logo100))
83新增: {
84新增: iconFile = appdir + logo100;
85新增: }
86新增: else if (File.Exists(appdir + logo125))
87新增: {
88新增: iconFile = appdir + logo125;
89新增: }
90新增: else if (File.Exists(appdir + logo150))
91新增: {
92新增: iconFile = appdir + logo150;
93新增: }
94新增: else if (File.Exists(appdir + logo200))
95新增: {
96新增: iconFile = appdir + logo200;
97新增: }
98新增: else if (File.Exists(appdir + logo400))
99新增: {
100新增: iconFile = appdir + logo400;
101新增: }
102新增: else
103新增: {
104新增: return string.Empty;
105新增: }
106新增:
107新增: if (!string.IsNullOrEmpty(iconFile) && File.Exists(iconFile))
108新增: {
109新增: // copy to tai dir
110新增:
111新增: File.Copy(iconFile, iconPath);
112新增: return iconPath;
113新增: }
114新增: return string.Empty;
115新增: }
116新增: }
117新增:
118新增:
119新增:
120新增: // exe app icon handle
121新增:
122新增: Icon ico = Icon.ExtractAssociatedIcon(file);
123新增:
124新增: using (var fileStream = new FileStream(iconPath, FileMode.Create))
125新增: {
126新增: BitmapEncoder encoder = new PngBitmapEncoder();
127新增: encoder.Frames.Add(BitmapFrame.Create(ToImageSource(ico) as BitmapSource));
128新增: encoder.Save(fileStream);
129新增: }
130新增: return iconPath;
131新增: }
132新增: catch (Exception ex)
133新增: {
134新增: Logger.Error(ex.Message + ",File: " + file + ",Process: " + processname);
135新增: return string.Empty;
136新增: }
137新增: }
138新增: public static ImageSource ToImageSource(Icon icon)
139新增: {
140新增: ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(
141新增: icon.Handle,
142新增: Int32Rect.Empty,
143新增: BitmapSizeOptions.FromEmptyOptions());
144新增:
145新增: return imageSource;
146新增: }
147新增: }
148新增:}
改名Core/Servicers/Instances/Logger.cs → Core/Librarys/Logger.cs+10 −13看文件
@@ -8,48 +8,45 @@ using System.Runtime.CompilerServices;
88using System.Text;
99using System.Threading.Tasks;
1010
11删除:namespace Core.Servicers.Instances
11新增:namespace Core.Librarys
1212{
13删除: public class Logger : ILogger
13新增: public class Logger
1414 {
1515 private static readonly object writeLock = new object();
16删除: private string loggerName;
16新增: private static string loggerName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
17新增: "Log", DateTime.Now.ToString("yyyy-MM-dd") + ".log");
1718 private enum LogLevel
1819 {
1920 Info,
2021 Warn,
2122 Error,
2223 }
23删除: public Logger()
24删除: {
25删除: loggerName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
26删除: "Log", DateTime.Now.ToString("yyyy-MM-dd") + ".log");
27删除: }
28删除: public void Info(string message, [CallerLineNumber] int callerLineNumber = -1, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerMemberName = null)
24新增:
25新增: public static void Info(string message, [CallerLineNumber] int callerLineNumber = -1, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerMemberName = null)
2926 {
3027 message = message + "\r\n[Caller Info] Line:" + callerLineNumber + ",File:" + callerFilePath + ",name:" + callerMemberName;
3128 Save(Fromat(LogLevel.Info, message));
3229 }
3330
34删除: public void Warn(string message, [CallerLineNumber] int callerLineNumber = -1, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerMemberName = null)
31新增: public static void Warn(string message, [CallerLineNumber] int callerLineNumber = -1, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerMemberName = null)
3532 {
3633 message = message + "\r\n[Caller Info] Line:" + callerLineNumber + ",File:" + callerFilePath + ",name:" + callerMemberName;
3734 Save(Fromat(LogLevel.Warn, message));
3835 }
39删除: public void Error(string message, [CallerLineNumber] int callerLineNumber = -1, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerMemberName = null)
36新增: public static void Error(string message, [CallerLineNumber] int callerLineNumber = -1, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerMemberName = null)
4037 {
4138 message = message + "\r\n[Caller Info] Line:" + callerLineNumber + ",File:" + callerFilePath + ",name:" + callerMemberName;
4239 Save(Fromat(LogLevel.Error, message));
4340 }
4441
45删除: private string Fromat(LogLevel logLevel, string message)
42新增: private static string Fromat(LogLevel logLevel, string message)
4643 {
4744 string logText = $"[{logLevel.ToString()}] [{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}] \r\n{message}\r\n------------------------\r\n\r\n";
4845 Debug.WriteLine(logText);
4946 return logText;
5047 }
5148
52删除: private void Save(string message)
49新增: private static void Save(string message)
5350 {
5451 lock (writeLock)
5552 {
新增Core/Librarys/SQLite/SQLiteBuilder.cs+339 −0看文件
@@ -0,0 +1,339 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Data.SQLite;
4新增:using System.IO;
5新增:using System.Linq;
6新增:using System.Reflection;
7新增:using System.Text;
8新增:using System.Threading.Tasks;
9新增:
10新增:namespace Core.Librarys.SQLite
11新增:{
12新增: /// <summary>
13新增: /// 数据模型信息接口
14新增: /// </summary>
15新增: public class IModelInfo
16新增: {
17新增: /// <summary>
18新增: /// 模型名
19新增: /// </summary>
20新增: public string Name { get; set; }
21新增: /// <summary>
22新增: /// 模型数据库表名
23新增: /// </summary>
24新增: public string TableName { get { return Name + "s"; } }
25新增: /// <summary>
26新增: /// 获取模型所有属性
27新增: /// </summary>
28新增: public List<IModelProperties> Properties { get; set; }
29新增: }
30新增: /// <summary>
31新增: /// 模型属性接口
32新增: /// </summary>
33新增: public class IModelProperties
34新增: {
35新增: /// <summary>
36新增: /// 列名
37新增: /// </summary>
38新增: public string Name { get; set; }
39新增: public string Type { get; set; }
40新增: public bool PK { get; set; }
41新增: public bool NotNull { get { return !PK; } }
42新增: }
43新增: /// <summary>
44新增: ///handle sqlite code first
45新增: /// </summary>
46新增: public class SQLiteBuilder
47新增: {
48新增: private System.Data.Entity.Infrastructure.DbModel model;
49新增: /// <summary>
50新增: /// 连接字符串
51新增: /// </summary>
52新增: private string connstr;
53新增: /// <summary>
54新增: /// 数据库版本文件
55新增: /// </summary>
56新增: private string versionFile;
57新增: /// <summary>
58新增: /// 数据模型
59新增: /// </summary>
60新增: private System.Data.Entity.Core.Metadata.Edm.EdmModel storeModel;
61新增: private System.Data.Entity.Core.Common.DbProviderManifest providerManifest;
62新增: public SQLiteBuilder(System.Data.Entity.Infrastructure.DbModel model)
63新增: {
64新增: this.model = model;
65新增:
66新增: if (model != null)
67新增: {
68新增: connstr = model.ProviderInfo.ProviderManifestToken;
69新增:
70新增: storeModel = model.StoreModel;
71新增:
72新增: providerManifest = model.ProviderManifest;
73新增:
74新增: versionFile = connstr.Split('=')[1] + ".version";
75新增: }
76新增: }
77新增:
78新增: public void Handle()
79新增: {
80新增: if (IsHandleDb())
81新增: {
82新增: HandleTable();
83新增: }
84新增: }
85新增:
86新增: /// <summary>
87新增: /// 处理表变化(仅处理新增表、新增表字段。不处理表名更改、列名更改、删除)
88新增: /// </summary>
89新增: private void HandleTable()
90新增: {
91新增: var modelInfos = GetModelInfos();
92新增:
93新增: var modelInfosDb = GetModelInfosForDb();
94新增:
95新增: foreach (var model in modelInfos)
96新增: {
97新增: //表名
98新增: string tableName = model.TableName;
99新增:
100新增: var modelInfoDb = modelInfosDb.Where(m => m.TableName == tableName);
101新增: //判断表是否存在
102新增: if (modelInfoDb.Count() <= 0)
103新增: {
104新增: //不存在则重新创建表
105新增: string csql = GetCreateTableSQL(model);
106新增: ExecuteNonQuery(csql);
107新增: }
108新增: else
109新增: {
110新增: //存在则扫描新字段(*暂时不处理字段的属性变化,只处理新增)
111新增:
112新增: //对应的数据库模型信息
113新增: var modelDb = modelInfoDb.Single();
114新增: //查找差异属性
115新增: foreach (var item in model.Properties)
116新增: {
117新增: if (modelDb.Properties.Where(m => m.Name == item.Name).Count() <= 0)
118新增: {
119新增: string csql = GetCreateColumnSQL(tableName, item);
120新增: ExecuteNonQuery(csql);
121新增: }
122新增: }
123新增:
124新增: }
125新增:
126新增: }
127新增: }
128新增:
129新增: #region 是否需要处理
130新增: private bool IsHandleDb()
131新增: {
132新增: string dir = Path.GetDirectoryName(versionFile);
133新增: if (!Directory.Exists(dir))
134新增: {
135新增: Directory.CreateDirectory(dir);
136新增: }
137新增:
138新增: bool f = File.Exists(versionFile);
139新增: string appVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
140新增: if (f)
141新增: {
142新增: //存在版本文件对比是否需要更新
143新增: string dbVersion = File.ReadAllText(versionFile);
144新增: if (dbVersion != appVersion)
145新增: {
146新增: //版本不一致需要更新
147新增: File.WriteAllText(versionFile, appVersion);
148新增: return true;
149新增: }
150新增: //不需要更新
151新增: return false;
152新增: }
153新增:
154新增: File.WriteAllText(versionFile, appVersion);
155新增: return true;
156新增: }
157新增:
158新增: #endregion
159新增:
160新增: #region 生成创建列SQL语句
161新增: /// <summary>
162新增: /// 生成创建列SQL语句
163新增: /// </summary>
164新增: /// <param name="tableName">表名</param>
165新增: /// <param name="properties">属性</param>
166新增: /// <returns></returns>
167新增: private string GetCreateColumnSQL(string tableName, IModelProperties properties)
168新增: {
169新增: string typeDefault = properties.NotNull ? properties.Type == "int" ? "NOT NULL DEFAULT 0" : "NOT NULL DEFAULT ''" : "";
170新增: return $"ALTER table {tableName} ADD COLUMN [{properties.Name}] {properties.Type} {typeDefault}";
171新增: }
172新增: #endregion
173新增:
174新增: #region 生成创建表SQL语句
175新增: /// <summary>
176新增: /// 生成创建表SQL语句
177新增: /// </summary>
178新增: /// <param name="model">模型信息</param>
179新增: /// <returns></returns>
180新增: private string GetCreateTableSQL(IModelInfo model)
181新增: {
182新增: string sql = $"CREATE TABLE \"{model.TableName}\" (";
183新增: foreach (var p in model.Properties)
184新增: {
185新增: string add = p.PK ? $"{p.Type} PRIMARY KEY" : p.Type + (p.NotNull ? " NOT NULL" : "");
186新增: string addChar = p == model.Properties[0] ? "" : ",";
187新增: sql += $"{addChar}[{p.Name}] {add}";
188新增: }
189新增: sql += ")";
190新增: return sql;
191新增: }
192新增: #endregion
193新增:
194新增: #region 判断表是否存在数据库中
195新增: /// <summary>
196新增: /// 判断表是否存在数据库中
197新增: /// </summary>
198新增: /// <param name="tableName"></param>
199新增: /// <returns></returns>
200新增: private bool IsTableExistDb(string tableName)
201新增: {
202新增: using (var con = new SQLiteConnection(@"Data Source=.\data.db"))
203新增: {
204新增: con.Open();
205新增: using (var cmd = new SQLiteCommand(con))
206新增: {
207新增: cmd.CommandText = "select count(*) from sqlite_master where type='table' and name = 'StatisticModels3'";
208新增: var rd = cmd.ExecuteReader();
209新增: if (rd.Read())
210新增: {
211新增: var count = rd.GetInt32(0);
212新增: return count > 0;
213新增: }
214新增: return false;
215新增: }
216新增:
217新增: }
218新增: }
219新增:
220新增: #endregion
221新增:
222新增: #region 获取所有数据模型的信息(从代码)
223新增: /// <summary>
224新增: /// 获取所有数据模型的信息(从代码)
225新增: /// </summary>
226新增: /// <returns></returns>
227新增: private List<IModelInfo> GetModelInfos()
228新增: {
229新增: var result = new List<IModelInfo>();
230新增:
231新增: foreach (var model in storeModel.EntityTypes)
232新增: {
233新增: var i = new IModelInfo();
234新增: var ps = new List<IModelProperties>();
235新增:
236新增: i.Name = model.Name;
237新增: i.Properties = ps;
238新增: //属性获取
239新增: foreach (var p in model.Properties)
240新增: {
241新增: ps.Add(new IModelProperties()
242新增: {
243新增: Name = p.Name,
244新增: PK = p.IsStoreGeneratedIdentity,
245新增: Type = p.TypeName == "int" && p.IsStoreGeneratedIdentity ? "INTEGER" : p.TypeName
246新增: });
247新增: }
248新增: result.Add(i);
249新增: }
250新增: return result;
251新增: }
252新增: #endregion
253新增:
254新增: #region 获取所有数据模型的信息(从数据库)
255新增: /// <summary>
256新增: /// 获取所有数据模型的信息(从数据库)
257新增: /// </summary>
258新增: /// <returns></returns>
259新增: private List<IModelInfo> GetModelInfosForDb()
260新增: {
261新增: var result = new List<IModelInfo>();
262新增:
263新增: using (var con = new SQLiteConnection(connstr))
264新增: {
265新增: con.Open();
266新增: using (var cmd = new SQLiteCommand(con))
267新增: {
268新增: cmd.CommandText = "select name from sqlite_master where type='table' order by name";
269新增: using (var rd = cmd.ExecuteReader())
270新增: {
271新增:
272新增:
273新增: while (rd.Read())
274新增: {
275新增: var modelInfo = new IModelInfo();
276新增: modelInfo.Name = rd["name"].ToString().Substring(0, rd["name"].ToString().Length - 1);
277新增: modelInfo.Properties = GetModelProperties(modelInfo.TableName);
278新增: result.Add(modelInfo);
279新增: }
280新增: }
281新增: }
282新增:
283新增: }
284新增:
285新增: return result;
286新增: }
287新增: #endregion
288新增:
289新增: #region 获取表的所有属性(从数据库)
290新增: private List<IModelProperties> GetModelProperties(string tableName)
291新增: {
292新增: var result = new List<IModelProperties>();
293新增:
294新增: using (var con = new SQLiteConnection(connstr))
295新增: {
296新增: con.Open();
297新增: using (var cmd = new SQLiteCommand(con))
298新增: {
299新增: cmd.CommandText = $"PRAGMA table_info([{tableName}])";
300新增: using (var rd = cmd.ExecuteReader())
301新增: {
302新增: while (rd.Read())
303新增: {
304新增: var mp = new IModelProperties();
305新增: mp.Name = rd["name"].ToString();
306新增: mp.Type = rd["type"].ToString();
307新增: mp.PK = rd["pk"].ToString() == "1";
308新增: result.Add(mp);
309新增: }
310新增: }
311新增: }
312新增: }
313新增: return result;
314新增: }
315新增: #endregion
316新增:
317新增:
318新增: //sqlite帮助
319新增: /// <summary>
320新增: /// 执行一条sql语句,返回影响行数
321新增: /// </summary>
322新增: /// <param name="sql"></param>
323新增: /// <returns></returns>
324新增: private int ExecuteNonQuery(string sql)
325新增: {
326新增: using (var con = new SQLiteConnection(connstr))
327新增: {
328新增: con.Open();
329新增: using (var cmd = new SQLiteCommand(con))
330新增: {
331新增: cmd.CommandText = sql;
332新增: return cmd.ExecuteNonQuery();
333新增: }
334新增:
335新增: }
336新增: }
337新增: }
338新增:
339新增:}
文件末尾没有换行
新增Core/Librarys/SQLite/SQLiteConfiguration.cs+22 −0看文件
@@ -0,0 +1,22 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Data.Entity;
4新增:using System.Data.Entity.Core.Common;
5新增:using System.Data.SQLite;
6新增:using System.Data.SQLite.EF6;
7新增:using System.Linq;
8新增:using System.Text;
9新增:using System.Threading.Tasks;
10新增:
11新增:namespace Core.Librarys.SQLite
12新增:{
13新增: public class SQLiteConfiguration : DbConfiguration
14新增: {
15新增: public SQLiteConfiguration()
16新增: {
17新增: SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance);
18新增: SetProviderFactory("System.Data.SQLite.EF6", SQLiteProviderFactory.Instance);
19新增: SetProviderServices("System.Data.SQLite", (DbProviderServices)SQLiteProviderFactory.Instance.GetService(typeof(DbProviderServices)));
20新增: }
21新增: }
22新增:}
新增Core/Librarys/SQLite/StatisticContext.cs+39 −0看文件
@@ -0,0 +1,39 @@
1新增:using Core.Models;
2新增:using System;
3新增:using System.Collections.Generic;
4新增:using System.Data.Entity;
5新增:using System.Data.SQLite;
6新增:using System.Linq;
7新增:using System.Text;
8新增:using System.Threading.Tasks;
9新增:
10新增:namespace Core.Librarys.SQLite
11新增:{
12新增: public class StatisticContext : DbContext
13新增: {
14新增: /// <summary>
15新增: /// 每日数据
16新增: /// </summary>
17新增: public DbSet<DailyLogModel> DailyLog { get; set; }
18新增:
19新增: // public StatisticContext(string n)
20新增: //: base("StatisticContext")
21新增: // {
22新增: // DbConfiguration.SetConfiguration(new SQLiteConfiguration());
23新增: // }
24新增: public StatisticContext()
25新增: : base(new SQLiteConnection()
26新增: {
27新增: ConnectionString = "Data Source=.\\Data\\data.db"
28新增: }, true)
29新增: {
30新增: DbConfiguration.SetConfiguration(new SQLiteConfiguration());
31新增: }
32新增:
33新增: protected override void OnModelCreating(DbModelBuilder modelBuilder)
34新增: {
35新增: var model = modelBuilder.Build(Database.Connection);
36新增: new SQLiteBuilder(model).Handle();
37新增: }
38新增: }
39新增:}
文件末尾没有换行
新增Core/Librarys/Shortcut.cs+76 −0看文件
@@ -0,0 +1,76 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.IO;
4新增:using System.Linq;
5新增:using System.Reflection;
6新增:using System.Text;
7新增:using System.Threading.Tasks;
8新增:
9新增:namespace Core.Librarys
10新增:{
11新增: public class Shortcut
12新增: {
13新增: /// <summary>
14新增: /// 为本程序创建一个快捷方式。
15新增: /// </summary>
16新增: /// <param name="lnkFilePath">快捷方式的完全限定路径。</param>
17新增: /// <param name="args">快捷方式启动程序时需要使用的参数。</param>
18新增: private static bool CreateShortcut(string lnkFilePath, string args)
19新增: {
20新增: try
21新增: {
22新增: var shellType = Type.GetTypeFromProgID("WScript.Shell");
23新增: dynamic shell = Activator.CreateInstance(shellType);
24新增: var shortcut = shell.CreateShortcut(lnkFilePath);
25新增: shortcut.TargetPath = Assembly.GetEntryAssembly().Location;
26新增: shortcut.Arguments = args;
27新增: shortcut.WorkingDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
28新增: shortcut.Save();
29新增: return true;
30新增: }
31新增: catch (Exception e)
32新增: {
33新增: Logger.Error(e.ToString());
34新增: return false;
35新增: }
36新增: }
37新增: /// <summary>
38新增: /// 设置开机启动
39新增: /// </summary>
40新增: /// <param name="startup"></param>
41新增: /// <returns></returns>
42新增: public static bool SetStartup(bool startup = true)
43新增: {
44新增: string path = Path.Combine(
45新增: Environment.GetFolderPath(Environment.SpecialFolder.Startup),
46新增: "Tai.lnk");
47新增: if (startup)
48新增: {
49新增: if (File.Exists(path))
50新增: {
51新增: return true;
52新增: }
53新增: return CreateShortcut(path, "");
54新增: }
55新增: else
56新增: {
57新增: if (File.Exists(path))
58新增: {
59新增: File.Delete(path);
60新增: }
61新增: return true;
62新增: }
63新增: }
64新增: /// <summary>
65新增: /// 创建桌面快捷方式
66新增: /// </summary>
67新增: /// <param name="create"></param>
68新增: /// <returns></returns>
69新增: public static bool CreateDesktopShortcut()
70新增: {
71新增: return CreateShortcut(Path.Combine(
72新增: Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
73新增: "Tai.lnk"), "");
74新增: }
75新增: }
76新增:}
修改Core/Librarys/Win32API.cs+169 −0看文件
@@ -4,6 +4,7 @@ using System.Linq;
44using System.Runtime.InteropServices;
55using System.Text;
66using System.Threading.Tasks;
7新增:using System.Windows;
78
89namespace Core.Librarys
910{
@@ -21,5 +22,173 @@ namespace Core.Librarys
2122
2223 [DllImport("user32.dll", CharSet = CharSet.Auto)]
2324 public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
25新增:
26新增: [DllImport("psapi.dll", SetLastError = true)]
27新增: public static extern int GetModuleFileNameExA(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, int nSize);
28新增:
29新增: [DllImport("kernel32.dll", SetLastError = true)]
30新增: public static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
31新增:
32新增: [DllImport("kernel32.dll", SetLastError = true)]
33新增: public static extern bool CloseHandle(UIntPtr hObject);
34新增:
35新增:
36新增:
37新增: internal struct WINDOWINFO
38新增: {
39新增: public uint ownerpid;
40新增: public uint childpid;
41新增: }
42新增:
43新增: [DllImport("user32.dll", SetLastError = true)]
44新增: public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
45新增:
46新增: [DllImport("user32", SetLastError = true)]
47新增: [return: MarshalAs(UnmanagedType.Bool)]
48新增: public static extern bool EnumChildWindows(IntPtr hWndParent, EnumWindowProc lpEnumFunc, IntPtr lParam);
49新增:
50新增:
51新增:
52新增: [DllImport("kernel32.dll", SetLastError = true)]
53新增: public static extern bool QueryFullProcessImageName([In] IntPtr hProcess, [In] int dwFlags, [Out] StringBuilder lpExeName, ref int lpdwSize);
54新增:
55新增:
56新增: public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);
57新增:
58新增: public const UInt32 PROCESS_QUERY_INFORMATION = 0x400;
59新增: public const UInt32 PROCESS_VM_READ = 0x010;
60新增:
61新增: private const uint WINEVENT_OUTOFCONTEXT = 0;
62新增: private const uint EVENT_SYSTEM_FOREGROUND = 3;
63新增: public static string UWP_AppName(IntPtr hWnd, uint pID)
64新增: {
65新增: WINDOWINFO windowinfo = new WINDOWINFO();
66新增: windowinfo.ownerpid = pID;
67新增: windowinfo.childpid = windowinfo.ownerpid;
68新增:
69新增: IntPtr pWindowinfo = Marshal.AllocHGlobal(Marshal.SizeOf(windowinfo));
70新增:
71新增: Marshal.StructureToPtr(windowinfo, pWindowinfo, false);
72新增:
73新增: EnumWindowProc lpEnumFunc = new EnumWindowProc(EnumChildWindowsCallback);
74新增: EnumChildWindows(hWnd, lpEnumFunc, pWindowinfo);
75新增:
76新增: windowinfo = (WINDOWINFO)Marshal.PtrToStructure(pWindowinfo, typeof(WINDOWINFO));
77新增:
78新增: IntPtr proc;
79新增: if ((proc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, (int)windowinfo.childpid)) == IntPtr.Zero) return null;
80新增:
81新增: int capacity = 2000;
82新增: StringBuilder sb = new StringBuilder(capacity);
83新增: QueryFullProcessImageName(proc, 0, sb, ref capacity);
84新增:
85新增: Marshal.FreeHGlobal(pWindowinfo);
86新增:
87新增: return sb.ToString(0, capacity);
88新增: }
89新增:
90新增: private static bool EnumChildWindowsCallback(IntPtr hWnd, IntPtr lParam)
91新增: {
92新增: WINDOWINFO info = (WINDOWINFO)Marshal.PtrToStructure(lParam, typeof(WINDOWINFO));
93新增:
94新增: uint pID;
95新增: GetWindowThreadProcessId(hWnd, out pID);
96新增:
97新增: if (pID != info.ownerpid) info.childpid = pID;
98新增:
99新增: Marshal.StructureToPtr(info, lParam, true);
100新增:
101新增: return true;
102新增: }
103新增:
104新增:
105新增: /// <summary>
106新增: /// 获取鼠标坐标
107新增: /// </summary>
108新增: /// <param name="lpPoint"></param>
109新增: /// <returns></returns>
110新增: [DllImport("user32.dll", SetLastError = true)]
111新增: [return: MarshalAs(UnmanagedType.Bool)]
112新增: public static extern bool GetCursorPos(out Point lpPoint);
113新增:
114新增:
115新增: #region 声音判断
116新增: /// <summary>
117新增: /// 指示系统当前是否在播放声音
118新增: /// </summary>
119新增: /// <returns></returns>
120新增: public static bool IsWindowsPlayingSound()
121新增: {
122新增: try
123新增: {
124新增: IMMDeviceEnumerator enumerator = (IMMDeviceEnumerator)(new MMDeviceEnumerator());
125新增: IMMDevice speakers = enumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
126新增: IAudioMeterInformation meter = (IAudioMeterInformation)speakers.Activate(typeof(IAudioMeterInformation).GUID, 0, IntPtr.Zero);
127新增: if (meter != null)
128新增: {
129新增:
130新增: float value = meter.GetPeakValue();
131新增:
132新增: // this is a bit tricky. 0 is the official "no sound" value
133新增: // but for example, if you open a video and plays/stops with it (w/o killing the app/window/stream),
134新增: // the value will not be zero, but something really small (around 1E-09)
135新增: // so, depending on your context, it is up to you to decide
136新增: // if you want to test for 0 or for a small value
137新增: return value > 1E-08;
138新增: }
139新增: else
140新增: {
141新增: return false;
142新增: }
143新增: }
144新增: catch (Exception ec)
145新增: {
146新增: Logger.Error(ec.Message);
147新增: return false;
148新增: }
149新增: }
150新增:
151新增: [ComImport, Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")]
152新增: private class MMDeviceEnumerator
153新增: {
154新增: }
155新增:
156新增: private enum EDataFlow
157新增: {
158新增: eRender,
159新增: eCapture,
160新增: eAll,
161新增: }
162新增:
163新增: private enum ERole
164新增: {
165新增: eConsole,
166新增: eMultimedia,
167新增: eCommunications,
168新增: }
169新增:
170新增: [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("A95664D2-9614-4F35-A746-DE8DB63617E6")]
171新增: private interface IMMDeviceEnumerator
172新增: {
173新增: void NotNeeded();
174新增: IMMDevice GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role);
175新增: // the rest is not defined/needed
176新增: }
177新增:
178新增: [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("D666063F-1587-4E43-81F1-B948E807363F")]
179新增: private interface IMMDevice
180新增: {
181新增: [return: MarshalAs(UnmanagedType.IUnknown)]
182新增: object Activate([MarshalAs(UnmanagedType.LPStruct)] Guid iid, int dwClsCtx, IntPtr pActivationParams);
183新增: // the rest is not defined/needed
184新增: }
185新增:
186新增: [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064")]
187新增: private interface IAudioMeterInformation
188新增: {
189新增: float GetPeakValue();
190新增: // the rest is not defined/needed
191新增: }
192新增: #endregion
24193 }
25194}
新增Core/Models/Config/ConfigAttribute.cs+34 −0看文件
@@ -0,0 +1,34 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace Core.Models.Config
8新增:{
9新增: [AttributeUsage(AttributeTargets.Class |
10新增: AttributeTargets.Constructor |
11新增: AttributeTargets.Field |
12新增: AttributeTargets.Method |
13新增: AttributeTargets.Property)]
14新增:
15新增: public class ConfigAttribute : System.Attribute
16新增: {
17新增: public string Name;
18新增: public string Description;
19新增: public string ToggleTrueText;
20新增: public string ToggleFalseText;
21新增: public string Group;
22新增: public int Index;
23新增: public bool IsName;
24新增: public ConfigAttribute()
25新增: {
26新增: ToggleTrueText = "开";
27新增: ToggleFalseText = "关";
28新增: Index = 0;
29新增: IsName = false;
30新增: }
31新增:
32新增:
33新增: }
34新增:}
新增Core/Models/Config/ConfigModel.cs+25 −0看文件
@@ -0,0 +1,25 @@
1新增:using Core.Models.Config.Link;
2新增:using System;
3新增:using System.Collections.Generic;
4新增:using System.Linq;
5新增:using System.Text;
6新增:using System.Threading.Tasks;
7新增:
8新增:namespace Core.Models.Config
9新增:{
10新增: /// <summary>
11新增: /// 应用设置
12新增: /// </summary>
13新增: public class ConfigModel
14新增: {
15新增: /// <summary>
16新增: /// 关联进程
17新增: /// </summary>
18新增: public List<LinkModel> Links { get; set; }
19新增:
20新增: /// <summary>
21新增: /// 常规
22新增: /// </summary>
23新增: public GeneralModel General { get; set; }
24新增: }
25新增:}
新增Core/Models/Config/GeneralModel.cs+20 −0看文件
@@ -0,0 +1,20 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace Core.Models.Config
8新增:{
9新增: /// <summary>
10新增: /// 常规
11新增: /// </summary>
12新增: public class GeneralModel
13新增: {
14新增: [Config(Name = "开机自启动", Description = "在电脑启动时自动运行 Tai", Group = "基础")]
15新增: /// <summary>
16新增: /// 是否启用开机自启动
17新增: /// </summary>
18新增: public bool IsStartatboot { get; set; }
19新增: }
20新增:}
新增Core/Models/Config/Link/LinkModel.cs+22 −0看文件
@@ -0,0 +1,22 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace Core.Models.Config.Link
8新增:{
9新增: public class LinkModel
10新增: {
11新增: /// <summary>
12新增: /// 关联名称
13新增: /// </summary>
14新增: [Config(Name = "关联名称", Description = "设置一个名称用于识别该关联的目的", IsName = true)]
15新增: public string Name { get; set; } = "新的关联";
16新增: /// <summary>
17新增: /// 关联进程列表
18新增: /// </summary>
19新增: [Config(Name = "关联进程", Description = "将需要关联的进程名称(不带.exe)添加到此")]
20新增: public List<string> ProcessList { get; set; } = new List<string>();
21新增: }
22新增:}
新增Core/Models/DailyLogModel.cs+36 −0看文件
@@ -0,0 +1,36 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace Core.Models
8新增:{
9新增: /// <summary>
10新增: /// 每日使用数据
11新增: /// </summary>
12新增: public class DailyLogModel
13新增: {
14新增: public int ID { get; set; }
15新增: /// <summary>
16新增: /// 统计日期
17新增: /// </summary>
18新增: public DateTime Date { get; set; }
19新增: /// <summary>
20新增: /// 使用时长(单位:秒)
21新增: /// </summary>
22新增: public int Time { get; set; } = 0;
23新增: /// <summary>
24新增: /// 进程名称
25新增: /// </summary>
26新增: public string ProcessName { get; set; }
27新增: /// <summary>
28新增: /// 进程描述
29新增: /// </summary>
30新增: public string ProcessDescription { get; set; }
31新增: /// <summary>
32新增: /// 进程文件
33新增: /// </summary>
34新增: public string File { get; set; }
35新增: }
36新增:}
新增Core/Servicers/Instances/AppConfig.cs+115 −0看文件
@@ -0,0 +1,115 @@
1新增:using Core.Event;
2新增:using Core.Librarys;
3新增:using Core.Models.Config;
4新增:using Core.Servicers.Interfaces;
5新增:using Newtonsoft.Json;
6新增:using System;
7新增:using System.Collections.Generic;
8新增:using System.IO;
9新增:using System.Linq;
10新增:using System.Text;
11新增:using System.Threading.Tasks;
12新增:
13新增:namespace Core.Servicers.Instances
14新增:{
15新增: public class AppConfig : IAppConfig
16新增: {
17新增: private string fileName;
18新增: private ConfigModel config;
19新增:
20新增: public event AppConfigEventHandler ConfigChanged;
21新增: private ConfigModel oldConfig;
22新增:
23新增: public AppConfig()
24新增: {
25新增: fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
26新增: "Data",
27新增: "AppConfig.json");
28新增: }
29新增: public void Load()
30新增: {
31新增: string configText = string.Empty;
32新增: try
33新增: {
34新增: if (File.Exists(fileName))
35新增: {
36新增: configText = File.ReadAllText(fileName);
37新增: config = JsonConvert.DeserializeObject<ConfigModel>(configText);
38新增: }
39新增: else
40新增: {
41新增: // 创建基础配置
42新增: CreateDefaultConfig();
43新增:
44新增: Save();
45新增: }
46新增:
47新增: CopyToOldConfig();
48新增: }
49新增: catch (JsonSerializationException ex)
50新增: {
51新增: HandleLoadFail(ex.Message, configText);
52新增: }
53新增: catch (JsonReaderException ex)
54新增: {
55新增: HandleLoadFail(ex.Message, configText);
56新增: }
57新增: catch (Exception ex)
58新增: {
59新增: Logger.Error(ex.Message);
60新增: }
61新增: }
62新增:
63新增: private void CopyToOldConfig()
64新增: {
65新增: string configStr = JsonConvert.SerializeObject(config);
66新增: oldConfig = JsonConvert.DeserializeObject<ConfigModel>(configStr);
67新增: }
68新增:
69新增: private void HandleLoadFail(string err, string configText)
70新增: {
71新增: // 创建基础配置
72新增: CreateDefaultConfig();
73新增:
74新增: Save();
75新增:
76新增: Logger.Error(err + "\r\nConfig content: " + configText);
77新增: }
78新增: private void CreateDefaultConfig()
79新增: {
80新增: config = new ConfigModel();
81新增: config.Links = new List<Models.Config.Link.LinkModel>();
82新增:
83新增: config.General = new GeneralModel();
84新增: config.General.IsStartatboot = false;
85新增: }
86新增:
87新增: public ConfigModel GetConfig()
88新增: {
89新增: return config;
90新增: }
91新增:
92新增:
93新增: public void Save()
94新增: {
95新增: try
96新增: {
97新增: string dir = Path.GetDirectoryName(fileName);
98新增: if (!Directory.Exists(dir))
99新增: {
100新增: Directory.CreateDirectory(dir);
101新增: }
102新增:
103新增: File.WriteAllText(fileName, JsonConvert.SerializeObject(config));
104新增:
105新增: ConfigChanged?.Invoke(oldConfig, config);
106新增:
107新增: CopyToOldConfig();
108新增: }
109新增: catch (Exception ex)
110新增: {
111新增: Logger.Error(ex.Message);
112新增: }
113新增: }
114新增: }
115新增:}
新增Core/Servicers/Instances/Data.cs+164 −0看文件
@@ -0,0 +1,164 @@
1新增:using Core.Librarys.SQLite;
2新增:using Core.Models;
3新增:using Core.Servicers.Interfaces;
4新增:using System;
5新增:using System.Collections.Generic;
6新增:using System.Linq;
7新增:using System.Text;
8新增:using System.Threading.Tasks;
9新增:
10新增:namespace Core.Servicers.Instances
11新增:{
12新增: public class Data : IData
13新增: {
14新增:
15新增: public void Set(string processName, string processDescription, string file, int seconds)
16新增: {
17新增: if (string.IsNullOrEmpty(processName) || string.IsNullOrEmpty(file) || seconds <= 0)
18新增: {
19新增: return;
20新增: }
21新增: processDescription = processDescription == null ? string.Empty : processDescription;
22新增: using (var db = new StatisticContext())
23新增: {
24新增: var today = DateTime.Now.Date;
25新增: var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.ProcessName == processName && m.ProcessDescription == processDescription && m.File == file);
26新增: if (res == null)
27新增: {
28新增: //数据库中没有时则创建
29新增: db.DailyLog.Add(new Models.DailyLogModel()
30新增: {
31新增: Date = today,
32新增: File = file,
33新增: ProcessDescription = processDescription,
34新增: ProcessName = processName,
35新增: Time = seconds,
36新增: });
37新增: }
38新增: else
39新增: {
40新增: res.Time += seconds;
41新增: }
42新增: db.SaveChanges();
43新增: }
44新增: }
45新增:
46新增: public List<DailyLogModel> GetTodaylogList()
47新增: {
48新增: using (var db = new StatisticContext())
49新增: {
50新增: var today = DateTime.Now.Date;
51新增: var res = db.DailyLog.Where(m => m.Date == today);
52新增: return res.ToList();
53新增: }
54新增: }
55新增:
56新增: public List<DailyLogModel> GetDateRangelogList(DateTime start, DateTime end)
57新增: {
58新增:
59新增: using (var db = new StatisticContext())
60新增: {
61新增: var today = DateTime.Now.Date;
62新增: var res = db.DailyLog.SqlQuery("Select Sum(Time) as Time,ProcessName,File,ID,Date,ProcessDescription from DailyLogModels WHERE Date between '" + start.ToString("yyyy-MM-dd HH:mm:ss") + "' AND '" + end.ToString("yyyy-MM-dd HH:mm:ss") + "' GROUP BY ProcessName,File ").ToList();
63新增: return res.ToList();
64新增: }
65新增: }
66新增:
67新增: public List<DailyLogModel> GetThisWeeklogList()
68新增: {
69新增: DateTime weekStartDate = DateTime.Now, weekEndDate = DateTime.Now;
70新增: if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
71新增: {
72新增: weekStartDate = DateTime.Now.Date;
73新增: weekEndDate = DateTime.Now.Date.AddDays(6);
74新增: }
75新增: else
76新增: {
77新增: int weekNum = (int)DateTime.Now.DayOfWeek;
78新增: if (weekNum == 0)
79新增: {
80新增: weekNum = 7;
81新增: }
82新增: weekNum -= 1;
83新增: weekStartDate = DateTime.Now.Date.AddDays(-weekNum);
84新增: weekEndDate = weekStartDate.Date.AddDays(6);
85新增: }
86新增:
87新增: return GetDateRangelogList(weekStartDate, weekEndDate);
88新增: }
89新增:
90新增: public List<DailyLogModel> GetLastWeeklogList()
91新增: {
92新增: DateTime weekStartDate = DateTime.Now, weekEndDate = DateTime.Now;
93新增:
94新增: int weekNum = (int)DateTime.Now.DayOfWeek;
95新增: if (weekNum == 0)
96新增: {
97新增: weekNum = 7;
98新增: }
99新增:
100新增:
101新增: weekStartDate = DateTime.Now.Date.AddDays(-6 - weekNum);
102新增: weekEndDate = weekStartDate.AddDays(6);
103新增:
104新增: return GetDateRangelogList(weekStartDate, weekEndDate);
105新增: }
106新增:
107新增: public void Set(string processName, int seconds)
108新增: {
109新增: if (string.IsNullOrEmpty(processName) || seconds <= 0)
110新增: {
111新增: return;
112新增: }
113新增: using (var db = new StatisticContext())
114新增: {
115新增: var today = DateTime.Now.Date;
116新增: var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.ProcessName == processName);
117新增: if (res != null)
118新增: {
119新增: res.Time += seconds;
120新增: db.SaveChanges();
121新增: }
122新增:
123新增: }
124新增: }
125新增:
126新增: public List<DailyLogModel> GetProcessMonthLogList(string file, DateTime month)
127新增: {
128新增: using (var db = new StatisticContext())
129新增: {
130新增:
131新增: var res = db.DailyLog.Where(
132新增: m =>
133新增: m.Date.Year == month.Year
134新增: && m.Date.Month == month.Month
135新增: //&& m.ProcessName == processName
136新增: //&& m.ProcessDescription == processDescription
137新增: && m.File == file
138新增: );
139新增: if (res != null)
140新增: {
141新增: return res.ToList();
142新增: }
143新增: return new List<DailyLogModel>();
144新增: }
145新增: }
146新增:
147新增: public DailyLogModel GetLast(string file)
148新增: {
149新增: using (var db = new StatisticContext())
150新增: {
151新增:
152新增: var res = db.DailyLog.Where(
153新增: m =>
154新增: m.File == file
155新增: ).OrderByDescending(m => m.ID).Take(1);
156新增: if (res != null)
157新增: {
158新增: return res.FirstOrDefault();
159新增: }
160新增: return null;
161新增: }
162新增: }
163新增: }
164新增:}
新增Core/Servicers/Instances/DateObserver.cs+57 −0看文件
@@ -0,0 +1,57 @@
1新增:using Core.Servicers.Interfaces;
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.Threading;
8新增:
9新增:namespace Core.Servicers.Instances
10新增:{
11新增: public class DateObserver : IDateObserver
12新增: {
13新增: public event EventHandler OnDateChanging;
14新增:
15新增:
16新增:
17新增: private DispatcherTimer timer;
18新增:
19新增: public DateObserver()
20新增: {
21新增: }
22新增:
23新增:
24新增: public void Start()
25新增: {
26新增: SetTimer();
27新增: }
28新增:
29新增: private void SetTimer()
30新增: {
31新增: timer = new DispatcherTimer();
32新增: timer.Tick += Timer_Tick;
33新增: DateTime now = DateTime.Now;
34新增: DateTime tmorrow = new DateTime(now.Year, now.Month, now.Day, 23, 59, 30);
35新增: int diffseconds = (int)tmorrow.Subtract(now).TotalSeconds;
36新增: if (diffseconds < 0)
37新增: {
38新增: diffseconds = 0;
39新增: }
40新增: timer.Interval = new TimeSpan(0, 0, diffseconds);
41新增: timer.Start();
42新增: }
43新增:
44新增: private async void Timer_Tick(object sender, EventArgs e)
45新增: {
46新增: timer.Stop();
47新增:
48新增: OnDateChanging?.Invoke(this, EventArgs.Empty);
49新增:
50新增: await Task.Run(async () =>
51新增: {
52新增: await Task.Delay(60000);
53新增: SetTimer();
54新增: });
55新增: }
56新增: }
57新增:}
修改Core/Servicers/Instances/Main.cs+209 −2看文件
@@ -1,6 +1,13 @@
1删除:using Core.Servicers.Interfaces;
1新增:using Core.Enums;
2新增:using Core.Librarys;
3新增:using Core.Librarys.SQLite;
4新增:using Core.Models.Config;
5新增:using Core.Models.Config.Link;
6新增:using Core.Servicers.Interfaces;
27using System;
38using System.Collections.Generic;
9新增:using System.Data.Entity;
10新增:using System.Diagnostics;
411using System.Linq;
512using System.Text;
613using System.Threading.Tasks;
@@ -10,18 +17,218 @@ namespace Core.Servicers.Instances
1017 public class Main : IMain
1118 {
1219 private readonly IObserver observer;
13删除: public Main(IObserver observer)
20新增: private readonly IData data;
21新增: private readonly ISleepdiscover sleepdiscover;
22新增: private readonly IAppConfig appConfig;
23新增: private readonly IDateObserver dateObserver;
24新增: // 忽略的进程
25新增: private readonly string[] IgnoreProcess = new string[] {
26新增: "Tai",
27新增: "SearchHost",
28新增: "Taskmgr",
29新增: "ApplicationFrameHost",
30新增: "StartMenuExperienceHost",
31新增: "ShellExperienceHost",
32新增: "OpenWith"
33新增: };
34新增:
35新增: /// <summary>
36新增: /// 当前聚焦进程
37新增: /// </summary>
38新增: private string activeProcess, activeProcessDescription, activeProcessFile = null;
39新增:
40新增: //private DateTime activeStartTime = DateTime.Now;
41新增:
42新增: /// <summary>
43新增: /// 活动计时器
44新增: /// </summary>
45新增: private Stopwatch activeWatcher;
46新增: /// <summary>
47新增: /// 睡眠状态
48新增: /// </summary>
49新增: private SleepStatus sleepStatus;
50新增:
51新增: /// <summary>
52新增: /// app config
53新增: /// </summary>
54新增: private ConfigModel config;
55新增:
56新增: public event EventHandler OnUpdateTime;
57新增:
58新增: public Main(
59新增: IObserver observer,
60新增: IData data,
61新增: ISleepdiscover sleepdiscover,
62新增: IAppConfig appConfig, IDateObserver dateObserver)
1463 {
1564 this.observer = observer;
65新增: this.data = data;
66新增: this.sleepdiscover = sleepdiscover;
67新增: this.appConfig = appConfig;
68新增: this.dateObserver = dateObserver;
69新增:
70新增: observer.OnAppActive += Observer_OnAppActive;
71新增: sleepdiscover.SleepStatusChanged += Sleepdiscover_SleepStatusChanged;
72新增: activeWatcher = new Stopwatch();
73新增: appConfig.ConfigChanged += AppConfig_ConfigChanged;
74新增: dateObserver.OnDateChanging += DateObserver_OnDateChanging;
75新增:
76新增: }
77新增:
78新增: private void DateObserver_OnDateChanging(object sender, EventArgs e)
79新增: {
80新增: Debug.WriteLine("日期变更前:" + DateTime.Now.ToString());
81新增: UpdateTime();
82新增: }
83新增:
84新增: private void AppConfig_ConfigChanged(ConfigModel oldConfig, ConfigModel newConfig)
85新增: {
86新增: if (oldConfig != newConfig)
87新增: {
88新增: // 处理开机自启
89新增: Shortcut.SetStartup(newConfig.General.IsStartatboot);
90新增: }
1691 }
92新增:
1793 public void Run()
1894 {
95新增: // 加载应用配置(确保配置文件最先加载
96新增: appConfig.Load();
97新增: config = appConfig.GetConfig();
98新增:
99新增: // 日期变化观察
100新增: dateObserver.Start();
101新增:
102新增: // 启动进程观察
19103 observer.Start();
104新增:
105新增: // 启动睡眠监测
106新增: sleepdiscover.Start();
107新增:
20108 }
21109
22110 public void Exit()
23111 {
24112 observer?.Stop();
25113 }
114新增:
115新增:
116新增: private void Sleepdiscover_SleepStatusChanged(Enums.SleepStatus sleepStatus)
117新增: {
118新增: this.sleepStatus = sleepStatus;
119新增:
120新增: Debug.WriteLine("睡眠状态:" + sleepStatus);
121新增:
122新增: if (sleepStatus == SleepStatus.Sleep)
123新增: {
124新增: // 更新时间
125新增: UpdateTime();
126新增:
127新增: activeProcess = null;
128新增:
129新增: activeWatcher.Stop();
130新增: }
131新增: }
132新增:
133新增: private void Observer_OnAppActive(string processName, string description, string file)
134新增: {
135新增:
136新增: if (activeProcess != processName && activeProcessFile != file)
137新增: {
138新增: UpdateTime();
139新增: }
140新增:
141新增: if (!IgnoreProcess.Contains(processName)
142新增: && file != string.Empty
143新增: && sleepStatus != SleepStatus.Sleep)
144新增: {
145新增: activeProcess = processName;
146新增: activeProcessDescription = description;
147新增: activeProcessFile = file;
148新增:
149新增: //activeStartTime = DateTime.Now;
150新增: activeWatcher.Restart();
151新增:
152新增: // 提取icon
153新增: Iconer.ExtractFromFile(file, processName, description);
154新增: }
155新增: else
156新增: {
157新增: activeProcess = null;
158新增: activeWatcher.Stop();
159新增: }
160新增: }
161新增:
162新增: private void HandleLinks(string processName, int seconds)
163新增: {
164新增: try
165新增: {
166新增: List<LinkModel> links = config.Links != null ? config.Links : new List<LinkModel>();
167新增: foreach (LinkModel link in links)
168新增: {
169新增: if (link.ProcessList != null
170新增: && link.ProcessList.Count >= 2
171新增: && link.ProcessList.Contains(processName))
172新增: {
173新增: // 属于关联进程
174新增: foreach (string linkProcess in link.ProcessList)
175新增: {
176新增: if (linkProcess != processName)
177新增: {
178新增: if (IsProcessRuning(linkProcess))
179新增: {
180新增: // 同步更新
181新增: data.Set(linkProcess, seconds);
182新增: }
183新增:
184新增: }
185新增: }
186新增: break;
187新增: }
188新增: }
189新增: }
190新增: catch (Exception ex)
191新增: {
192新增: Logger.Error(ex.Message + ",关联进程更新错误,Process Name: " + processName + ",Time: " + seconds);
193新增: }
194新增:
195新增: }
196新增:
197新增: #region 判断进程是否在运行中
198新增: /// <summary>
199新增: /// 判断进程是否在运行中
200新增: /// </summary>
201新增: /// <param name="processName"></param>
202新增: /// <returns></returns>
203新增: private bool IsProcessRuning(string processName)
204新增: {
205新增: Process[] process = Process.GetProcessesByName(processName);
206新增: return process != null && process.Length > 0;
207新增: }
208新增: #endregion
209新增:
210新增: private void UpdateTime()
211新增: {
212新增: if (!string.IsNullOrEmpty(activeProcess))
213新增: {
214新增: // 更新计时
215新增:
216新增: int seconds = (int)activeWatcher.Elapsed.TotalSeconds;
217新增:
218新增: Debug.WriteLine(sleepStatus + " 进程:" + activeProcess + " 更新时间:" + seconds);
219新增: if (seconds <= 0)
220新增: {
221新增: return;
222新增: }
223新增:
224新增: data.Set(activeProcess, activeProcessDescription, activeProcessFile, seconds);
225新增:
226新增: // 关联进程更新
227新增: HandleLinks(activeProcess, seconds);
228新增:
229新增: OnUpdateTime?.Invoke(this, null);
230新增: }
231新增: }
232新增:
26233 }
27234}
修改Core/Servicers/Instances/Observer.cs+76 −6看文件
@@ -1,9 +1,12 @@
1删除:using Core.Librarys;
1新增:using Core.Event;
2新增:using Core.Librarys;
23using Core.Servicers.Interfaces;
34using System;
45using System.Collections.Generic;
56using System.Diagnostics;
7新增:using System.IO;
68using System.Linq;
9新增:using System.Runtime.InteropServices;
710using System.Text;
811using System.Threading.Tasks;
912
@@ -14,6 +17,11 @@ namespace Core.Servicers.Instances
1417 private IntPtr hook;
1518 Win32API.WinEventDelegate winEventDelegate;
1619
20新增:
21新增: public event ObserverEventHandler OnAppActive;
22新增:
23新增:
24新增: private string activeProcessName, activeProcessFile = null;
1725 public Observer()
1826 {
1927 winEventDelegate = new Win32API.WinEventDelegate(WinEventProc);
@@ -24,14 +32,76 @@ namespace Core.Servicers.Instances
2432 winEventDelegate, 0, 0, 0);
2533 }
2634
27删除: private static void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
35新增: private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
2836 {
29删除: int processID = 0;
30删除: Win32API.GetWindowThreadProcessId(hwnd, out processID);
31删除: Process process = Process.GetProcessById(processID);
32删除: Debug.WriteLine(process.ProcessName);
37新增: string processName = String.Empty, processFileName = String.Empty, processDescription = String.Empty;
38新增:
39新增: try
40新增: {
41新增: int processID = 0;
42新增: Win32API.GetWindowThreadProcessId(hwnd, out processID);
43新增: Process process = Process.GetProcessById(processID);
44新增: processName = process.ProcessName;
45新增:
46新增: IntPtr processHandle = IntPtr.Zero;
47新增: processHandle = Win32API.OpenProcess(0x001F0FFF, false, processID);
48新增:
49新增: if (processName == "Snipaste")
50新增: {
51新增:
52新增: int error = Marshal.GetLastWin32Error();
53新增:
54新增: Debug.WriteLine("The last Win32 Error was: " + error);
55新增:
56新增: }
57新增: var buffer = new StringBuilder(4096);
58新增: Win32API.GetModuleFileNameExA(processHandle, IntPtr.Zero, buffer, buffer.Capacity);
59新增: processFileName = buffer.ToString();
60新增:
61新增: // handle uwp app
62新增: if (processFileName.IndexOf("ApplicationFrameHost.exe") != -1)
63新增: {
64新增: processFileName = Win32API.UWP_AppName(hwnd, (uint)processID);
65新增: if (processFileName != string.Empty && processFileName.IndexOf("\\") != -1)
66新增: {
67新增: processName = processFileName.Split('\\').Last();
68新增: processName = processName.Replace(".exe", "");
69新增: }
70新增: }
71新增:
72新增: FileVersionInfo info = FileVersionInfo.GetVersionInfo(processFileName);
73新增: processDescription = info.FileDescription;
74新增:
75新增:
76新增: //Debug.WriteLine("file name: ---------> " + processFileName);
77新增: //Debug.WriteLine("app name: ---------> " + processName);
78新增: //Debug.WriteLine("processDescription: ---------> " + processDescription);
79新增: }
80新增: catch (Exception e)
81新增: {
82新增: Logger.Error(e.Message + " | Process Name:" + processName + " | Process File:" + processFileName + " | Process Description:" + processDescription);
83新增: }
84新增:
85新增: EventInvoke(processName, processDescription, processFileName);
3386 }
3487
88新增: private void EventInvoke(string processName, string description, string filename)
89新增: {
90新增: // 防止重复和错误响应
91新增: if (string.IsNullOrEmpty(processName) || string.IsNullOrEmpty(filename) || !File.Exists(filename))
92新增: {
93新增: return;
94新增: }
95新增: if (filename == activeProcessFile && processName == activeProcessName)
96新增: {
97新增: return;
98新增: }
99新增:
100新增: activeProcessName = processName;
101新增: activeProcessFile = filename;
102新增:
103新增: OnAppActive?.Invoke(processName, description, filename);
104新增: }
35105
36106 public void Stop()
37107 {
新增Core/Servicers/Instances/Sleepdiscover.cs+111 −0看文件
@@ -0,0 +1,111 @@
1新增:using Core.Enums;
2新增:using Core.Event;
3新增:using Core.Librarys;
4新增:using Core.Servicers.Interfaces;
5新增:using System;
6新增:using System.Collections.Generic;
7新增:using System.Diagnostics;
8新增:using System.Linq;
9新增:using System.Text;
10新增:using System.Threading.Tasks;
11新增:using System.Windows;
12新增:using System.Windows.Threading;
13新增:
14新增:namespace Core.Servicers.Instances
15新增:{
16新增: public class Sleepdiscover : ISleepdiscover
17新增: {
18新增: public event SleepdiscoverEventHandler SleepStatusChanged;
19新增:
20新增: private DispatcherTimer timer;
21新增:
22新增: private Point lastPoint;
23新增:
24新增: private SleepStatus status = SleepStatus.Wake;
25新增:
26新增: // 播放声音开始时间
27新增: private DateTime playSoundStartTime;
28新增: public void Start()
29新增: {
30新增: timer = new DispatcherTimer();
31新增: timer.Interval = new TimeSpan(0, 2, 0);
32新增: timer.Tick += Timer_Tick;
33新增: timer.Start();
34新增:
35新增: Win32API.GetCursorPos(out lastPoint);
36新增:
37新增: playSoundStartTime = DateTime.MinValue;
38新增: }
39新增:
40新增: private void Timer_Tick(object sender, EventArgs e)
41新增: {
42新增: Point point;
43新增: Win32API.GetCursorPos(out point);
44新增:
45新增: if (point == null)
46新增: {
47新增: return;
48新增: }
49新增:
50新增: if (lastPoint == null)
51新增: {
52新增: lastPoint = point;
53新增: return;
54新增: }
55新增:
56新增: if (status == SleepStatus.Wake)
57新增: {
58新增:
59新增: if (lastPoint.ToString() == point.ToString())
60新增: {
61新增: // 处于活跃状态
62新增: bool isPlaySound = Win32API.IsWindowsPlayingSound();
63新增: // 超过时间未活动鼠标
64新增:
65新增: if (isPlaySound)
66新增: {
67新增: // 在播放声音
68新增:
69新增: if (playSoundStartTime == DateTime.MinValue)
70新增: {
71新增: playSoundStartTime = DateTime.Now;
72新增: }
73新增: else
74新增: {
75新增: // 判断声音时间是否超过2个小时
76新增: TimeSpan timeSpan = DateTime.Now - playSoundStartTime;
77新增:
78新增: if (timeSpan.TotalHours >= 2)
79新增: {
80新增: // 超过表示可能睡着了,切换状态
81新增: status = SleepStatus.Sleep;
82新增:
83新增: playSoundStartTime = DateTime.MinValue;
84新增:
85新增: SleepStatusChanged?.Invoke(status);
86新增: }
87新增: }
88新增: }
89新增: else
90新增: {
91新增: // 没有播放声音切换状态
92新增: status = SleepStatus.Sleep;
93新增: SleepStatusChanged?.Invoke(status);
94新增: }
95新增: }
96新增: }
97新增: else
98新增: {
99新增: // 处于休眠状态
100新增: if (lastPoint.ToString() != point.ToString())
101新增: {
102新增: // 鼠标活动了切换状态
103新增: status = SleepStatus.Wake;
104新增: SleepStatusChanged?.Invoke(status);
105新增: }
106新增: }
107新增:
108新增: Win32API.GetCursorPos(out lastPoint);
109新增: }
110新增: }
111新增:}
新增Core/Servicers/Interfaces/IAppConfig.cs+36 −0看文件
@@ -0,0 +1,36 @@
1新增:using Core.Event;
2新增:using Core.Models.Config;
3新增:using System;
4新增:using System.Collections.Generic;
5新增:using System.Linq;
6新增:using System.Text;
7新增:using System.Threading.Tasks;
8新增:
9新增:namespace Core.Servicers.Interfaces
10新增:{
11新增: /// <summary>
12新增: /// 应用配置
13新增: /// </summary>
14新增: public interface IAppConfig
15新增: {
16新增: /// <summary>
17新增: /// 加载配置
18新增: /// </summary>
19新增: void Load();
20新增:
21新增: /// <summary>
22新增: /// 获取配置
23新增: /// </summary>
24新增: /// <returns></returns>
25新增: ConfigModel GetConfig();
26新增:
27新增: /// <summary>
28新增: /// 更新配置
29新增: /// </summary>
30新增: void Save();
31新增: /// <summary>
32新增: /// 配置修改时发生
33新增: /// </summary>
34新增: event AppConfigEventHandler ConfigChanged;
35新增: }
36新增:}
新增Core/Servicers/Interfaces/IData.cs+67 −0看文件
@@ -0,0 +1,67 @@
1新增:using Core.Models;
2新增:using System;
3新增:using System.Collections.Generic;
4新增:using System.Linq;
5新增:using System.Text;
6新增:using System.Threading.Tasks;
7新增:
8新增:namespace Core.Servicers.Interfaces
9新增:{
10新增: public interface IData
11新增: {
12新增: /// <summary>
13新增: /// 设置进程数据
14新增: /// </summary>
15新增: /// <param name="processName"></param>
16新增: /// <param name="processDescription"></param>
17新增: /// <param name="file"></param>
18新增: /// <param name="seconds"></param>
19新增: void Set(string processName, string processDescription, string file, int seconds);
20新增:
21新增: /// <summary>
22新增: /// 获取今天的数据
23新增: /// </summary>
24新增: /// <returns></returns>
25新增: List<DailyLogModel> GetTodaylogList();
26新增: /// <summary>
27新增: /// 查询指定范围数据
28新增: /// </summary>
29新增: /// <param name="start"></param>
30新增: /// <param name="end"></param>
31新增: /// <returns></returns>
32新增: List<DailyLogModel> GetDateRangelogList(DateTime start, DateTime end);
33新增:
34新增: /// <summary>
35新增: /// 获取本周的数据
36新增: /// </summary>
37新增: /// <returns></returns>
38新增: List<DailyLogModel> GetThisWeeklogList();
39新增: /// <summary>
40新增: /// 获取上周的数据
41新增: /// </summary>
42新增: /// <returns></returns>
43新增: List<DailyLogModel> GetLastWeeklogList();
44新增: /// <summary>
45新增: /// 设置进程数据(仅通过进程名可能会出现重复的问题
46新增: /// </summary>
47新增: /// <param name="processName"></param>
48新增: /// <param name="seconds"></param>
49新增: void Set(string processName, int seconds);
50新增:
51新增: /// <summary>
52新增: /// 获取指定进程某个月的数据
53新增: /// </summary>
54新增: /// <param name="file"></param>
55新增: /// <param name="month"></param>
56新增: /// <returns></returns>
57新增: List<DailyLogModel> GetProcessMonthLogList(string file, DateTime month);
58新增:
59新增: /// <summary>
60新增: /// 获取一个进程最后一条记录
61新增: /// </summary>
62新增: /// <param name="file"></param>
63新增: /// <returns></returns>
64新增: DailyLogModel GetLast(string file);
65新增:
66新增: }
67新增:}
新增Core/Servicers/Interfaces/IDateObserver.cs+23 −0看文件
@@ -0,0 +1,23 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace Core.Servicers.Interfaces
8新增:{
9新增: /// <summary>
10新增: /// 日期变更观察(用于监听日期变化
11新增: /// </summary>
12新增: public interface IDateObserver
13新增: {
14新增: /// <summary>
15新增: /// 启动
16新增: /// </summary>
17新增: void Start();
18新增: /// <summary>
19新增: /// 日期即将变化时发生(前30秒)
20新增: /// </summary>
21新增: event EventHandler OnDateChanging;
22新增: }
23新增:}
删除Core/Servicers/Interfaces/ILogger.cs+0 −16
@@ -1,16 +0,0 @@
1删除:using System;
2删除:using System.Collections.Generic;
3删除:using System.Linq;
4删除:using System.Runtime.CompilerServices;
5删除:using System.Text;
6删除:using System.Threading.Tasks;
7删除:
8删除:namespace Core.Servicers.Interfaces
9删除:{
10删除: public interface ILogger
11删除: {
12删除: void Info(string message, [CallerLineNumber] int callerLineNumber = -1, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerMemberName = null);
13删除: void Warn(string message, [CallerLineNumber] int callerLineNumber = -1, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerMemberName = null);
14删除: void Error(string message, [CallerLineNumber] int callerLineNumber = -1, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerMemberName = null);
15删除: }
16删除:}
修改Core/Servicers/Interfaces/IMain.cs+5 −0看文件
@@ -19,5 +19,10 @@ namespace Core.Servicers.Interfaces
1919 /// 退出服务
2020 /// </summary>
2121 void Exit();
22新增:
23新增: /// <summary>
24新增: /// 更新某个进程时间时发生
25新增: /// </summary>
26新增: event EventHandler OnUpdateTime;
2227 }
2328}
修改Core/Servicers/Interfaces/IObserver.cs+7 −1看文件
@@ -1,4 +1,5 @@
1删除:using System;
1新增:using Core.Event;
2新增:using System;
23using System.Collections.Generic;
34using System.Linq;
45using System.Text;
@@ -19,5 +20,10 @@ namespace Core.Servicers.Interfaces
1920 /// 停止观察
2021 /// </summary>
2122 void Stop();
23新增:
24新增: /// <summary>
25新增: /// 切换活跃APP时发生
26新增: /// </summary>
27新增: event ObserverEventHandler OnAppActive;
2228 }
2329}
新增Core/Servicers/Interfaces/ISleepdiscover.cs+22 −0看文件
@@ -0,0 +1,22 @@
1新增:using Core.Event;
2新增:using System;
3新增:using System.Collections.Generic;
4新增:using System.Linq;
5新增:using System.Text;
6新增:using System.Threading.Tasks;
7新增:
8新增:namespace Core.Servicers.Interfaces
9新增:{
10新增: public interface ISleepdiscover
11新增: {
12新增: /// <summary>
13新增: /// 启动
14新增: /// </summary>
15新增: void Start();
16新增:
17新增: /// <summary>
18新增: /// 休眠状态发生更改
19新增: /// </summary>
20新增: event SleepdiscoverEventHandler SleepStatusChanged;
21新增: }
22新增:}
新增Core/packages.config+15 −0看文件
@@ -0,0 +1,15 @@
1新增:<?xml version="1.0" encoding="utf-8"?>
2新增:<packages>
3新增: <package id="EntityFramework" version="6.3.0" targetFramework="net461" />
4新增: <package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
5新增: <package id="SQLitePCLRaw.core" version="2.0.6" targetFramework="net461" />
6新增: <package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.115.5" targetFramework="net461" />
7新增: <package id="System.Buffers" version="4.4.0" targetFramework="net461" />
8新增: <package id="System.Data.SQLite" version="1.0.113.7" targetFramework="net461" />
9新增: <package id="System.Data.SQLite.Core" version="1.0.115.5" targetFramework="net461" />
10新增: <package id="System.Data.SQLite.EF6" version="1.0.113.0" targetFramework="net461" />
11新增: <package id="System.Data.SQLite.Linq" version="1.0.115.5" targetFramework="net461" />
12新增: <package id="System.Memory" version="4.5.3" targetFramework="net461" />
13新增: <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net461" />
14新增: <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net461" />
15新增:</packages>
文件末尾没有换行
修改Tai.sln+10 −0看文件
@@ -10,17 +10,27 @@ EndProject
1010Global
1111 GlobalSection(SolutionConfigurationPlatforms) = preSolution
1212 Debug|Any CPU = Debug|Any CPU
13新增: Debug|x64 = Debug|x64
1314 Release|Any CPU = Release|Any CPU
15新增: Release|x64 = Release|x64
1416 EndGlobalSection
1517 GlobalSection(ProjectConfigurationPlatforms) = postSolution
1618 {FA57023C-3399-45A4-A339-E453002BD878}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1719 {FA57023C-3399-45A4-A339-E453002BD878}.Debug|Any CPU.Build.0 = Debug|Any CPU
20新增: {FA57023C-3399-45A4-A339-E453002BD878}.Debug|x64.ActiveCfg = Debug|x64
21新增: {FA57023C-3399-45A4-A339-E453002BD878}.Debug|x64.Build.0 = Debug|x64
1822 {FA57023C-3399-45A4-A339-E453002BD878}.Release|Any CPU.ActiveCfg = Release|Any CPU
1923 {FA57023C-3399-45A4-A339-E453002BD878}.Release|Any CPU.Build.0 = Release|Any CPU
24新增: {FA57023C-3399-45A4-A339-E453002BD878}.Release|x64.ActiveCfg = Release|x64
25新增: {FA57023C-3399-45A4-A339-E453002BD878}.Release|x64.Build.0 = Release|x64
2026 {24270E1E-8C24-40B0-A463-98753DFAA4AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2127 {24270E1E-8C24-40B0-A463-98753DFAA4AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
28新增: {24270E1E-8C24-40B0-A463-98753DFAA4AE}.Debug|x64.ActiveCfg = Debug|x64
29新增: {24270E1E-8C24-40B0-A463-98753DFAA4AE}.Debug|x64.Build.0 = Debug|x64
2230 {24270E1E-8C24-40B0-A463-98753DFAA4AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
2331 {24270E1E-8C24-40B0-A463-98753DFAA4AE}.Release|Any CPU.Build.0 = Release|Any CPU
32新增: {24270E1E-8C24-40B0-A463-98753DFAA4AE}.Release|x64.ActiveCfg = Release|x64
33新增: {24270E1E-8C24-40B0-A463-98753DFAA4AE}.Release|x64.Build.0 = Release|x64
2434 EndGlobalSection
2535 GlobalSection(SolutionProperties) = preSolution
2636 HideSolutionNode = FALSE
修改UI/App.config+4 −0看文件
@@ -9,6 +9,10 @@
99 <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
1010 <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
1111 </dependentAssembly>
12新增: <dependentAssembly>
13新增: <assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" />
14新增: <bindingRedirect oldVersion="0.0.0.0-1.0.115.5" newVersion="1.0.115.5" />
15新增: </dependentAssembly>
1216 </assemblyBinding>
1317 </runtime>
1418</configuration>
修改UI/App.xaml.cs+72 −7看文件
@@ -5,6 +5,7 @@ using System;
55using System.Collections.Generic;
66using System.Configuration;
77using System.Data;
8新增:using System.Diagnostics;
89using System.Drawing;
910using System.Linq;
1011using System.Threading.Tasks;
@@ -23,6 +24,7 @@ namespace UI
2324 public partial class App : Application
2425 {
2526 private readonly ServiceProvider serviceProvider;
27新增: private System.Threading.Mutex mutex;
2628
2729 // 状态栏图标
2830 private System.Windows.Forms.NotifyIcon statusBarIcon;
@@ -32,13 +34,33 @@ namespace UI
3234
3335 // 状态栏图标菜单
3436 private ContextMenu contextMenu;
37新增:
38新增: private DefaultWindow mainWindow;
3539 public App()
3640 {
3741 var serviceCollection = new ServiceCollection();
3842 ConfigureServices(serviceCollection);
3943 serviceProvider = serviceCollection.BuildServiceProvider();
44新增: }
45新增:
46新增: #region 获取当前程序是否已运行
47新增: /// <summary>
48新增: /// 获取当前程序是否已运行
49新增: /// </summary>
50新增: private bool IsRuned()
51新增: {
52新增: bool ret;
53新增: mutex = new System.Threading.Mutex(true, System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name, out ret);
54新增: if (!ret)
55新增: {
56新增:#if !DEBUG
57新增: return true;
4058
59新增:#endif
60新增: }
61新增: return false;
4162 }
63新增: #endregion
4264
4365 #region 状态栏图标
4466 /// <summary>
@@ -49,9 +71,8 @@ namespace UI
4971 CreateStatusBarIconMenu();
5072
5173 statusBarIcon = new System.Windows.Forms.NotifyIcon();
52删除:
53删除: statusBarIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(
54删除: System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name);
74新增: statusBarIcon.Text = "Tai!";
75新增: statusBarIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name);
5576
5677 statusBarIcon.Visible = true;
5778 statusBarIcon.MouseClick += NotifyIcon_MouseClick;
@@ -89,8 +110,18 @@ namespace UI
89110 var mainWindowMenuItem = new MenuItem();
90111 mainWindowMenuItem.Header = "主界面";
91112 mainWindowMenuItem.Click += MainWindowMenuItem_Click;
113新增: var exitMenuItem = new MenuItem();
114新增: exitMenuItem.Header = "退出";
115新增: exitMenuItem.Click += ExitMenuItem_Click; ;
92116
93117 contextMenu.Items.Add(mainWindowMenuItem);
118新增: contextMenu.Items.Add(exitMenuItem);
119新增:
120新增: }
121新增:
122新增: private void ExitMenuItem_Click(object sender, RoutedEventArgs e)
123新增: {
124新增: Shutdown();
94125 }
95126
96127 private void MainWindowMenuItem_Click(object sender, RoutedEventArgs e)
@@ -101,17 +132,43 @@ namespace UI
101132
102133 private void ConfigureServices(IServiceCollection services)
103134 {
135新增: // 核心服务
104136 services.AddSingleton<IObserver, Observer>();
105137 services.AddSingleton<IMain, Main>();
138新增: services.AddSingleton<IData, Data>();
139新增: services.AddSingleton<ISleepdiscover, Sleepdiscover>();
140新增: services.AddSingleton<IAppConfig, AppConfig>();
141新增: services.AddSingleton<IDateObserver, DateObserver>();
106142
143新增: // 主窗口
107144 services.AddSingleton<MainViewModel>();
108145 services.AddTransient<MainWindow>();
109146
147新增: // 首页
110148 services.AddTransient<IndexPage>();
149新增: services.AddTransient<IndexPageVM>();
150新增:
151新增: // 数据页
152新增: services.AddTransient<DataPage>();
153新增: services.AddTransient<DataPageVM>();
154新增:
155新增: // 设置页
156新增: services.AddTransient<SettingPage>();
157新增: services.AddTransient<SettingPageVM>();
158新增:
159新增: // 详情页
160新增: services.AddTransient<DetailPage>();
161新增: services.AddTransient<DetailPageVM>();
111162 }
112163
113164 private void OnStartup(object sender, StartupEventArgs e)
114165 {
166新增: // 阻止多开进程
167新增: if (IsRuned())
168新增: {
169新增: Shutdown();
170新增: }
171新增:
115172 var main = serviceProvider.GetService<IMain>();
116173 main.Run();
117174
@@ -128,12 +185,20 @@ namespace UI
128185
129186 private void ShowMainWindow()
130187 {
131删除: var mainWindow = serviceProvider.GetService<MainWindow>();
132188 var dataContext = serviceProvider.GetService<MainViewModel>();
133删除: mainWindow.DataContext = dataContext;
134删除: dataContext.SelectGroup(-1);
135删除: ////dataContext.Uri = nameof(IndexPage);
189新增:
190新增:
191新增: if (mainWindow == null || mainWindow.IsWindowClosed)
192新增: {
193新增: mainWindow = serviceProvider.GetService<MainWindow>();
194新增:
195新增: mainWindow.DataContext = dataContext;
196新增: dataContext.SelectGroup(-1);
197新增: dataContext.Uri = nameof(IndexPage);
198新增: }
199新增:
136200 mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
201新增: mainWindow.WindowState = WindowState.Normal;
137202 mainWindow.Show();
138203 mainWindow.Activate();
139204 }
新增UI/Controls/Base/EmptyData.cs+18 −0看文件
@@ -0,0 +1,18 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Text;
4新增:using System.Windows;
5新增:using System.Windows.Controls;
6新增:using System.Windows.Media;
7新增:using System.Windows.Media.Animation;
8新增:
9新增:namespace UI.Controls.Base
10新增:{
11新增: public class EmptyData : Control
12新增: {
13新增: public EmptyData()
14新增: {
15新增: DefaultStyleKey = typeof(EmptyData);
16新增: }
17新增: }
18新增:}
修改UI/Controls/Base/IconConverter.cs+1 −0看文件
@@ -114,6 +114,7 @@ namespace UI.Controls.Base
114114 {IconTypes.Bug,"\xEBE8"},
115115 {IconTypes.ChevronUp,"\xE70E"},
116116 {IconTypes.BIDashboard,"\xF543"},
117新增: {IconTypes.Preview,"\xE8FF"},
117118
118119
119120 };
修改UI/Controls/Base/IconTypes.cs+2 −1看文件
@@ -137,6 +137,7 @@ namespace UI.Controls.Base
137137 Cat,
138138 Car,
139139 Bug,
140删除: BIDashboard
140新增: BIDashboard,
141新增: Preview
141142 }
142143}
新增UI/Controls/Base/Placeholder.cs+60 −0看文件
@@ -0,0 +1,60 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Text;
4新增:using System.Windows;
5新增:using System.Windows.Controls;
6新增:using System.Windows.Media;
7新增:using System.Windows.Media.Animation;
8新增:
9新增:namespace UI.Controls.Base
10新增:{
11新增: public class Placeholder : Control
12新增: {
13新增: public CornerRadius CornerRadius
14新增: {
15新增: get { return (CornerRadius)GetValue(CornerRadiusProperty); }
16新增: set { SetValue(CornerRadiusProperty, value); }
17新增: }
18新增: public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius",
19新增: typeof(CornerRadius),
20新增: typeof(Placeholder));
21新增:
22新增: private Border Flash;
23新增: public Placeholder()
24新增: {
25新增:
26新增: DefaultStyleKey = typeof(Placeholder);
27新增: }
28新增: public override void OnApplyTemplate()
29新增: {
30新增: base.OnApplyTemplate();
31新增: Flash = GetTemplateChild("Flash") as Border;
32新增: Loaded += Placeholder_Loaded;
33新增: }
34新增:
35新增: private void Placeholder_Loaded(object sender, RoutedEventArgs e)
36新增: {
37新增: Animation();
38新增: }
39新增:
40新增: private void Animation()
41新增: {
42新增: Storyboard storyboard = new Storyboard();
43新增: DoubleAnimation scrollAnimation = new DoubleAnimation();
44新增: scrollAnimation.From = -10;
45新增: scrollAnimation.To = ActualWidth;
46新增:
47新增: scrollAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
48新增: Storyboard.SetTarget(scrollAnimation, Flash);
49新增: Storyboard.SetTargetProperty(scrollAnimation, new PropertyPath("RenderTransform.Children[0].X"));
50新增: scrollAnimation.AutoReverse = true;
51新增: scrollAnimation.RepeatBehavior = RepeatBehavior.Forever;
52新增: scrollAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
53新增:
54新增: storyboard.Children.Add(scrollAnimation);
55新增:
56新增: storyboard.Begin();
57新增: }
58新增:
59新增: }
60新增:}
新增UI/Controls/Button/Button.cs+40 −0看文件
@@ -0,0 +1,40 @@
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新增:using System.Windows.Input;
9新增:using UI.Controls.Base;
10新增:
11新增:namespace UI.Controls.Button
12新增:{
13新增: public class Button : System.Windows.Controls.Button
14新增: {
15新增: public IconTypes Icon
16新增: {
17新增: get { return (IconTypes)GetValue(IconProperty); }
18新增: set { SetValue(IconProperty, value); }
19新增: }
20新增: public static readonly DependencyProperty IconProperty =
21新增: DependencyProperty.Register("Icon",
22新增: typeof(IconTypes),
23新增: typeof(Button), new PropertyMetadata(IconTypes.None));
24新增: public Button()
25新增: {
26新增: DefaultStyleKey = typeof(Button);
27新增: }
28新增:
29新增: //protected override void OnMouseEnter(MouseEventArgs e)
30新增: //{
31新增: // base.OnMouseEnter(e);
32新增: // VisualStateManager.GoToState(this, "MouseOver", true);
33新增: //}
34新增: //protected override void OnMouseLeave(MouseEventArgs e)
35新增: //{
36新增: // base.OnMouseLeave(e);
37新增: // VisualStateManager.GoToState(this, "Normal", true);
38新增: //}
39新增: }
40新增:}
新增UI/Controls/Button/IconButton.cs+55 −0看文件
@@ -0,0 +1,55 @@
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新增:using System.Windows.Input;
9新增:using UI.Controls.Base;
10新增:
11新增:namespace UI.Controls.Button
12新增:{
13新增: public class IconButton : Control
14新增: {
15新增: public Command Command
16新增: {
17新增: get { return (Command)GetValue(CommandProperty); }
18新增: set { SetValue(CommandProperty, value); }
19新增: }
20新增: public static readonly DependencyProperty CommandProperty =
21新增: DependencyProperty.Register("Command",
22新增: typeof(Command),
23新增: typeof(IconButton));
24新增: public IconTypes Icon
25新增: {
26新增: get { return (IconTypes)GetValue(IconProperty); }
27新增: set { SetValue(IconProperty, value); }
28新增: }
29新增: public static readonly DependencyProperty IconProperty =
30新增: DependencyProperty.Register("Icon",
31新增: typeof(IconTypes),
32新增: typeof(IconButton), new PropertyMetadata(IconTypes.None));
33新增: public IconButton()
34新增: {
35新增: DefaultStyleKey = typeof(IconButton);
36新增: }
37新增:
38新增: protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
39新增: {
40新增: base.OnMouseLeftButtonUp(e);
41新增:
42新增: Command?.Execute(null);
43新增: }
44新增: protected override void OnMouseEnter(MouseEventArgs e)
45新增: {
46新增: base.OnMouseEnter(e);
47新增: VisualStateManager.GoToState(this, "MouseOver", true);
48新增: }
49新增: protected override void OnMouseLeave(MouseEventArgs e)
50新增: {
51新增: base.OnMouseLeave(e);
52新增: VisualStateManager.GoToState(this, "Normal", true);
53新增: }
54新增: }
55新增:}
新增UI/Controls/Charts/Charts.cs+489 −0看文件
@@ -0,0 +1,489 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Diagnostics;
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.Data;
10新增:using System.Windows.Documents;
11新增:using System.Windows.Input;
12新增:using System.Windows.Media;
13新增:using System.Windows.Media.Imaging;
14新增:using System.Windows.Navigation;
15新增:using System.Windows.Shapes;
16新增:using UI.Controls.Base;
17新增:using UI.Controls.Charts.Model;
18新增:using UI.Extensions;
19新增:
20新增:namespace UI.Controls.Charts
21新增:{
22新增: public class Charts : Control
23新增: {
24新增: #region ChartsType 样式类型
25新增: /// <summary>
26新增: /// 样式类型
27新增: /// </summary>
28新增: public ChartsType ChartsType
29新增: {
30新增: get { return (ChartsType)GetValue(ChartsTypeProperty); }
31新增: set { SetValue(ChartsTypeProperty, value); }
32新增: }
33新增: public static readonly DependencyProperty ChartsTypeProperty =
34新增: DependencyProperty.Register("ChartsType",
35新增: typeof(ChartsType),
36新增: typeof(Charts));
37新增:
38新增:
39新增: #endregion
40新增: #region MaxValueLimit 限制最大值
41新增: /// <summary>
42新增: /// 样式类型
43新增: /// </summary>
44新增: public double MaxValueLimit
45新增: {
46新增: get { return (double)GetValue(MaxValueLimitProperty); }
47新增: set { SetValue(MaxValueLimitProperty, value); }
48新增: }
49新增: public static readonly DependencyProperty MaxValueLimitProperty =
50新增: DependencyProperty.Register("MaxValueLimit",
51新增: typeof(double),
52新增: typeof(Charts),
53新增: new PropertyMetadata((double)0));
54新增:
55新增:
56新增: #endregion
57新增: #region ShowLimit 显示条数限制
58新增: /// <summary>
59新增: /// 样式类型
60新增: /// </summary>
61新增: public int ShowLimit
62新增: {
63新增: get { return (int)GetValue(ShowLimitProperty); }
64新增: set { SetValue(ShowLimitProperty, value); }
65新增: }
66新增: public static readonly DependencyProperty ShowLimitProperty =
67新增: DependencyProperty.Register("ShowLimit",
68新增: typeof(int),
69新增: typeof(Charts),
70新增: new PropertyMetadata((int)0));
71新增:
72新增:
73新增: #endregion
74新增: #region Data 数据
75新增: /// <summary>
76新增: /// 样式类型
77新增: /// </summary>
78新增: public IEnumerable<ChartsDataModel> Data
79新增: {
80新增: get { return (IEnumerable<ChartsDataModel>)GetValue(DataProperty); }
81新增: set { SetValue(DataProperty, value); }
82新增: }
83新增: public static readonly DependencyProperty DataProperty =
84新增: DependencyProperty.Register("Data",
85新增: typeof(IEnumerable<ChartsDataModel>),
86新增: typeof(Charts),
87新增: new PropertyMetadata(null, new PropertyChangedCallback(OnPropertyChanged))
88新增: );
89新增:
90新增:
91新增: #endregion
92新增: #region LoadingPlaceholderCount 加载中时占位显示条数
93新增: /// <summary>
94新增: /// 加载中时占位显示条数
95新增: /// </summary>
96新增: public int LoadingPlaceholderCount
97新增: {
98新增: get { return (int)GetValue(LoadingPlaceholderCountProperty); }
99新增: set { SetValue(LoadingPlaceholderCountProperty, value); }
100新增: }
101新增: public static readonly DependencyProperty LoadingPlaceholderCountProperty =
102新增: DependencyProperty.Register("LoadingPlaceholderCount",
103新增: typeof(int),
104新增: typeof(Charts),
105新增: new PropertyMetadata((int)3));
106新增:
107新增:
108新增: #endregion
109新增: #region IsLoading 是否在加载中
110新增: /// <summary>
111新增: /// 是否在加载中
112新增: /// </summary>
113新增: public bool IsLoading
114新增: {
115新增: get { return (bool)GetValue(IsLoadingProperty); }
116新增: set { SetValue(IsLoadingProperty, value); }
117新增: }
118新增: public static readonly DependencyProperty IsLoadingProperty =
119新增: DependencyProperty.Register("IsLoading",
120新增: typeof(bool),
121新增: typeof(Charts),
122新增: new PropertyMetadata(false, new PropertyChangedCallback(OnPropertyChanged)));
123新增:
124新增:
125新增: #endregion
126新增: #region ClickCommand 点击命令
127新增: /// <summary>
128新增: /// 点击命令
129新增: /// </summary>
130新增: public Command ClickCommand
131新增: {
132新增: get { return (Command)GetValue(ClickCommandProperty); }
133新增: set { SetValue(ClickCommandProperty, value); }
134新增: }
135新增: public static readonly DependencyProperty ClickCommandProperty =
136新增: DependencyProperty.Register("ClickCommand",
137新增: typeof(Command),
138新增: typeof(Charts));
139新增:
140新增:
141新增: #endregion
142新增: private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
143新增: {
144新增: var charts = (d as Charts);
145新增: if (e.Property == DataProperty)
146新增: {
147新增: var dc = charts.ChartsType;
148新增: charts.Render();
149新增: }
150新增: if (e.Property == IsLoadingProperty)
151新增: {
152新增: if (!charts.IsLoading)
153新增: {
154新增: charts.Render();
155新增: }
156新增: else
157新增: {
158新增: charts.RenderLoadingPlaceholder();
159新增: }
160新增: }
161新增:
162新增: }
163新增: /// <summary>
164新增: /// 点击项目时发生
165新增: /// </summary>
166新增: public event EventHandler OnItemClick;
167新增:
168新增: /// <summary>
169新增: /// 容器
170新增: /// </summary>
171新增: private StackPanel Container;
172新增: private WrapPanel CardContainer;
173新增: private Grid MonthContainer;
174新增:
175新增: /// <summary>
176新增: /// 是否在渲染中
177新增: /// </summary>
178新增: private bool isRendering = false;
179新增: /// <summary>
180新增: /// 计算最大值
181新增: /// </summary>
182新增: private double maxValue = 0;
183新增: public Charts()
184新增: {
185新增: DefaultStyleKey = typeof(Charts);
186新增: }
187新增: public override void OnApplyTemplate()
188新增: {
189新增: base.OnApplyTemplate();
190新增: Container = GetTemplateChild("Container") as StackPanel;
191新增: CardContainer = GetTemplateChild("CardContainer") as WrapPanel;
192新增: MonthContainer = GetTemplateChild("MonthContainer") as Grid;
193新增:
194新增: Loaded += Charts_Loaded;
195新增: }
196新增:
197新增: private void Charts_Loaded(object sender, RoutedEventArgs e)
198新增: {
199新增: if (Container != null)
200新增: {
201新增: if (IsLoading)
202新增: {
203新增: RenderLoadingPlaceholder();
204新增: }
205新增: else
206新增: {
207新增: Render();
208新增: }
209新增: }
210新增: }
211新增:
212新增: private void RenderLoadingPlaceholder()
213新增: {
214新增: if (Container != null && LoadingPlaceholderCount > 0)
215新增: {
216新增: Container.Children.Clear();
217新增: CardContainer.Children.Clear();
218新增:
219新增: for (int i = 0; i < LoadingPlaceholderCount; i++)
220新增: {
221新增: switch (ChartsType)
222新增: {
223新增: case ChartsType.HorizontalA:
224新增: var item = new ChartsItemTypeA();
225新增: item.IsLoading = true;
226新增: Container.Children.Add(item);
227新增: break;
228新增: case ChartsType.Card:
229新增: var card = new ChartsItemTypeCard();
230新增: card.IsLoading = true;
231新增: CardContainer.Children.Add(card);
232新增: break;
233新增: }
234新增: }
235新增:
236新增: }
237新增: }
238新增: private void Calculate()
239新增: {
240新增: if (Data == null)
241新增: {
242新增: return;
243新增: }
244新增: // 计算最大值
245新增: // 如果设置了固定的最大值则使用,否则查找数据中的最大值
246新增: maxValue = MaxValueLimit > 0 ? MaxValueLimit : Data.Count() > 0 ? Data.Max(m => m.Value) : 0;
247新增:
248新增: if (ChartsType == ChartsType.HorizontalA)
249新增: {
250新增: //不允许最大值小于10,否则效果不好看
251新增: if (maxValue < 10)
252新增: {
253新增: maxValue = 10;
254新增: }
255新增: // 适当增加最大值
256新增: maxValue = Math.Round(maxValue / 2, MidpointRounding.AwayFromZero) * 2 + 2;
257新增: }
258新增: }
259新增:
260新增: private void Render()
261新增: {
262新增: if (isRendering || Container == null || CardContainer == null)
263新增: {
264新增: return;
265新增: }
266新增: Calculate();
267新增: Container.Children.Clear();
268新增: CardContainer.Children.Clear();
269新增: MonthContainer.Children.Clear();
270新增:
271新增: if (Data == null || Data.Count() <= 0)
272新增: {
273新增: Container.Children.Add(new EmptyData());
274新增: CardContainer.Children.Add(new EmptyData());
275新增: return;
276新增: }
277新增:
278新增: isRendering = true;
279新增:
280新增: switch (ChartsType)
281新增: {
282新增: case ChartsType.HorizontalA:
283新增: RenderHorizontalAStyle();
284新增: break;
285新增: case ChartsType.Card:
286新增: RenderCardStyle();
287新增: break;
288新增: case ChartsType.Month:
289新增: RenderMonthStyle();
290新增: break;
291新增: }
292新增: }
293新增:
294新增: #region 渲染横向样式A
295新增: private void RenderHorizontalAStyle()
296新增: {
297新增:
298新增: var data = Data.OrderByDescending(x => x.Value).ToList();
299新增:
300新增: foreach (var item in data)
301新增: {
302新增: var chartsItem = new ChartsItemTypeA();
303新增: chartsItem.Data = item;
304新增: chartsItem.ToolTip = item.PopupText;
305新增: chartsItem.MaxValue = maxValue;
306新增:
307新增: // 处理点击事件
308新增: HandleItemClick(chartsItem, item);
309新增:
310新增: Container.Children.Add(chartsItem);
311新增: if (ShowLimit > 0 && Container.Children.Count == ShowLimit)
312新增: {
313新增: break;
314新增: }
315新增: }
316新增: isRendering = false;
317新增: }
318新增: #endregion
319新增: #region 渲染卡片样式Card
320新增: private void RenderCardStyle()
321新增: {
322新增: var data = Data.OrderByDescending(x => x.Value).Take(ShowLimit).ToList();
323新增:
324新增: data.Shuffle();
325新增:
326新增: foreach (var item in data)
327新增: {
328新增: var chartsItem = new ChartsItemTypeCard();
329新增: chartsItem.Data = item;
330新增:
331新增: // 处理点击事件
332新增: HandleItemClick(chartsItem, item);
333新增:
334新增: chartsItem.MaxValue = maxValue;
335新增: chartsItem.ToolTip = item.PopupText;
336新增: CardContainer.Children.Add(chartsItem);
337新增: }
338新增: isRendering = false;
339新增:
340新增: }
341新增: #endregion
342新增:
343新增: #region 渲染月份样式
344新增: private void RenderMonthStyle()
345新增: {
346新增: var data = Data.ToList();
347新增: DateTime month = data[0].DateTime;
348新增:
349新增: int days = DateTime.DaysInMonth(month.Year, month.Month);
350新增:
351新增: // 绘制网格
352新增: var headerGrid = new Grid();
353新增: headerGrid.Margin = new Thickness(0, 0, 0, 10);
354新增:
355新增: var dataGrid = new Grid();
356新增:
357新增: string[] week = { "一", "二", "三", "四", "五", "六", "日" };
358新增: for (int i = 0; i < 7; i++)
359新增: {
360新增:
361新增: dataGrid.ColumnDefinitions.Add(new ColumnDefinition()
362新增: {
363新增: Width = new GridLength(1, GridUnitType.Star)
364新增: });
365新增: headerGrid.ColumnDefinitions.Add(new ColumnDefinition()
366新增: {
367新增: Width = new GridLength(1, GridUnitType.Star)
368新增: });
369新增:
370新增: // 填充头部
371新增: var header = new TextBlock();
372新增: header.Text = week[i];
373新增: header.VerticalAlignment = VerticalAlignment.Center;
374新增: header.HorizontalAlignment = HorizontalAlignment.Center;
375新增: Grid.SetColumn(header, i);
376新增: headerGrid.Children.Add(header);
377新增: }
378新增:
379新增: for (int i = 0; i < 6; i++)
380新增: {
381新增: dataGrid.RowDefinitions.Add(new RowDefinition()
382新增: {
383新增: Height = new GridLength(1, GridUnitType.Star)
384新增: });
385新增: }
386新增:
387新增: // 填充空数据
388新增: for (int i = 0; i < days; i++)
389新增: {
390新增: var date = new DateTime(month.Year, month.Month, i + 1);
391新增: var chartsItem = new ChartsItemTypeMonth();
392新增: chartsItem.Data = new ChartsDataModel()
393新增: {
394新增: DateTime = date,
395新增: };
396新增: var location = CalGridLocation(date);
397新增: Grid.SetColumn(chartsItem, location[0]);
398新增: Grid.SetRow(chartsItem, location[1]);
399新增: dataGrid.Children.Add(chartsItem);
400新增: Debug.WriteLine((i + 1) + " -> " + location[0] + "," + location[1]);
401新增: }
402新增:
403新增: // 填充有效数据
404新增: foreach (var item in data)
405新增: {
406新增: if (item.DateTime != null)
407新增: {
408新增: int day = item.DateTime.Day;
409新增:
410新增: Debug.WriteLine("日期:" + day + "号");
411新增: var chartsItem = new ChartsItemTypeMonth();
412新增: chartsItem.Data = item;
413新增: chartsItem.ToolTip = item.PopupText;
414新增: chartsItem.MaxValue = maxValue;
415新增:
416新增: // 处理点击事件
417新增: HandleItemClick(chartsItem, item);
418新增:
419新增: var location = CalGridLocation(item.DateTime);
420新增:
421新增: Grid.SetColumn(chartsItem, location[0]);
422新增: Grid.SetRow(chartsItem, location[1]);
423新增: dataGrid.Children.Add(chartsItem);
424新增: if (ShowLimit > 0 && Container.Children.Count == ShowLimit)
425新增: {
426新增: break;
427新增: }
428新增: }
429新增: }
430新增:
431新增: var sp = new StackPanel();
432新增: sp.Children.Add(headerGrid);
433新增: sp.Children.Add(dataGrid);
434新增:
435新增: MonthContainer.Children.Add(sp);
436新增: isRendering = false;
437新增: }
438新增:
439新增: private int[] CalGridLocation(DateTime date)
440新增: {
441新增: var res = new int[2];
442新增: // 判断1号是星期几
443新增: int firstDayWeekNum = (int)new DateTime(date.Year, date.Month, 1).DayOfWeek;
444新增: if (firstDayWeekNum == 0)
445新增: {
446新增: firstDayWeekNum = 7;
447新增: }
448新增:
449新增: int col = 0;
450新增: int row = 0;
451新增: if (firstDayWeekNum == 1)
452新增: {
453新增: col = date.Day - 1;
454新增: }
455新增: else
456新增: {
457新增: col = date.Day + firstDayWeekNum - 2;
458新增: }
459新增: if (col > 6)
460新增: {
461新增: row = (int)col / 7;
462新增:
463新增: int dayWeekNum = (int)new DateTime(date.Year, date.Month, date.Day).DayOfWeek;
464新增: if (dayWeekNum == 0)
465新增: {
466新增: dayWeekNum = 7;
467新增: }
468新增: col = dayWeekNum - 1;
469新增:
470新增:
471新增: }
472新增:
473新增: res[0] = col;
474新增: res[1] = row;
475新增: return res;
476新增: }
477新增: #endregion
478新增:
479新增:
480新增: private void HandleItemClick(UIElement el, ChartsDataModel data)
481新增: {
482新增: el.MouseLeftButtonUp += (s, e) =>
483新增: {
484新增: OnItemClick?.Invoke(data, null);
485新增: ClickCommand?.Execute(data);
486新增: };
487新增: }
488新增: }
489新增:}
新增UI/Controls/Charts/ChartsItemTypeA.cs+121 −0看文件
@@ -0,0 +1,121 @@
1新增:using Core.Librarys.Image;
2新增:using System;
3新增:using System.Collections.Generic;
4新增:using System.Diagnostics;
5新增:using System.Linq;
6新增:using System.Text;
7新增:using System.Threading.Tasks;
8新增:using System.Windows;
9新增:using System.Windows.Controls;
10新增:using System.Windows.Data;
11新增:using System.Windows.Documents;
12新增:using System.Windows.Input;
13新增:using System.Windows.Media;
14新增:using System.Windows.Media.Imaging;
15新增:using System.Windows.Navigation;
16新增:using System.Windows.Shapes;
17新增:using UI.Controls.Charts.Model;
18新增:
19新增:namespace UI.Controls.Charts
20新增:{
21新增: public class ChartsItemTypeA : Control
22新增: {
23新增: #region ChartsType 样式类型
24新增: /// <summary>
25新增: /// 样式类型
26新增: /// </summary>
27新增: public ChartsDataModel Data
28新增: {
29新增: get { return (ChartsDataModel)GetValue(DataProperty); }
30新增: set { SetValue(DataProperty, value); }
31新增: }
32新增: public static readonly DependencyProperty DataProperty =
33新增: DependencyProperty.Register("Data",
34新增: typeof(ChartsDataModel),
35新增: typeof(ChartsItemTypeA));
36新增:
37新增:
38新增: #endregion
39新增:
40新增: #region MaxValue 最大值
41新增: /// <summary>
42新增: /// 样式类型
43新增: /// </summary>
44新增: public double MaxValue
45新增: {
46新增: get { return (double)GetValue(MaxValueProperty); }
47新增: set { SetValue(MaxValueProperty, value); }
48新增: }
49新增: public static readonly DependencyProperty MaxValueProperty =
50新增: DependencyProperty.Register("MaxValue",
51新增: typeof(double),
52新增: typeof(ChartsItemTypeA));
53新增:
54新增:
55新增: #endregion
56新增:
57新增: #region IsLoading 是否正在加载中
58新增: /// <summary>
59新增: /// 是否正在加载中
60新增: /// </summary>
61新增: public bool IsLoading
62新增: {
63新增: get { return (bool)GetValue(IsLoadingProperty); }
64新增: set { SetValue(IsLoadingProperty, value); }
65新增: }
66新增: public static readonly DependencyProperty IsLoadingProperty =
67新增: DependencyProperty.Register("IsLoading",
68新增: typeof(bool),
69新增: typeof(ChartsItemTypeA));
70新增:
71新增:
72新增: #endregion
73新增: private TextBlock NameTextObj, ValueTextObj;
74新增: private Rectangle ValueBlockObj;
75新增: private StackPanel ValueContainer;
76新增: private Image IconObj;
77新增: private bool isRendering = false;
78新增: public ChartsItemTypeA()
79新增: {
80新增: DefaultStyleKey = typeof(ChartsItemTypeA);
81新增: }
82新增: public override void OnApplyTemplate()
83新增: {
84新增: base.OnApplyTemplate();
85新增: NameTextObj = GetTemplateChild("NameTextObj") as TextBlock;
86新增: ValueTextObj = GetTemplateChild("ValueTextObj") as TextBlock;
87新增: ValueBlockObj = GetTemplateChild("ValueBlockObj") as Rectangle;
88新增: ValueContainer = GetTemplateChild("ValueContainer") as StackPanel;
89新增:
90新增: IconObj = GetTemplateChild("IconObj") as Image;
91新增:
92新增: Loaded += ChartsItemTypeA_Loaded;
93新增: }
94新增:
95新增: private void ChartsItemTypeA_Loaded(object sender, RoutedEventArgs e)
96新增: {
97新增: Render();
98新增: }
99新增:
100新增: private void Render()
101新增: {
102新增: if (isRendering || Data==null)
103新增: {
104新增: return;
105新增: }
106新增: isRendering = true;
107新增: NameTextObj.Text = Data.Name;
108新增: ValueTextObj.Text = Data.Tag;
109新增: IconObj.Source = Imager.Load(Data.Icon);
110新增:
111新增: ValueTextObj.SizeChanged += (e, c) =>
112新增: {
113新增: if (MaxValue <= 0)
114新增: {
115新增: return;
116新增: }
117新增: ValueBlockObj.Width = (Data.Value / MaxValue) * (ValueContainer.ActualWidth * 0.95 - ValueTextObj.ActualWidth);
118新增: };
119新增: }
120新增: }
121新增:}
新增UI/Controls/Charts/ChartsItemTypeCard.cs+129 −0看文件
@@ -0,0 +1,129 @@
1新增:using Core.Librarys.Image;
2新增:using System;
3新增:using System.Collections.Generic;
4新增:using System.Diagnostics;
5新增:using System.Linq;
6新增:using System.Text;
7新增:using System.Threading.Tasks;
8新增:using System.Windows;
9新增:using System.Windows.Controls;
10新增:using System.Windows.Data;
11新增:using System.Windows.Documents;
12新增:using System.Windows.Input;
13新增:using System.Windows.Media;
14新增:using System.Windows.Media.Imaging;
15新增:using System.Windows.Navigation;
16新增:using System.Windows.Shapes;
17新增:using UI.Controls.Charts.Model;
18新增:
19新增:namespace UI.Controls.Charts
20新增:{
21新增: public class ChartsItemTypeCard : Control
22新增: {
23新增: #region ChartsType 样式类型
24新增: /// <summary>
25新增: /// 样式类型
26新增: /// </summary>
27新增: public ChartsDataModel Data
28新增: {
29新增: get { return (ChartsDataModel)GetValue(DataProperty); }
30新增: set { SetValue(DataProperty, value); }
31新增: }
32新增: public static readonly DependencyProperty DataProperty =
33新增: DependencyProperty.Register("Data",
34新增: typeof(ChartsDataModel),
35新增: typeof(ChartsItemTypeCard));
36新增:
37新增:
38新增: #endregion
39新增:
40新增: #region MaxValue 最大值
41新增: /// <summary>
42新增: /// 样式类型
43新增: /// </summary>
44新增: public double MaxValue
45新增: {
46新增: get { return (double)GetValue(MaxValueProperty); }
47新增: set { SetValue(MaxValueProperty, value); }
48新增: }
49新增: public static readonly DependencyProperty MaxValueProperty =
50新增: DependencyProperty.Register("MaxValue",
51新增: typeof(double),
52新增: typeof(ChartsItemTypeCard));
53新增:
54新增:
55新增: #endregion
56新增:
57新增: #region IsLoading 是否正在加载中
58新增: /// <summary>
59新增: /// 是否正在加载中
60新增: /// </summary>
61新增: public bool IsLoading
62新增: {
63新增: get { return (bool)GetValue(IsLoadingProperty); }
64新增: set { SetValue(IsLoadingProperty, value); }
65新增: }
66新增: public static readonly DependencyProperty IsLoadingProperty =
67新增: DependencyProperty.Register("IsLoading",
68新增: typeof(bool),
69新增: typeof(ChartsItemTypeCard));
70新增:
71新增:
72新增: #endregion
73新增: private TextBlock NameTextObj, ValueTextObj;
74新增: private Rectangle ValueBlockObj;
75新增: private StackPanel ValueContainer;
76新增: private Image IconObj;
77新增: private bool isRendering = false;
78新增: public ChartsItemTypeCard()
79新增: {
80新增: DefaultStyleKey = typeof(ChartsItemTypeCard);
81新增: }
82新增: public override void OnApplyTemplate()
83新增: {
84新增: base.OnApplyTemplate();
85新增: NameTextObj = GetTemplateChild("NameTextObj") as TextBlock;
86新增: ValueTextObj = GetTemplateChild("ValueTextObj") as TextBlock;
87新增: ValueBlockObj = GetTemplateChild("ValueBlockObj") as Rectangle;
88新增: ValueContainer = GetTemplateChild("ValueContainer") as StackPanel;
89新增:
90新增: IconObj = GetTemplateChild("IconObj") as Image;
91新增:
92新增: Loaded += ChartsItemTypeCard_Loaded;
93新增: }
94新增:
95新增: private void ChartsItemTypeCard_Loaded(object sender, RoutedEventArgs e)
96新增: {
97新增: Render();
98新增: }
99新增:
100新增: private void Render()
101新增: {
102新增: if (isRendering || Data == null)
103新增: {
104新增: return;
105新增: }
106新增: isRendering = true;
107新增: NameTextObj.Text = Data.Name;
108新增: NameTextObj.SizeChanged += (e, c) =>
109新增: {
110新增: // 处理文字过长显示
111新增: if (NameTextObj.ActualWidth > 121 && NameTextObj.FontSize > 8)
112新增: {
113新增: NameTextObj.FontSize = NameTextObj.FontSize - 1;
114新增: }
115新增: };
116新增: ValueTextObj.Text = Data.Tag;
117新增: IconObj.Source = Imager.Load(Data.Icon);
118新增:
119新增: ValueTextObj.SizeChanged += (e, c) =>
120新增: {
121新增: //if (MaxValue <= 0)
122新增: //{
123新增: // return;
124新增: //}
125新增: ValueBlockObj.Width = ValueBlockObj.Height = (Data.Value / MaxValue) * ActualWidth;
126新增: };
127新增: }
128新增: }
129新增:}
新增UI/Controls/Charts/ChartsItemTypeMonth.cs+158 −0看文件
@@ -0,0 +1,158 @@
1新增:using Core.Librarys.Image;
2新增:using System;
3新增:using System.Collections.Generic;
4新增:using System.Diagnostics;
5新增:using System.Linq;
6新增:using System.Text;
7新增:using System.Threading.Tasks;
8新增:using System.Windows;
9新增:using System.Windows.Controls;
10新增:using System.Windows.Data;
11新增:using System.Windows.Documents;
12新增:using System.Windows.Input;
13新增:using System.Windows.Media;
14新增:using System.Windows.Media.Imaging;
15新增:using System.Windows.Navigation;
16新增:using System.Windows.Shapes;
17新增:using UI.Controls.Charts.Model;
18新增:
19新增:namespace UI.Controls.Charts
20新增:{
21新增: public class ChartsItemTypeMonth : Control
22新增: {
23新增: #region Data 数据
24新增: /// <summary>
25新增: /// 数据
26新增: /// </summary>
27新增: public ChartsDataModel Data
28新增: {
29新增: get { return (ChartsDataModel)GetValue(DataProperty); }
30新增: set { SetValue(DataProperty, value); }
31新增: }
32新增: public static readonly DependencyProperty DataProperty =
33新增: DependencyProperty.Register("Data",
34新增: typeof(ChartsDataModel),
35新增: typeof(ChartsItemTypeMonth));
36新增:
37新增:
38新增: #endregion
39新增:
40新增: #region MaxValue 最大值
41新增: /// <summary>
42新增: /// 样式类型
43新增: /// </summary>
44新增: public double MaxValue
45新增: {
46新增: get { return (double)GetValue(MaxValueProperty); }
47新增: set { SetValue(MaxValueProperty, value); }
48新增: }
49新增: public static readonly DependencyProperty MaxValueProperty =
50新增: DependencyProperty.Register("MaxValue",
51新增: typeof(double),
52新增: typeof(ChartsItemTypeMonth));
53新增:
54新增:
55新增: #endregion
56新增:
57新增: #region IsLoading 是否正在加载中
58新增: /// <summary>
59新增: /// 是否正在加载中
60新增: /// </summary>
61新增: public bool IsLoading
62新增: {
63新增: get { return (bool)GetValue(IsLoadingProperty); }
64新增: set { SetValue(IsLoadingProperty, value); }
65新增: }
66新增: public static readonly DependencyProperty IsLoadingProperty =
67新增: DependencyProperty.Register("IsLoading",
68新增: typeof(bool),
69新增: typeof(ChartsItemTypeMonth));
70新增:
71新增:
72新增: #endregion
73新增: #region IsSelected 是否选中
74新增: /// <summary>
75新增: /// 是否选中
76新增: /// </summary>
77新增: public bool IsSelected
78新增: {
79新增: get { return (bool)GetValue(IsSelectedProperty); }
80新增: set { SetValue(IsSelectedProperty, value); }
81新增: }
82新增: public static readonly DependencyProperty IsSelectedProperty =
83新增: DependencyProperty.Register("IsSelected",
84新增: typeof(bool),
85新增: typeof(ChartsItemTypeMonth));
86新增:
87新增:
88新增: #endregion
89新增: private TextBlock NameTextObj, ValueTextObj;
90新增: private Rectangle ValueBlockObj;
91新增: private StackPanel ValueContainer;
92新增: private Image IconObj;
93新增: private bool isRendering = false;
94新增: public ChartsItemTypeMonth()
95新增: {
96新增: DefaultStyleKey = typeof(ChartsItemTypeMonth);
97新增: }
98新增: public override void OnApplyTemplate()
99新增: {
100新增: base.OnApplyTemplate();
101新增: NameTextObj = GetTemplateChild("NameTextObj") as TextBlock;
102新增: ValueTextObj = GetTemplateChild("ValueTextObj") as TextBlock;
103新增: ValueBlockObj = GetTemplateChild("ValueBlockObj") as Rectangle;
104新增: ValueContainer = GetTemplateChild("ValueContainer") as StackPanel;
105新增:
106新增: IconObj = GetTemplateChild("IconObj") as Image;
107新增:
108新增: Loaded += ChartsItemTypeMonth_Loaded;
109新增: }
110新增:
111新增: private void ChartsItemTypeMonth_Loaded(object sender, RoutedEventArgs e)
112新增: {
113新增: Render();
114新增: }
115新增:
116新增: private void Render()
117新增: {
118新增: if (isRendering || Data == null)
119新增: {
120新增: return;
121新增: }
122新增: isRendering = true;
123新增: //Loaded += (s, e) =>
124新增: //{
125新增: // ValueBlockObj.Width = ValueBlockObj.Height = (Data.Value / MaxValue) * ActualWidth;
126新增: //};
127新增: ValueBlockObj.Width = ValueBlockObj.Height = (Data.Value / MaxValue) * ActualWidth;
128新增: ToolTip = Data.DateTime.ToString("yyyy年MM月dd日") + " " + (string.IsNullOrEmpty(Data.Tag) ? "无数据" : Data.Tag);
129新增:
130新增: if (Data.DateTime.Date == DateTime.Now.Date)
131新增: {
132新增: IsSelected = true;
133新增: ToolTip = "[今日] " + ToolTip;
134新增: }
135新增: //ValueTextObj.Text = Data.DateTime.Day.ToString();
136新增: //NameTextObj.Text = Data.Name;
137新增: //NameTextObj.SizeChanged += (e, c) =>
138新增: //{
139新增: // // 处理文字过长显示
140新增: // if (NameTextObj.ActualWidth > 121 && NameTextObj.FontSize > 8)
141新增: // {
142新增: // NameTextObj.FontSize = NameTextObj.FontSize - 1;
143新增: // }
144新增: //};
145新增: //ValueTextObj.Text = Data.Tag;
146新增: //IconObj.Source = Imager.Load(Data.Icon);
147新增:
148新增: //ValueTextObj.SizeChanged += (e, c) =>
149新增: //{
150新增: // //if (MaxValue <= 0)
151新增: // //{
152新增: // // return;
153新增: // //}
154新增: // ValueBlockObj.Width = ValueBlockObj.Height = (Data.Value / MaxValue) * ActualWidth;
155新增: //};
156新增: }
157新增: }
158新增:}
新增UI/Controls/Charts/ChartsType.cs+27 −0看文件
@@ -0,0 +1,27 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace UI.Controls.Charts
8新增:{
9新增: /// <summary>
10新增: /// 图表样式类型
11新增: /// </summary>
12新增: public enum ChartsType
13新增: {
14新增: /// <summary>
15新增: /// 横向A样式
16新增: /// </summary>
17新增: HorizontalA = 1,
18新增: /// <summary>
19新增: /// 卡片
20新增: /// </summary>
21新增: Card = 2,
22新增: /// <summary>
23新增: /// 月份
24新增: /// </summary>
25新增: Month = 3
26新增: }
27新增:}
新增UI/Controls/Charts/Model/ChartsDataModel.cs+42 −0看文件
@@ -0,0 +1,42 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace UI.Controls.Charts.Model
8新增:{
9新增: public class ChartsDataModel
10新增: {
11新增: /// <summary>
12新增: /// 名称
13新增: /// </summary>
14新增: public string Name { get; set; }
15新增:
16新增: /// <summary>
17新增: /// 值
18新增: /// </summary>
19新增: public double Value { get; set; }
20新增: /// <summary>
21新增: /// 列名
22新增: /// </summary>
23新增: public string Tag { get; set; }
24新增: /// <summary>
25新增: /// 悬浮文本
26新增: /// </summary>
27新增: public string PopupText { get; set; }
28新增: /// <summary>
29新增: /// 是否选中
30新增: /// </summary>
31新增: public bool IsSelected { get; set; }
32新增: /// <summary>
33新增: /// 图标文件
34新增: /// </summary>
35新增: public string Icon { get; set; }
36新增:
37新增: /// <summary>
38新增: /// 时间(仅在类型为Month样式时有效)
39新增: /// </summary>
40新增: public DateTime DateTime { get; set; }
41新增: }
42新增:}
新增UI/Controls/DatePickerBar/DatePickerBar.cs+285 −0看文件
@@ -0,0 +1,285 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Collections.ObjectModel;
4新增:using System.Collections.Specialized;
5新增:using System.Diagnostics;
6新增:using System.Linq;
7新增:using System.Text;
8新增:using System.Windows;
9新增:using System.Windows.Controls;
10新增:using System.Windows.Input;
11新增:using System.Windows.Media;
12新增:using System.Windows.Media.Animation;
13新增:using UI.Controls.Navigation.Models;
14新增:
15新增:namespace UI.Controls.DatePickerBar
16新增:{
17新增: public class DatePickerBar : Control
18新增: {
19新增: public DatePickerShowType ShowType
20新增: {
21新增: get { return (DatePickerShowType)GetValue(ShowTypeProperty); }
22新增: set { SetValue(ShowTypeProperty, value); }
23新增: }
24新增: public static readonly DependencyProperty ShowTypeProperty =
25新增: DependencyProperty.Register("ShowType", typeof(DatePickerShowType), typeof(DatePickerBar), new PropertyMetadata(DatePickerShowType.Day));
26新增:
27新增:
28新增: public DateTime SelectedDate
29新增: {
30新增: get { return (DateTime)GetValue(SelectedDateProperty); }
31新增: set { SetValue(SelectedDateProperty, value); }
32新增: }
33新增: public static readonly DependencyProperty SelectedDateProperty =
34新增: DependencyProperty.Register("SelectedDate", typeof(DateTime), typeof(DatePickerBar), new PropertyMetadata(new PropertyChangedCallback(OnSelectedItemChanged)));
35新增:
36新增: private static void OnSelectedItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
37新增: {
38新增: var control = d as DatePickerBar;
39新增: if (e.NewValue != e.OldValue)
40新增: {
41新增: control.ScrollToActive(DateTime.Parse(e.NewValue.ToString()));
42新增: }
43新增: }
44新增:
45新增:
46新增: public string SelectedDateString
47新增: {
48新增: get { return (string)GetValue(SelectedDateStringProperty); }
49新增: set { SetValue(SelectedDateStringProperty, value); }
50新增: }
51新增: public static readonly DependencyProperty SelectedDateStringProperty =
52新增: DependencyProperty.Register("SelectedDateString", typeof(string), typeof(DatePickerBar));
53新增:
54新增: private StackPanel Container;
55新增: private ScrollViewer ScrollViewer;
56新增: private Dictionary<DateTime, DatePickerBarItem> ItemsDictionary;
57新增: private List<DateTime> DateList;
58新增:
59新增: // 选中标记块
60新增: private Border ActiveBlock;
61新增: // 动画
62新增: Storyboard storyboard;
63新增: public DatePickerBar()
64新增: {
65新增: DefaultStyleKey = typeof(DatePickerBar);
66新增: ItemsDictionary = new Dictionary<DateTime, DatePickerBarItem>();
67新增: DateList = new List<DateTime>();
68新增: storyboard = new Storyboard();
69新增: }
70新增:
71新增:
72新增:
73新增: public override void OnApplyTemplate()
74新增: {
75新增: base.OnApplyTemplate();
76新增: Container = GetTemplateChild("Container") as StackPanel;
77新增: ActiveBlock = GetTemplateChild("ActiveBlock") as Border;
78新增: ScrollViewer = GetTemplateChild("ScrollViewer") as ScrollViewer;
79新增: Render();
80新增: }
81新增:
82新增:
83新增: private void AddItem(DateTime date)
84新增: {
85新增: if (Container != null)
86新增: {
87新增: if (DateList.IndexOf(date) != -1)
88新增: {
89新增: return;
90新增: }
91新增:
92新增: var control = new DatePickerBarItem();
93新增: control.Title = date.Day.ToString();
94新增: control.Date = date;
95新增: control.MouseUp += (e, c) =>
96新增: {
97新增: if (date > DateTime.Now.Date)
98新增: {
99新增: return;
100新增: }
101新增: ScrollToActive(date);
102新增: };
103新增: control.Loaded += (e, c) =>
104新增: {
105新增: if (date == DateTime.Now.Date)
106新增: {
107新增: SelectedDate = DateTime.Now.Date;
108新增: }
109新增: };
110新增:
111新增: // 后一天
112新增: int next = DateList.IndexOf(date.AddDays(+1));
113新增:
114新增: if (next != -1)
115新增: {
116新增: int index = next - 1;
117新增: if (index < 0)
118新增: {
119新增: index = 0;
120新增: }
121新增: DateList.Insert(index, date);
122新增: ItemsDictionary.Add(date, control);
123新增: Container.Children.Insert(index, control);
124新增: }
125新增: else
126新增: {
127新增: DateList.Add(date);
128新增: ItemsDictionary.Add(date, control);
129新增: Container.Children.Add(control);
130新增: }
131新增: //if (Data.IndexOf(item) == Data.Count - 1)
132新增: //{
133新增: // control.Loaded += (e, c) =>
134新增: // {
135新增: // ScrollToActive();
136新增: // };
137新增: //}
138新增: //Container.Children.Add(control);
139新增: //ItemsDictionary.Add(control);
140新增: }
141新增: }
142新增:
143新增:
144新增:
145新增: private void Render()
146新增: {
147新增: if (ShowType == DatePickerShowType.Day)
148新增: {
149新增: // 前30天
150新增: for (int i = 1; i < 30; i++)
151新增: {
152新增: AddItem(DateTime.Now.Date.AddDays(-i));
153新增: }
154新增:
155新增: AddItem(DateTime.Now.Date);
156新增:
157新增: // 后十天
158新增: for (int i = 1; i < 10; i++)
159新增: {
160新增: AddItem(DateTime.Now.Date.AddDays(+i));
161新增: }
162新增:
163新增: }
164新增:
165新增: if (ShowType == DatePickerShowType.Month)
166新增: {
167新增: var nowDate = DateTime.Now;
168新增: for (int i = 1; i < 13; i++)
169新增: {
170新增: var date = new DateTime(nowDate.Year, i, 1);
171新增: AddMonthItem(date);
172新增: }
173新增: }
174新增:
175新增:
176新增:
177新增: }
178新增:
179新增: private void AddMonthItem(DateTime date)
180新增: {
181新增:
182新增: if (Container != null)
183新增: {
184新增: if (DateList.IndexOf(date) != -1)
185新增: {
186新增: return;
187新增: }
188新增:
189新增: var control = new DatePickerBarItem();
190新增: control.Title = date.Month.ToString();
191新增: control.Date = date;
192新增: control.MouseUp += (e, c) =>
193新增: {
194新增: if (date > DateTime.Now.Date)
195新增: {
196新增: return;
197新增: }
198新增: ScrollToActive(date);
199新增: };
200新增: control.Loaded += (e, c) =>
201新增: {
202新增: if (date.Year == DateTime.Now.Date.Year
203新增: && date.Month == DateTime.Now.Date.Month)
204新增: {
205新增: SelectedDate = date;
206新增: }
207新增: };
208新增:
209新增:
210新增: DateList.Add(date);
211新增: ItemsDictionary.Add(date, control);
212新增: Container.Children.Add(control);
213新增:
214新增: }
215新增: }
216新增:
217新增: private void ScrollToActive(DateTime date)
218新增: {
219新增: if (ItemsDictionary.ContainsKey(SelectedDate))
220新增: {
221新增: ItemsDictionary[SelectedDate].IsSelected = false;
222新增: }
223新增: else
224新增: {
225新增: return;
226新增: }
227新增: SelectedDate = date;
228新增: ItemsDictionary[date].IsSelected = true;
229新增:
230新增:
231新增: SelectedDateString = SelectedDate.ToString("yyyy/MM");
232新增: if (ShowType == DatePickerShowType.Month)
233新增: {
234新增: SelectedDateString = SelectedDate.ToString("yyyy");
235新增: }
236新增: var control = ItemsDictionary[SelectedDate];
237新增:
238新增: Point relativePoint = control.TransformToAncestor(Container).Transform(new Point(0, 0));
239新增:
240新增: double scrollTo = relativePoint.X - (ScrollViewer.ActualWidth / 2) + control.ActualWidth / 2;
241新增: if (scrollTo < 0)
242新增: {
243新增: scrollTo = 0;
244新增: }
245新增:
246新增: ScrollViewer.ScrollToHorizontalOffset(scrollTo);
247新增:
248新增:
249新增: //if (oldSelectedIndex > ItemsDictionary.Count || ItemsDictionary.Count == 0)
250新增: //{
251新增: // return;
252新增: //}
253新增: // 获取选中项
254新增:
255新增: //var item = ItemsDictionary[SelectedIndex];
256新增: //var oldSelectedItem = ItemsDictionary[oldSelectedIndex];
257新增:
258新增:
259新增: // 选中项的坐标
260新增: //Point relativePoint = item.TransformToAncestor(this).Transform(new Point(0, 0));
261新增:
262新增: // 创建动画
263新增:
264新增:
265新增:
266新增: //storyboard.Children.Clear();
267新增: //DoubleAnimation scrollAnimation = new DoubleAnimation();
268新增: //double scrollX = relativePoint.X - 10;
269新增: //scrollX = scrollX < 0 ? 0 : scrollX;
270新增: //scrollAnimation.To = scrollX;
271新增:
272新增: //scrollAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
273新增: //Storyboard.SetTarget(scrollAnimation, ActiveBlock);
274新增: //Storyboard.SetTargetProperty(scrollAnimation, new PropertyPath("RenderTransform.Children[0].X"));
275新增:
276新增: //scrollAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.15));
277新增:
278新增:
279新增: //storyboard.Children.Add(scrollAnimation);
280新增:
281新增:
282新增: //storyboard.Begin();
283新增: }
284新增: }
285新增:}
新增UI/Controls/DatePickerBar/DatePickerBarItem.cs+58 −0看文件
@@ -0,0 +1,58 @@
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 UI.Controls.DatePickerBar
10新增:{
11新增: public class DatePickerBarItem : Control
12新增: {
13新增: public string Title
14新增: {
15新增: get { return (string)GetValue(TitleProperty); }
16新增: set { SetValue(TitleProperty, value); }
17新增: }
18新增: public static readonly DependencyProperty TitleProperty =
19新增: DependencyProperty.Register("Title", typeof(string), typeof(DatePickerBarItem));
20新增:
21新增:
22新增: public bool IsSelected
23新增: {
24新增: get { return (bool)GetValue(IsSelectedProperty); }
25新增: set { SetValue(IsSelectedProperty, value); }
26新增: }
27新增: public static readonly DependencyProperty IsSelectedProperty =
28新增: DependencyProperty.Register("IsSelected", typeof(bool), typeof(DatePickerBarItem));
29新增: public bool IsDisabled
30新增: {
31新增: get { return (bool)GetValue(IsDisabledProperty); }
32新增: set { SetValue(IsDisabledProperty, value); }
33新增: }
34新增: public static readonly DependencyProperty IsDisabledProperty =
35新增: DependencyProperty.Register("IsDisabled", typeof(bool), typeof(DatePickerBarItem));
36新增: public DateTime Date
37新增: {
38新增: get { return (DateTime)GetValue(DateProperty); }
39新增: set { SetValue(DateProperty, value); }
40新增: }
41新增: public static readonly DependencyProperty DateProperty =
42新增: DependencyProperty.Register("Date", typeof(DateTime), typeof(DatePickerBarItem), new PropertyMetadata(new PropertyChangedCallback(OnPropertyChanged)));
43新增:
44新增: private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
45新增: {
46新增: var control = d as DatePickerBarItem;
47新增: if (e.NewValue != e.OldValue)
48新增: {
49新增: control.IsDisabled = control.Date > DateTime.Now.Date;
50新增: }
51新增: }
52新增: public DatePickerBarItem()
53新增: {
54新增: DefaultStyleKey = typeof(DatePickerBarItem);
55新增:
56新增: }
57新增: }
58新增:}
新增UI/Controls/DatePickerBar/DatePickerShowType.cs+23 −0看文件
@@ -0,0 +1,23 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace UI.Controls.DatePickerBar
8新增:{
9新增: /// <summary>
10新增: /// 日期选择器显示类型
11新增: /// </summary>
12新增: public enum DatePickerShowType
13新增: {
14新增: /// <summary>
15新增: /// 日
16新增: /// </summary>
17新增: Day,
18新增: /// <summary>
19新增: /// 月
20新增: /// </summary>
21新增: Month,
22新增: }
23新增:}
新增UI/Controls/Input/InputBox.cs+23 −0看文件
@@ -0,0 +1,23 @@
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新增:using System.Windows.Controls.Primitives;
9新增:
10新增:namespace UI.Controls.Input
11新增:{
12新增: public class InputBox : TextBox
13新增: {
14新增: public string Placeholder { get { return (string)GetValue(PlaceholderProperty); } set { SetValue(PlaceholderProperty, value); } }
15新增: public static readonly DependencyProperty PlaceholderProperty = DependencyProperty.Register("Placeholder", typeof(string), typeof(InputBox));
16新增: public InputBox()
17新增: {
18新增: DefaultStyleKey = typeof(InputBox);
19新增: }
20新增:
21新增:
22新增: }
23新增:}
新增UI/Controls/List/BaseList.cs+131 −0看文件
@@ -0,0 +1,131 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Collections.ObjectModel;
4新增:using System.Diagnostics;
5新增:using System.Linq;
6新增:using System.Text;
7新增:using System.Threading.Tasks;
8新增:using System.Windows;
9新增:using System.Windows.Controls;
10新增:using System.Windows.Input;
11新增:
12新增:namespace UI.Controls.List
13新增:{
14新增: public class BaseList : Control
15新增: {
16新增: public ObservableCollection<string> Items { get { return (ObservableCollection<string>)GetValue(ItemsProperty); } set { SetValue(ItemsProperty, value); } }
17新增: public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register("Items", typeof(ObservableCollection<string>), typeof(BaseList), new PropertyMetadata(new PropertyChangedCallback(ItemsChanged)));
18新增:
19新增: private static void ItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
20新增: {
21新增: var control = d as BaseList;
22新增: if (e.NewValue != e.OldValue)
23新增: {
24新增: control.Render();
25新增: }
26新增: }
27新增:
28新增: public string SelectedItem { get { return (string)GetValue(SelectedItemProperty); } set { SetValue(SelectedItemProperty, value); } }
29新增: public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(string), typeof(BaseList));
30新增:
31新增: private StackPanel Container;
32新增:
33新增: //private Dictionary<int, BaseListItem> ItemsMap;
34新增: private List<BaseListItem> ItemsMap;
35新增:
36新增: public BaseList()
37新增: {
38新增: DefaultStyleKey = typeof(BaseList);
39新增: Items = new ObservableCollection<string>();
40新增: ItemsMap = new List<BaseListItem>();
41新增: Items.CollectionChanged += Items_CollectionChanged;
42新增: }
43新增:
44新增: private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
45新增: {
46新增: if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
47新增: {
48新增: foreach (var item in e.NewItems)
49新增: {
50新增: AddItem(item as string);
51新增: }
52新增: }
53新增:
54新增: if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
55新增: {
56新增: foreach (var item in e.OldItems)
57新增: {
58新增: RemoveItem(item as string);
59新增: }
60新增: }
61新增: }
62新增:
63新增: public override void OnApplyTemplate()
64新增: {
65新增: base.OnApplyTemplate();
66新增: Container = GetTemplateChild("Container") as StackPanel;
67新增: Render();
68新增: }
69新增:
70新增: private void Render()
71新增: {
72新增: if (Container != null)
73新增: {
74新增: Container.Children.Clear();
75新增: ItemsMap.Clear();
76新增:
77新增: if (Items == null)
78新增: {
79新增: return;
80新增: }
81新增:
82新增: foreach (var item in Items)
83新增: {
84新增: AddItem(item);
85新增: }
86新增: }
87新增: }
88新增:
89新增: private void AddItem(string item)
90新增: {
91新增: if (Container == null)
92新增: {
93新增: return;
94新增: }
95新增: var itemControl = new BaseListItem();
96新增: itemControl.Text = item;
97新增: itemControl.MouseLeftButtonUp += ItemClick;
98新增: itemControl.MouseRightButtonUp += ItemClick;
99新增: ItemsMap.Add(itemControl);
100新增: Container.Children.Add(itemControl);
101新增: }
102新增:
103新增: private void RemoveItem(string item)
104新增: {
105新增: if (Container == null)
106新增: {
107新增: return;
108新增: }
109新增: var control = ItemsMap.Where(m => m.Text == item).FirstOrDefault();
110新增: if (control != null)
111新增: {
112新增: Container.Children.Remove(control);
113新增: }
114新增: }
115新增:
116新增: private void ItemClick(object sender, MouseButtonEventArgs e)
117新增: {
118新增: ClearSelectedItems();
119新增: (sender as BaseListItem).IsSelected = true;
120新增: SelectedItem = (sender as BaseListItem).Text;
121新增: }
122新增:
123新增: private void ClearSelectedItems()
124新增: {
125新增: foreach (var item in ItemsMap)
126新增: {
127新增: item.IsSelected = false;
128新增: }
129新增: }
130新增: }
131新增:}
新增UI/Controls/List/BaseListItem.cs+40 −0看文件
@@ -0,0 +1,40 @@
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新增:using System.Windows.Input;
9新增:
10新增:namespace UI.Controls.List
11新增:{
12新增: public class BaseListItem : Control
13新增: {
14新增: public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } }
15新增: public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(BaseListItem));
16新增:
17新增: public bool IsSelected { get { return (bool)GetValue(IsSelectedProperty); } set { SetValue(IsSelectedProperty, value); } }
18新增: public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(BaseListItem));
19新增:
20新增: //public Command RemoveCommand { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } }
21新增: //public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(BaseListItem));
22新增:
23新增: //public event EventHandler ItemChanged;
24新增:
25新增: public BaseListItem()
26新增: {
27新增: DefaultStyleKey = typeof(BaseListItem);
28新增: }
29新增: protected override void OnMouseEnter(MouseEventArgs e)
30新增: {
31新增: base.OnMouseEnter(e);
32新增: VisualStateManager.GoToState(this, "MouseOver", true);
33新增: }
34新增: protected override void OnMouseLeave(MouseEventArgs e)
35新增: {
36新增: base.OnMouseLeave(e);
37新增: VisualStateManager.GoToState(this, "Normal", true);
38新增: }
39新增: }
40新增:}
修改UI/Controls/Navigation/Navigation.cs+6 −1看文件
@@ -312,9 +312,14 @@ namespace UI.Controls.Navigation
312312 if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
313313 {
314314 //左键选中
315新增:
315316 SelectedItem = Data.Where(m => m.ID == navitem.ID).FirstOrDefault();
316317 OnSelected?.Invoke(this, null);
317删除: ScrollToActive();
318新增:
319新增: if (SelectedItem != null && SelectedItem.ID != navitem.ID)
320新增: {
321新增: ScrollToActive();
322新增: }
318323 }
319324 if (e.ChangedButton == System.Windows.Input.MouseButton.Right)
320325 {
新增UI/Controls/SettingPanel/SettingPanel.cs+326 −0看文件
@@ -0,0 +1,326 @@
1新增:using Core.Models.Config;
2新增:using System;
3新增:using System.Collections;
4新增:using System.Collections.Generic;
5新增:using System.Collections.ObjectModel;
6新增:using System.Diagnostics;
7新增:using System.Linq;
8新增:using System.Reflection;
9新增:using System.Text;
10新增:using System.Threading.Tasks;
11新增:using System.Windows;
12新增:using System.Windows.Controls;
13新增:using System.Windows.Media;
14新增:
15新增:namespace UI.Controls.SettingPanel
16新增:{
17新增:
18新增: public class SettingPanel : Control
19新增: {
20新增: public struct Config
21新增: {
22新增: public ConfigAttribute Attribute { get; set; }
23新增: public PropertyInfo PropertyInfo { get; set; }
24新增: }
25新增: public object Data { get { return (object)GetValue(DataProperty); } set { SetValue(DataProperty, value); } }
26新增: public static readonly DependencyProperty DataProperty = DependencyProperty.Register("Data", typeof(object), typeof(SettingPanel), new PropertyMetadata(new PropertyChangedCallback(OnDataChanged)));
27新增:
28新增: private static void OnDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
29新增: {
30新增: var control = d as SettingPanel;
31新增: if (e.NewValue != e.OldValue)
32新增: {
33新增: control.Render();
34新增: }
35新增: }
36新增:
37新增:
38新增: private StackPanel Container;
39新增: private object configData;
40新增: private readonly string nosetGroupKey = "noset_group";
41新增: private Dictionary<string, List<Config>> configList;
42新增: public SettingPanel()
43新增: {
44新增: DefaultStyleKey = typeof(SettingPanel);
45新增: }
46新增: public override void OnApplyTemplate()
47新增: {
48新增: base.OnApplyTemplate();
49新增:
50新增: Container = GetTemplateChild("Container") as StackPanel;
51新增:
52新增: Render();
53新增: }
54新增: private void Render()
55新增: {
56新增: configList = new Dictionary<string, List<Config>>();
57新增: configList.Add(nosetGroupKey, new List<Config>());
58新增:
59新增: if (Container == null)
60新增: {
61新增: return;
62新增: }
63新增:
64新增: Container.Children.Clear();
65新增:
66新增: if (Data == null)
67新增: {
68新增: return;
69新增: }
70新增:
71新增:
72新增:
73新增: if (Data is IEnumerable)
74新增: {
75新增: // 多例
76新增: RenderMultiPanel();
77新增: }
78新增: else
79新增: {
80新增: // 单例
81新增: RenderSinglePanel();
82新增: }
83新增:
84新增:
85新增: }
86新增:
87新增:
88新增: #region 渲染多例面板
89新增: /// <summary>
90新增: /// 渲染多例面板
91新增: /// </summary>
92新增:
93新增: private void RenderMultiPanel()
94新增: {
95新增: var dataList = Data as IEnumerable<object>;
96新增: var list = dataList.ToList();
97新增: var cacheList = new Dictionary<int, object>();
98新增:
99新增: var dataType = Data.GetType();
100新增: var itemType = dataType.GenericTypeArguments[0];
101新增: var test1 = dataType.GetGenericArguments()[0];
102新增:
103新增: var emptyData = Activator.CreateInstance(itemType);
104新增:
105新增: // 添加按钮
106新增: var addBtn = new Button.Button();
107新增: addBtn.Content = "新建项";
108新增: addBtn.Width = 150;
109新增: addBtn.Icon = Base.IconTypes.CalculatorAddition;
110新增: addBtn.Click += (s, e) =>
111新增: {
112新增: int id = cacheList.Keys.Count > 0 ? cacheList.Keys.Max() + 1 : 1;
113新增:
114新增: cacheList.Add(id, emptyData);
115新增:
116新增: var panel = CreateMultiPanel(emptyData, id, cacheList);
117新增:
118新增: Container.Children.Insert(Container.Children.Count - 1, panel);
119新增:
120新增: };
121新增: Container.Children.Add(addBtn);
122新增:
123新增:
124新增: // 渲染数据
125新增: for (int i = 0; i < list.Count; i++)
126新增: {
127新增: int id = cacheList.Keys.Count > 0 ? cacheList.Keys.Max() + 1 : 1;
128新增:
129新增: cacheList.Add(id, list[i]);
130新增: var panel = CreateMultiPanel(list[i], id, cacheList);
131新增: Container.Children.Insert(Container.Children.Count - 1, panel);
132新增: }
133新增:
134新增:
135新增:
136新增: }
137新增:
138新增:
139新增: private SettingPanelMultiItem CreateMultiPanel(object data, int id, Dictionary<int, object> cacheList)
140新增: {
141新增: var panel = new SettingPanelMultiItem();
142新增: panel.Data = data;
143新增: panel.Tag = id;
144新增: panel.DataChanged += (e, c) =>
145新增: {
146新增: int pid = (int)panel.Tag;
147新增:
148新增: if (cacheList.ContainsKey(pid))
149新增: {
150新增: // 更新
151新增: cacheList[pid] = panel.Data;
152新增:
153新增: var listType = typeof(List<>);
154新增: var constructedListType = listType.MakeGenericType(panel.Data.GetType());
155新增:
156新增: var newList = (IList)Activator.CreateInstance(constructedListType);
157新增:
158新增: foreach (var item in cacheList.Values)
159新增: {
160新增: newList.Add(item);
161新增: }
162新增: Data = newList;
163新增: }
164新增: };
165新增: panel.OnRemoveAction = new Command(new Action<object>((s) =>
166新增: {
167新增: cacheList.Remove(id);
168新增: var listType = typeof(List<>);
169新增: var constructedListType = listType.MakeGenericType(panel.Data.GetType());
170新增:
171新增: var newList = (IList)Activator.CreateInstance(constructedListType);
172新增: foreach (var item in cacheList.Values)
173新增: {
174新增: newList.Add(item);
175新增: }
176新增: Data = newList;
177新增: }));
178新增: return panel;
179新增: }
180新增: #endregion
181新增:
182新增: /// <summary>
183新增: /// 渲染单例面板
184新增: /// </summary>
185新增: private void RenderSinglePanel()
186新增: {
187新增: configData = Activator.CreateInstance(Data.GetType());
188新增:
189新增: // 遍历方法特性
190新增: foreach (PropertyInfo pi in Data.GetType().GetProperties())
191新增: {
192新增: foreach (Attribute attr in pi.GetCustomAttributes(true))
193新增: {
194新增: if (attr is ConfigAttribute)
195新增: {
196新增: ConfigAttribute attribute = (ConfigAttribute)attr;
197新增:
198新增: var config = new Config()
199新增: {
200新增: Attribute = attribute,
201新增: PropertyInfo = pi
202新增: };
203新增: if (string.IsNullOrEmpty(attribute.Group))
204新增: {
205新增: // 未分组
206新增: configList[nosetGroupKey].Add(config);
207新增: }
208新增: else
209新增: {
210新增: if (!configList.ContainsKey(attribute.Group))
211新增: {
212新增: configList.Add(attribute.Group, new List<Config>());
213新增: }
214新增: configList[attribute.Group].Add(config);
215新增: }
216新增:
217新增:
218新增: }
219新增: }
220新增: }
221新增:
222新增: // 渲染已分组的项目
223新增: foreach (var item in configList)
224新增: {
225新增: if (item.Key != nosetGroupKey)
226新增: {
227新增: RenderGroup(item.Value, item.Key);
228新增: }
229新增: }
230新增:
231新增: // 渲染未分组项目
232新增: RenderGroup(configList[nosetGroupKey]);
233新增: }
234新增: private void RenderGroup(List<Config> configList, string groupName = null)
235新增: {
236新增: if (configList == null || configList.Count == 0)
237新增: {
238新增: return;
239新增: }
240新增: var itemContainer = new StackPanel();
241新增:
242新增: var sortList = configList.OrderBy(m => m.Attribute.Index).ToList();
243新增: for (int i = 0; i < sortList.Count; i++)
244新增: {
245新增: var config = sortList[i];
246新增:
247新增: var control = RenderConfigItem(config.Attribute, config.PropertyInfo);
248新增: if (control != null)
249新增: {
250新增: itemContainer.Children.Add(control);
251新增:
252新增: if (i != sortList.Count - 1)
253新增: {
254新增: // 添加分割线
255新增: var spliteLine = new Border();
256新增: spliteLine.Height = 1;
257新增: spliteLine.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ededed"));
258新增: itemContainer.Children.Add(spliteLine);
259新增: }
260新增: }
261新增:
262新增:
263新增: }
264新增:
265新增: var groupControl = GetCreateGroupContainer(itemContainer, groupName);
266新增: Container.Children.Add(groupControl);
267新增: }
268新增:
269新增: private StackPanel GetCreateGroupContainer(UIElement item, string groupName = null)
270新增: {
271新增: var container = new StackPanel();
272新增: container.Margin = new Thickness(0, 10, 0, 20);
273新增: if (groupName != null)
274新增: {
275新增: var groupNameControl = new TextBlock();
276新增: groupNameControl.Text = groupName;
277新增: groupNameControl.FontSize = 14;
278新增: groupNameControl.Margin = new Thickness(0, 0, 0, 10);
279新增: container.Children.Add(groupNameControl);
280新增: }
281新增:
282新增: var border = new Border();
283新增: border.Background = new SolidColorBrush(Colors.White);
284新增: border.CornerRadius = new CornerRadius(6);
285新增: border.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ededed"));
286新增: border.BorderThickness = new Thickness(1);
287新增: border.Child = item;
288新增:
289新增: container.Children.Add(border);
290新增:
291新增: return container;
292新增: }
293新增:
294新增:
295新增: private UIElement RenderConfigItem(ConfigAttribute attribute, PropertyInfo pi)
296新增: {
297新增: UIElement uIElement = null;
298新增: if (pi.PropertyType == typeof(bool))
299新增: {
300新增: uIElement = RenderBooleanConfigControl(attribute, pi);
301新增: }
302新增:
303新增: return uIElement;
304新增: }
305新增:
306新增: private UIElement RenderBooleanConfigControl(ConfigAttribute configAttribute, PropertyInfo pi)
307新增: {
308新增: var inputControl = new Toggle.Toggle();
309新增: inputControl.ToggleChanged += (e, c) =>
310新增: {
311新增: pi.SetValue(configData, inputControl.IsChecked);
312新增:
313新增: Data = configData;
314新增: };
315新增:
316新增: inputControl.IsChecked = (bool)pi.GetValue(Data);
317新增:
318新增: var item = new SettingPanelItem();
319新增: item.Name = configAttribute.Name;
320新增: item.Description = configAttribute.Description;
321新增: item.Content = inputControl;
322新增:
323新增: return item;
324新增: }
325新增: }
326新增:}
新增UI/Controls/SettingPanel/SettingPanelItem.cs+36 −0看文件
@@ -0,0 +1,36 @@
1新增:using Core.Models.Config;
2新增:using System;
3新增:using System.Collections.Generic;
4新增:using System.Collections.ObjectModel;
5新增:using System.Diagnostics;
6新增:using System.Linq;
7新增:using System.Reflection;
8新增:using System.Text;
9新增:using System.Threading.Tasks;
10新增:using System.Windows;
11新增:using System.Windows.Controls;
12新增:
13新增:namespace UI.Controls.SettingPanel
14新增:{
15新增: public class SettingPanelItem : Control
16新增: {
17新增: /// <summary>
18新增: /// 描述
19新增: /// </summary>
20新增: public string Description { get { return (string)GetValue(DescriptionProperty); } set { SetValue(DescriptionProperty, value); } }
21新增: public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(SettingPanelItem));
22新增:
23新增: public object Content { get { return (object)GetValue(ContentProperty); } set { SetValue(ContentProperty, value); } }
24新增: public static readonly DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof(object), typeof(SettingPanelItem));
25新增:
26新增: public SettingPanelItem()
27新增: {
28新增: DefaultStyleKey = typeof(SettingPanelItem);
29新增: }
30新增: public override void OnApplyTemplate()
31新增: {
32新增: base.OnApplyTemplate();
33新增:
34新增: }
35新增: }
36新增:}
新增UI/Controls/SettingPanel/SettingPanelMultiItem.cs+241 −0看文件
@@ -0,0 +1,241 @@
1新增:using Core.Models.Config;
2新增:using System;
3新增:using System.Collections;
4新增:using System.Collections.Generic;
5新增:using System.Collections.ObjectModel;
6新增:using System.Collections.Specialized;
7新增:using System.Diagnostics;
8新增:using System.Linq;
9新增:using System.Reflection;
10新增:using System.Text;
11新增:using System.Threading.Tasks;
12新增:using System.Windows;
13新增:using System.Windows.Controls;
14新增:using UI.Controls.Button;
15新增:using UI.Controls.Input;
16新增:using UI.Controls.List;
17新增:
18新增:namespace UI.Controls.SettingPanel
19新增:{
20新增: public class SettingPanelMultiItem : Control
21新增: {
22新增: public bool Fold { get { return (bool)GetValue(FoldProperty); } set { SetValue(FoldProperty, value); } }
23新增: public static readonly DependencyProperty FoldProperty = DependencyProperty.Register("Fold", typeof(bool), typeof(SettingPanelMultiItem), new PropertyMetadata(false));
24新增:
25新增: public object Data { get { return (object)GetValue(DataProperty); } set { SetValue(DataProperty, value); } }
26新增: public static readonly DependencyProperty DataProperty = DependencyProperty.Register("Data", typeof(object), typeof(SettingPanelMultiItem));
27新增:
28新增: public Command OnRemoveAction { get { return (Command)GetValue(OnRemoveActionProperty); } set { SetValue(OnRemoveActionProperty, value); } }
29新增: public static readonly DependencyProperty OnRemoveActionProperty = DependencyProperty.Register("OnRemoveAction", typeof(Command), typeof(SettingPanelMultiItem));
30新增: public Command OnFoldAction { get { return (Command)GetValue(OnFoldActionProperty); } set { SetValue(OnFoldActionProperty, value); } }
31新增: public static readonly DependencyProperty OnFoldActionProperty = DependencyProperty.Register("OnFoldAction", typeof(Command), typeof(SettingPanelMultiItem));
32新增: public string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } }
33新增: public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(SettingPanelMultiItem));
34新增: public event EventHandler DataChanged;
35新增:
36新增: private StackPanel Container;
37新增: private object configData;
38新增: private IconButton FoldBtn;
39新增: public SettingPanelMultiItem()
40新增: {
41新增: DefaultStyleKey = typeof(SettingPanelMultiItem);
42新增: }
43新增: public override void OnApplyTemplate()
44新增: {
45新增: base.OnApplyTemplate();
46新增: Container = GetTemplateChild("Container") as StackPanel;
47新增: FoldBtn = GetTemplateChild("FoldBtn") as IconButton;
48新增:
49新增: OnFoldAction = new Command(new Action<object>(FoldAction));
50新增: Render();
51新增: }
52新增:
53新增: private void FoldAction(object obj)
54新增: {
55新增: Fold = !Fold;
56新增: if (Fold)
57新增: {
58新增: FoldBtn.Icon = Base.IconTypes.ChevronDown;
59新增:
60新增: FoldBtn.ToolTip = "展开";
61新增: }
62新增: else
63新增: {
64新增: FoldBtn.Icon = Base.IconTypes.ChevronUp;
65新增:
66新增: FoldBtn.ToolTip = "收起";
67新增:
68新增: }
69新增: }
70新增:
71新增: private void Render()
72新增: {
73新增: if (Container == null)
74新增: {
75新增: return;
76新增: }
77新增:
78新增: Container.Children.Clear();
79新增:
80新增: configData = Activator.CreateInstance(Data.GetType());
81新增:
82新增: // 遍历方法特性
83新增: foreach (PropertyInfo pi in Data.GetType().GetProperties())
84新增: {
85新增: foreach (Attribute attr in pi.GetCustomAttributes(true))
86新增: {
87新增: if (attr is ConfigAttribute)
88新增: {
89新增: ConfigAttribute attribute = (ConfigAttribute)attr;
90新增:
91新增: if (pi.PropertyType == typeof(string))
92新增: {
93新增: // 输入框
94新增: RenderTextBox(attribute, pi);
95新增: }
96新增: else if (pi.PropertyType == typeof(List<string>))
97新增: {
98新增: // String 集合
99新增: RenderStringList(attribute, pi);
100新增: }
101新增: }
102新增: }
103新增: }
104新增: }
105新增:
106新增: private void RenderStringList(ConfigAttribute attribute, PropertyInfo pi)
107新增: {
108新增: var title = new SettingPanelItem();
109新增: title.Name = attribute.Name;
110新增: title.Description = attribute.Description;
111新增:
112新增: Container.Children.Add(title);
113新增:
114新增: var list = pi.GetValue(Data) as List<string>;
115新增:
116新增: var listControl = new BaseList();
117新增:
118新增: listControl.Loaded += (sender, args) =>
119新增: {
120新增: listControl.Items.CollectionChanged += (o, e) =>
121新增: {
122新增: var newData = new List<string>();
123新增: foreach (var item in listControl.Items)
124新增: {
125新增: newData.Add(item.ToString());
126新增: }
127新增: pi.SetValue(configData, newData);
128新增: Data = configData;
129新增: DataChanged?.Invoke(this, EventArgs.Empty);
130新增: };
131新增: //((INotifyCollectionChanged)listControl.Items).CollectionChanged += (sender2, e) =>
132新增: //{
133新增: // var newData = new List<string>();
134新增: // foreach (var item in listControl.Items)
135新增: // {
136新增: // newData.Add(item.ToString());
137新增: // }
138新增: // pi.SetValue(configData, newData);
139新增: // Data = configData;
140新增: // DataChanged?.Invoke(this, EventArgs.Empty);
141新增: //};
142新增: };
143新增: listControl.Margin = new Thickness(15, 0, 15, 10);
144新增:
145新增: if (list != null)
146新增: {
147新增: foreach (string item in list)
148新增: {
149新增: listControl.Items.Add(item);
150新增: }
151新增: }
152新增: else
153新增: {
154新增: list = new List<string>();
155新增: }
156新增: var contextMenu = new ContextMenu();
157新增:
158新增: var contextMenuItemDel = new MenuItem();
159新增: contextMenuItemDel.Header = "移除";
160新增: contextMenuItemDel.Click += (e, c) =>
161新增: {
162新增: listControl.Items.Remove(listControl.SelectedItem);
163新增: };
164新增: contextMenu.Items.Add(contextMenuItemDel);
165新增: listControl.ContextMenu = contextMenu;
166新增:
167新增:
168新增: var addInputBox = new InputBox();
169新增: addInputBox.Placeholder = attribute.Name;
170新增: addInputBox.Margin = new Thickness(0, 0, 10, 0);
171新增:
172新增: var addBtn = new Button.Button();
173新增: //addBtn.Margin = new Thickness(15, 0, 15, 10);
174新增: addBtn.Content = "添加";
175新增:
176新增: addBtn.Click += (e, c) =>
177新增: {
178新增: if (addInputBox.Text == String.Empty || list.Contains(addInputBox.Text))
179新增: {
180新增: return;
181新增: }
182新增: //list.Add(addInputBox.Text);
183新增: listControl.Items.Add(addInputBox.Text);
184新增: addInputBox.Text = String.Empty;
185新增:
186新增:
187新增:
188新增: };
189新增: pi.SetValue(configData, list);
190新增: Container.Children.Add(listControl);
191新增:
192新增: var inputPanel = new Grid();
193新增: inputPanel.ColumnDefinitions.Add(
194新增: new ColumnDefinition()
195新增: {
196新增: Width = new GridLength(10, GridUnitType.Star)
197新增: });
198新增: inputPanel.ColumnDefinitions.Add(
199新增: new ColumnDefinition()
200新增: {
201新增: Width = new GridLength(2, GridUnitType.Star)
202新增: });
203新增: inputPanel.Margin = new Thickness(15, 10, 15, 10);
204新增: Grid.SetColumn(addInputBox, 0);
205新增: Grid.SetColumn(addBtn, 1);
206新增: inputPanel.Children.Add(addInputBox);
207新增: inputPanel.Children.Add(addBtn);
208新增: Container.Children.Add(inputPanel);
209新增:
210新增:
211新增: }
212新增: private void RenderTextBox(ConfigAttribute attribute, PropertyInfo pi)
213新增: {
214新增:
215新增: var textBox = new InputBox();
216新增: textBox.Text = (string)pi.GetValue(Data);
217新增: textBox.Placeholder = attribute.Name;
218新增: textBox.Width = 125;
219新增: textBox.LostFocus += (e, c) =>
220新增: {
221新增: if (attribute.IsName)
222新增: {
223新增: Title = textBox.Text;
224新增: }
225新增: pi.SetValue(configData, textBox.Text);
226新增: Data = configData;
227新增: DataChanged?.Invoke(this, EventArgs.Empty);
228新增: };
229新增: var item = new SettingPanelItem();
230新增: item.Name = attribute.Name;
231新增: item.Description = attribute.Description;
232新增: item.Content = textBox;
233新增: pi.SetValue(configData, textBox.Text);
234新增: if (attribute.IsName)
235新增: {
236新增: Title = textBox.Text;
237新增: }
238新增: Container.Children.Add(item);
239新增: }
240新增: }
241新增:}
新增UI/Controls/Tabbar/Tabbar.cs+299 −0看文件
@@ -0,0 +1,299 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Collections.ObjectModel;
4新增:using System.Collections.Specialized;
5新增:using System.Linq;
6新增:using System.Text;
7新增:using System.Windows;
8新增:using System.Windows.Controls;
9新增:using System.Windows.Input;
10新增:using System.Windows.Media;
11新增:using System.Windows.Media.Animation;
12新增:using UI.Controls.Navigation.Models;
13新增:
14新增:namespace UI.Controls.Tabbar
15新增:{
16新增: public class Tabbar : Control
17新增: {
18新增:
19新增:
20新增: public int SelectedIndex
21新增: {
22新增: get { return (int)GetValue(SelectedIndexProperty); }
23新增: set { SetValue(SelectedIndexProperty, value); }
24新增: }
25新增: public static readonly DependencyProperty SelectedIndexProperty =
26新增: DependencyProperty.Register("SelectedIndex", typeof(int), typeof(Tabbar), new PropertyMetadata((int)0, new PropertyChangedCallback(OnSelectedItemChanged)));
27新增:
28新增: private static void OnSelectedItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
29新增: {
30新增: var control = d as Tabbar;
31新增: if (e.NewValue != e.OldValue)
32新增: {
33新增: control.ScrollToActive(int.Parse(e.OldValue.ToString()));
34新增: }
35新增: }
36新增:
37新增:
38新增: public ObservableCollection<string> Data
39新增: {
40新增: get
41新增: {
42新增: return (ObservableCollection<string>)GetValue(DataProperty);
43新增: }
44新增: set
45新增: {
46新增: SetValue(DataProperty, value);
47新增: }
48新增: }
49新增: public static readonly DependencyProperty DataProperty =
50新增: DependencyProperty.Register("Data", typeof(ObservableCollection<string>), typeof(Tabbar), new PropertyMetadata(new PropertyChangedCallback(OnDataChanged)));
51新增:
52新增: private static void OnDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
53新增: {
54新增: var control = d as Tabbar;
55新增: if (e.NewValue != e.OldValue)
56新增: {
57新增:
58新增: }
59新增: }
60新增:
61新增:
62新增: private StackPanel ItemsPanel;
63新增: private List<TextBlock> ItemsDictionary;
64新增:
65新增: // 选中标记块
66新增: private Border ActiveBlock;
67新增: // 动画
68新增: Storyboard storyboard;
69新增: public Tabbar()
70新增: {
71新增: DefaultStyleKey = typeof(Tabbar);
72新增: ItemsDictionary = new List<TextBlock>();
73新增: storyboard = new Storyboard();
74新增: }
75新增:
76新增: private void Data_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
77新增: {
78新增: //if (e.Action == NotifyCollectionChangedAction.Add)
79新增: //{
80新增: // foreach (var item in e.NewItems)
81新增: // {
82新增: // AddItem(item as NavigationItemModel);
83新增: // }
84新增: //}
85新增: //if (e.Action == NotifyCollectionChangedAction.Remove)
86新增: //{
87新增: // foreach (var item in e.OldItems)
88新增: // {
89新增: // RemoveItem(item as NavigationItemModel);
90新增: // }
91新增: //}
92新增: //if (e.Action == NotifyCollectionChangedAction.Replace)
93新增: //{
94新增: // foreach (var ritem in e.NewItems)
95新增: // {
96新增: // var item = ritem as NavigationItemModel;
97新增: // var id = item.ID;
98新增: // ItemsDictionary[id].Icon = item.Icon;
99新增: // ItemsDictionary[id].Title = item.Title;
100新增:
101新增: // }
102新增: //}
103新增: }
104新增:
105新增: public override void OnApplyTemplate()
106新增: {
107新增: base.OnApplyTemplate();
108新增: ItemsPanel = GetTemplateChild("ItemsPanel") as StackPanel;
109新增: ActiveBlock = GetTemplateChild("ActiveBlock") as Border;
110新增:
111新增: Render();
112新增: }
113新增:
114新增:
115新增: private void AddItem(string item)
116新增: {
117新增: if (ItemsPanel != null)
118新增: {
119新增: var control = new TextBlock();
120新增: control.Text = item;
121新增: control.Margin = new Thickness(0, 0, 10, 0);
122新增: control.FontSize = 18;
123新增: control.Cursor = Cursors.Hand;
124新增: control.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1F1F1F"));
125新增: control.VerticalAlignment = VerticalAlignment.Bottom;
126新增: control.MouseUp += (e, c) =>
127新增: {
128新增: int index = Data.IndexOf(item);
129新增: if (SelectedIndex != index)
130新增: {
131新增: SelectedIndex = index;
132新增: }
133新增: };
134新增: if (Data.IndexOf(item) == Data.Count - 1)
135新增: {
136新增: control.Loaded += (e, c) =>
137新增: {
138新增: ScrollToActive();
139新增: Reset();
140新增: };
141新增: }
142新增: ItemsPanel.Children.Add(control);
143新增: ItemsDictionary.Add(control);
144新增: }
145新增: }
146新增:
147新增:
148新增:
149新增: private void Render()
150新增: {
151新增: if (Data != null)
152新增: {
153新增: ItemsPanel.Children.Clear();
154新增: foreach (var item in Data)
155新增: {
156新增: AddItem(item);
157新增: }
158新增:
159新增: }
160新增: }
161新增:
162新增: private void ScrollToActive(int oldSelectedIndex = 0)
163新增: {
164新增: if (oldSelectedIndex > ItemsDictionary.Count || ItemsDictionary.Count == 0)
165新增: {
166新增: return;
167新增: }
168新增: // 获取选中项
169新增:
170新增: var item = ItemsDictionary[SelectedIndex];
171新增: var oldSelectedItem = ItemsDictionary[oldSelectedIndex];
172新增:
173新增: //ActiveBlock.Height = item.ActualHeight * Data.Count;
174新增:
175新增: // 选中项的坐标
176新增: Point relativePoint = item.TransformToAncestor(this).Transform(new Point(0, 0));
177新增:
178新增: // 创建动画
179新增:
180新增: // 设定动画方向
181新增: //var activeBlockTTF = (ActiveBlock.RenderTransform as TransformGroup).Children[0] as TranslateTransform;
182新增:
183新增: //var transformGroup = new TransformGroup();
184新增: //transformGroup.Children.Add(new TranslateTransform(0, activeBlockTTF.Y));
185新增: //transformGroup.Children.Add(new ScaleTransform(1, 1, 0, 0));
186新增:
187新增: //ActiveBlock.RenderTransform = transformGroup;
188新增:
189新增:
190新增: storyboard.Children.Clear();
191新增: DoubleAnimation scrollAnimation = new DoubleAnimation();
192新增: //scrollAnimation.From = activeBlockTTF.Y;
193新增: double scrollX = relativePoint.X - 10;
194新增: scrollX = scrollX < 0 ? 0 : scrollX;
195新增: scrollAnimation.To = scrollX;
196新增:
197新增: scrollAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
198新增: Storyboard.SetTarget(scrollAnimation, ActiveBlock);
199新增: Storyboard.SetTargetProperty(scrollAnimation, new PropertyPath("RenderTransform.Children[0].X"));
200新增:
201新增: scrollAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.15));
202新增:
203新增: // 文字大小动画
204新增: DoubleAnimation fontSizeAnimation = new DoubleAnimation();
205新增: //scrollAnimation.From = activeBlockTTF.Y;
206新增: fontSizeAnimation.To = 18;
207新增:
208新增: fontSizeAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
209新增: Storyboard.SetTarget(fontSizeAnimation, item);
210新增: Storyboard.SetTargetProperty(fontSizeAnimation, new PropertyPath("FontSize"));
211新增:
212新增: fontSizeAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.1));
213新增:
214新增:
215新增:
216新增: // 文字颜色动画
217新增: ColorAnimation fontColorAnimation = new ColorAnimation();
218新增: //scrollAnimation.From = activeBlockTTF.Y;
219新增: fontColorAnimation.To = (Color)ColorConverter.ConvertFromString("#2b20d9");
220新增:
221新增: fontColorAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
222新增: Storyboard.SetTarget(fontColorAnimation, item);
223新增: Storyboard.SetTargetProperty(fontColorAnimation, new PropertyPath("(TextBlock.Foreground).(SolidColorBrush.Color)"));
224新增:
225新增: fontColorAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.1));
226新增:
227新增:
228新增: storyboard.Children.Add(scrollAnimation);
229新增: storyboard.Children.Add(fontSizeAnimation);
230新增:
231新增: storyboard.Children.Add(fontColorAnimation);
232新增:
233新增:
234新增: if (oldSelectedIndex != SelectedIndex)
235新增: {
236新增: DoubleAnimation oldFontSizeAnimation = new DoubleAnimation();
237新增: //scrollAnimation.From = activeBlockTTF.Y;
238新增: oldFontSizeAnimation.To = 14;
239新增:
240新增: oldFontSizeAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
241新增: Storyboard.SetTarget(oldFontSizeAnimation, oldSelectedItem);
242新增: Storyboard.SetTargetProperty(oldFontSizeAnimation, new PropertyPath("FontSize"));
243新增:
244新增: oldFontSizeAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.1));
245新增:
246新增: ColorAnimation oldFontColorAnimation = new ColorAnimation();
247新增: //scrollAnimation.From = activeBlockTTF.Y;
248新增: oldFontColorAnimation.To = (Color)ColorConverter.ConvertFromString("#CCCCCC");
249新增:
250新增: oldFontColorAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
251新增: Storyboard.SetTarget(oldFontColorAnimation, oldSelectedItem);
252新增: Storyboard.SetTargetProperty(oldFontColorAnimation, new PropertyPath("(TextBlock.Foreground).(SolidColorBrush.Color)"));
253新增:
254新增: oldFontColorAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.3));
255新增:
256新增: storyboard.Children.Add(oldFontSizeAnimation);
257新增: storyboard.Children.Add(oldFontColorAnimation);
258新增:
259新增: }
260新增: storyboard.Begin();
261新增: }
262新增:
263新增: private void Reset()
264新增: {
265新增: Storyboard storyboard = new Storyboard();
266新增:
267新增: foreach (var item in ItemsPanel.Children)
268新增: {
269新增: if (item != ItemsPanel.Children[SelectedIndex])
270新增: {
271新增: DoubleAnimation fontSizeAnimation = new DoubleAnimation();
272新增: //scrollAnimation.From = activeBlockTTF.Y;
273新增: fontSizeAnimation.To = 14;
274新增:
275新增: fontSizeAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
276新增: Storyboard.SetTarget(fontSizeAnimation, (UIElement)item);
277新增: Storyboard.SetTargetProperty(fontSizeAnimation, new PropertyPath("FontSize"));
278新增:
279新增: fontSizeAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.1));
280新增:
281新增: ColorAnimation oldFontColorAnimation = new ColorAnimation();
282新增: //scrollAnimation.From = activeBlockTTF.Y;
283新增: oldFontColorAnimation.To = (Color)ColorConverter.ConvertFromString("#CCCCCC");
284新增:
285新增: oldFontColorAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn };
286新增: Storyboard.SetTarget(oldFontColorAnimation, (UIElement)item);
287新增: Storyboard.SetTargetProperty(oldFontColorAnimation, new PropertyPath("(TextBlock.Foreground).(SolidColorBrush.Color)"));
288新增:
289新增: oldFontColorAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.3));
290新增:
291新增: storyboard.Children.Add(fontSizeAnimation);
292新增: storyboard.Children.Add(oldFontColorAnimation);
293新增: }
294新增: }
295新增:
296新增: storyboard.Begin();
297新增: }
298新增: }
299新增:}
新增UI/Controls/Toggle/Toggle.cs+72 −0看文件
@@ -0,0 +1,72 @@
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新增:using System.Windows.Input;
9新增:
10新增:namespace UI.Controls.Toggle
11新增:{
12新增: public class Toggle : Control
13新增: {
14新增: public event EventHandler ToggleChanged;
15新增: public bool IsChecked
16新增: {
17新增: get { return (bool)GetValue(IsCheckedProperty); }
18新增: set { SetValue(IsCheckedProperty, value); }
19新增: }
20新增: public static readonly DependencyProperty IsCheckedProperty =
21新增: DependencyProperty.Register("IsChecked", typeof(bool), typeof(Toggle), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnIsCheckedChanged)));
22新增:
23新增: private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
24新增: {
25新增: var control = d as Toggle;
26新增: if (e.OldValue != e.NewValue)
27新增: {
28新增: control.Text = control.IsChecked ? control.OnText : control.OffText;
29新增: }
30新增: VisualStateManager.GoToState(control, control.IsChecked ? "On" : "Off", true);
31新增: }
32新增:
33新增: public string OnText
34新增: {
35新增: get { return (string)GetValue(OnTextProperty); }
36新增: set { SetValue(OnTextProperty, value); }
37新增: }
38新增: public static readonly DependencyProperty OnTextProperty =
39新增: DependencyProperty.Register("OnText", typeof(string), typeof(Toggle), new PropertyMetadata("开"));
40新增: public string OffText
41新增: {
42新增: get { return (string)GetValue(OffTextProperty); }
43新增: set { SetValue(OffTextProperty, value); }
44新增: }
45新增: public static readonly DependencyProperty OffTextProperty =
46新增: DependencyProperty.Register("OffText", typeof(string), typeof(Toggle), new PropertyMetadata("关"));
47新增: public string Text
48新增: {
49新增: get { return (string)GetValue(TextProperty); }
50新增: set { SetValue(TextProperty, value); }
51新增: }
52新增: public static readonly DependencyProperty TextProperty =
53新增: DependencyProperty.Register("Text", typeof(string), typeof(Toggle), new PropertyMetadata("关"));
54新增:
55新增: public Toggle()
56新增: {
57新增: DefaultStyleKey = typeof(Toggle);
58新增: }
59新增: public override void OnApplyTemplate()
60新增: {
61新增: base.OnApplyTemplate();
62新增: VisualStateManager.GoToState(this, IsChecked ? "On" : "Off", true);
63新增: }
64新增: protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
65新增: {
66新增: base.OnMouseLeftButtonUp(e);
67新增: IsChecked = !IsChecked;
68新增: ToggleChanged?.Invoke(this, EventArgs.Empty);
69新增: VisualStateManager.GoToState(this, IsChecked ? "On" : "Off", true);
70新增: }
71新增: }
72新增:}
修改UI/Controls/Window/DefaultWindow.cs+11 −0看文件
@@ -90,6 +90,12 @@ namespace UI.Controls.Window
9090 #endregion
9191 #endregion
9292
93新增: private bool IsWindowClosed_ = false;
94新增: /// <summary>
95新增: /// 指示当前窗口是否已被关闭
96新增: /// </summary>
97新增: public bool IsWindowClosed { get { return IsWindowClosed_; } }
98新增:
9399 #region 3.初始化
94100 public DefaultWindow()
95101 {
@@ -177,6 +183,11 @@ namespace UI.Controls.Window
177183 }
178184 #endregion
179185
186新增: protected override void OnClosed(EventArgs e)
187新增: {
188新增: base.OnClosed(e);
189新增: IsWindowClosed_ = true;
190新增: }
180191 #region 5.命令
181192
182193 private void OnCloseWindowCommand(object sender, ExecutedRoutedEventArgs e)
新增UI/Extensions/ListExtensions.cs+39 −0看文件
@@ -0,0 +1,39 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading;
6新增:using System.Threading.Tasks;
7新增:
8新增:namespace UI.Extensions
9新增:{
10新增: public static class ThreadSafeRandom
11新增: {
12新增: [ThreadStatic] private static Random Local;
13新增:
14新增: public static Random ThisThreadsRandom
15新增: {
16新增: get { return Local ?? (Local = new Random(unchecked(Environment.TickCount * 31 + Thread.CurrentThread.ManagedThreadId))); }
17新增: }
18新增: }
19新增: public static class ListExtensions
20新增: {
21新增: /// <summary>
22新增: /// 随机打乱该List
23新增: /// </summary>
24新增: /// <typeparam name="T"></typeparam>
25新增: /// <param name="list"></param>
26新增: public static void Shuffle<T>(this IList<T> list)
27新增: {
28新增: int n = list.Count;
29新增: while (n > 1)
30新增: {
31新增: n--;
32新增: int k = ThreadSafeRandom.ThisThreadsRandom.Next(n + 1);
33新增: T value = list[k];
34新增: list[k] = list[n];
35新增: list[n] = value;
36新增: }
37新增: }
38新增: }
39新增:}
新增UI/Librays/Image/Imager.cs+58 −0看文件
@@ -0,0 +1,58 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Drawing;
4新增:using System.IO;
5新增:using System.Linq;
6新增:using System.Text;
7新增:using System.Threading.Tasks;
8新增:using System.Windows;
9新增:using System.Windows.Interop;
10新增:using System.Windows.Media;
11新增:using System.Windows.Media.Imaging;
12新增:using System.Windows.Resources;
13新增:
14新增:namespace Core.Librarys.Image
15新增:{
16新增: public class Imager
17新增: {
18新增: public static BitmapImage Load(string filePath)
19新增: {
20新增: if (filePath == null)
21新增: {
22新增: return null;
23新增: }
24新增:
25新增: var bitmap = new BitmapImage();
26新增: bitmap.BeginInit();
27新增: if (filePath.IndexOf("pack://") != -1)
28新增: {
29新增: StreamResourceInfo info = Application.GetResourceStream(new Uri(filePath, UriKind.RelativeOrAbsolute));
30新增: using (var st = info.Stream)
31新增: {
32新增: bitmap.StreamSource = st;
33新增: bitmap.EndInit();
34新增: bitmap.Freeze();
35新增: }
36新增: }
37新增: else
38新增: {
39新增: if (!File.Exists(filePath))
40新增: {
41新增: return null;
42新增: }
43新增: byte[] imageData;
44新增: using (var fileStream = new FileStream(@filePath, FileMode.Open, FileAccess.Read))
45新增:
46新增: using (var binaryReader = new BinaryReader(fileStream))
47新增: {
48新增: imageData = binaryReader.ReadBytes((int)fileStream.Length);
49新增: bitmap.StreamSource = new MemoryStream(imageData);
50新增: bitmap.EndInit();
51新增: bitmap.Freeze();
52新增: }
53新增: }
54新增:
55新增: return bitmap;
56新增: }
57新增: }
58新增:}
新增UI/Librays/Timer.cs+37 −0看文件
@@ -0,0 +1,37 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Linq;
4新增:using System.Text;
5新增:using System.Threading.Tasks;
6新增:
7新增:namespace UI.Librays
8新增:{
9新增: public class Timer
10新增: {
11新增: public static string Fromat(int seconds)
12新增: {
13新增: if (seconds < 60)
14新增: {
15新增: return seconds + "秒";
16新增: }
17新增: else
18新增: {
19新增: double minutes = seconds / 60;
20新增: if (minutes < 60)
21新增: {
22新增: return minutes + "分钟";
23新增: }
24新增: else
25新增: {
26新增: double hours = (double)seconds / 60;
27新增: if (hours != (int)hours)
28新增: {
29新增: double pointNumber = hours - (int)hours;
30新增: return (int)hours + "小时" + (int)(pointNumber * 60) + "分";
31新增: }
32新增: return hours + "小时";
33新增: }
34新增: }
35新增: }
36新增: }
37新增:}
修改UI/MainWindow.xaml+5 −11看文件
@@ -6,7 +6,7 @@
66 xmlns:local="clr-namespace:UI"
77 mc:Ignorable="d"
88 xmlns:ui="clr-namespace:UI.Controls.Window"
9删除: Title="Tai - 时间管家" Height="450" Width="800"
9新增: Title="Tai" Height="585" Width="814" MinHeight="585" MinWidth="814"
1010 xmlns:control="clr-namespace:UI.Controls"
1111 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
1212 xmlns:Navigation="clr-namespace:UI.Controls.Navigation"
@@ -31,21 +31,15 @@
3131 <TextBlock Text="test"/>
3232 </Navigation:Navigation.TopExtContent>-->
3333 <Navigation:Navigation.BottomExtContent>
34删除: <Navigation:NavigationItem Icon="Settings" Title="设置" Uri="SettingsPage" Command="{Binding GotoPageCommand}" CommandParameter="SettingsPage"/>
34新增: <Navigation:NavigationItem Icon="Settings" Title="设置" Uri="SettingsPage" Command="{Binding GotoPageCommand}" CommandParameter="SettingPage"/>
3535 </Navigation:Navigation.BottomExtContent>
36删除: <Navigation:Navigation.ContextMenu>
37删除: <ContextMenu>
38删除: <MenuItem Header="新建分组" Command="{Binding ShowGroupModalCommand}">
39删除: <!--<MenuItem.Icon>
40删除: <base:Icon IconType="CalculatorAddition" FontSize="12"/>
41删除: </MenuItem.Icon>-->
42删除: </MenuItem>
43删除: </ContextMenu>
44删除: </Navigation:Navigation.ContextMenu>
36新增:
4537 </Navigation:Navigation>
4638
4739 <Border Grid.Column="1" Background="#f9f9f9" Margin="0,40,10,10" CornerRadius="5" BorderThickness="1,1,1,1" BorderBrush="#ccc">
40新增: <ScrollViewer VerticalScrollBarVisibility="Auto">
4841 <control:PageContainer ServiceProvider="{Binding ServiceProvider}" Uri="{Binding Uri,Mode=TwoWay}" Title="{Binding Title}" IsShowTilteBar="{Binding IsShowTitleBar,Mode=TwoWay}"/>
42新增: </ScrollViewer>
4943 </Border>
5044
5145 </Grid>
新增UI/Models/DataPageModel.cs+33 −0看文件
@@ -0,0 +1,33 @@
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 UI.Controls.Charts.Model;
8新增:
9新增:namespace UI.Models
10新增:{
11新增: public class DataPageModel : UINotifyPropertyChanged
12新增: {
13新增: private List<ChartsDataModel> Data_;
14新增: /// <summary>
15新增: /// data
16新增: /// </summary>
17新增: public List<ChartsDataModel> Data
18新增: {
19新增: get { return Data_; }
20新增: set { Data_ = value; OnPropertyChanged(); }
21新增: }
22新增:
23新增: private DateTime Date_;
24新增: /// <summary>
25新增: /// date
26新增: /// </summary>
27新增: public DateTime Date
28新增: {
29新增: get { return Date_; }
30新增: set { Date_ = value; OnPropertyChanged(); }
31新增: }
32新增: }
33新增:}
新增UI/Models/DetailPageModel.cs+44 −0看文件
@@ -0,0 +1,44 @@
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 UI.Controls.Charts.Model;
8新增:
9新增:namespace UI.Models
10新增:{
11新增: public class DetailPageModel : UINotifyPropertyChanged
12新增: {
13新增:
14新增: private List<ChartsDataModel> Data_;
15新增: /// <summary>
16新增: /// data
17新增: /// </summary>
18新增: public List<ChartsDataModel> Data
19新增: {
20新增: get { return Data_; }
21新增: set { Data_ = value; OnPropertyChanged(); }
22新增: }
23新增: private ChartsDataModel Process_;
24新增: public ChartsDataModel Process { get { return Process_; } set { Process_ = value; OnPropertyChanged(); } }
25新增: private bool IsLoading_;
26新增: public bool IsLoading { get { return IsLoading_; } set { IsLoading_ = value; OnPropertyChanged(); } }
27新增:
28新增: private string Total_;
29新增: public string Total { get { return Total_; } set { Total_ = value; OnPropertyChanged(); } }
30新增:
31新增: private string Ratio_;
32新增: public string Ratio { get { return Ratio_; } set { Ratio_ = value; OnPropertyChanged(); } }
33新增:
34新增: private DateTime Date_;
35新增: public DateTime Date { get { return Date_; } set { Date_ = value; OnPropertyChanged();} }
36新增:
37新增: private string LongDay_;
38新增: public string LongDay { get { return LongDay_; } set { LongDay_ = value;OnPropertyChanged();} }
39新增:
40新增: private string ProcessName_;
41新增: public string ProcessName { get { return ProcessName_; } set { ProcessName_ = value; OnPropertyChanged(); } }
42新增:
43新增: }
44新增:}
新增UI/Models/IndexPageModel.cs+51 −0看文件
@@ -0,0 +1,51 @@
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 UI.Controls.Charts.Model;
8新增:
9新增:namespace UI.Models
10新增:{
11新增: public class IndexPageModel : UINotifyPropertyChanged
12新增: {
13新增: private ObservableCollection<string> TabbarData_;
14新增: /// <summary>
15新增: /// tabbar data
16新增: /// </summary>
17新增: public ObservableCollection<string> TabbarData
18新增: {
19新增: get { return TabbarData_; }
20新增: set { TabbarData_ = value; OnPropertyChanged(); }
21新增: }
22新增:
23新增: private int TabbarSelectedIndex_;
24新增: /// <summary>
25新增: /// tabbar selected item index
26新增: /// </summary>
27新增: public int TabbarSelectedIndex
28新增: {
29新增: get { return TabbarSelectedIndex_; }
30新增: set
31新增: {
32新增: TabbarSelectedIndex_ = value;
33新增: OnPropertyChanged();
34新增: }
35新增: }
36新增:
37新增:
38新增: private List<ChartsDataModel> WeekData_;
39新增: /// <summary>
40新增: /// week data
41新增: /// </summary>
42新增: public List<ChartsDataModel> WeekData
43新增: {
44新增: get { return WeekData_; }
45新增: set { WeekData_ = value; OnPropertyChanged(); }
46新增: }
47新增:
48新增: private bool IsLoading_;
49新增: public bool IsLoading { get { return IsLoading_; } set { IsLoading_ = value; OnPropertyChanged(); } }
50新增: }
51新增:}
新增UI/Models/SettingPageModel.cs+35 −0看文件
@@ -0,0 +1,35 @@
1新增:using Core.Models.Config;
2新增:using System;
3新增:using System.Collections.Generic;
4新增:using System.Collections.ObjectModel;
5新增:using System.Linq;
6新增:using System.Text;
7新增:using System.Threading.Tasks;
8新增:
9新增:namespace UI.Models
10新增:{
11新增: public class SettingPageModel : UINotifyPropertyChanged
12新增: {
13新增: private object data;
14新增: public object Data { get { return data; } set { data = value; OnPropertyChanged(); } }
15新增:
16新增: private ObservableCollection<string> TabbarData_;
17新增: /// <summary>
18新增: /// tabbar data
19新增: /// </summary>
20新增: public ObservableCollection<string> TabbarData { get { return TabbarData_; } set { TabbarData_ = value; OnPropertyChanged(); } }
21新增:
22新增: private int TabbarSelectedIndex_;
23新增: /// <summary>
24新增: /// tabbar selected item index
25新增: /// </summary>
26新增: public int TabbarSelectedIndex { get { return TabbarSelectedIndex_; } set { TabbarSelectedIndex_ = value; OnPropertyChanged(); } }
27新增:
28新增: private string version;
29新增: /// <summary>
30新增: /// 软件版本号
31新增: /// </summary>
32新增: public string Version{ get { return version; } set { version = value; OnPropertyChanged(); } }
33新增:
34新增: }
35新增:}
修改UI/Properties/AssemblyInfo.cs+5 −5看文件
@@ -7,12 +7,12 @@ using System.Windows;
77// 有关程序集的一般信息由以下
88// 控制。更改这些特性值可修改
99// 与程序集关联的信息。
10删除:[assembly: AssemblyTitle("Test")]
11删除:[assembly: AssemblyDescription("")]
10新增:[assembly: AssemblyTitle("Tai")]
11新增:[assembly: AssemblyDescription("Tai")]
1212[assembly: AssemblyConfiguration("")]
13删除:[assembly: AssemblyCompany("")]
14删除:[assembly: AssemblyProduct("UI")]
15删除:[assembly: AssemblyCopyright("Copyright © 2021")]
13新增:[assembly: AssemblyCompany("nacat")]
14新增:[assembly: AssemblyProduct("Tai")]
15新增:[assembly: AssemblyCopyright("Copyright © 2021 https://github.com/noberumotto")]
1616[assembly: AssemblyTrademark("")]
1717[assembly: AssemblyCulture("")]
1818
新增UI/Resources/Icons/defaultIcon.png看文件

二进制文件,不显示改动。

新增UI/Resources/Icons/tai.ico看文件

二进制文件,不显示改动。

删除UI/TextTemplate.ico

二进制文件,不显示改动。

新增UI/Themes/Base/EmptyData.xaml+33 −0看文件
@@ -0,0 +1,33 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Base">
4新增: <Style TargetType="{x:Type local:EmptyData}">
5新增: <Setter Property="SnapsToDevicePixels"
6新增: Value="true" />
7新增: <Setter Property="HorizontalAlignment"
8新增: Value="Left" />
9新增:
10新增:
11新增: <Setter Property="Template">
12新增: <Setter.Value>
13新增: <ControlTemplate TargetType="{x:Type local:EmptyData}">
14新增: <Border >
15新增:
16新增: <StackPanel>
17新增: <Grid>
18新增: <local:Icon IconType="Preview" FontSize="100" Foreground="Gray" RenderTransformOrigin=".5,.5" Opacity=".3">
19新增: <local:Icon.RenderTransform>
20新增: <RotateTransform Angle="90" />
21新增: </local:Icon.RenderTransform>
22新增: </local:Icon>
23新增: </Grid>
24新增: <TextBlock Text="暂时没有数据" HorizontalAlignment="Center" Foreground="Gray" Opacity=".3"/>
25新增: </StackPanel>
26新增:
27新增: </Border>
28新增:
29新增: </ControlTemplate>
30新增: </Setter.Value>
31新增: </Setter>
32新增: </Style>
33新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/Base/Placeholder.xaml+32 −0看文件
@@ -0,0 +1,32 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Base">
4新增: <Style TargetType="{x:Type local:Placeholder}">
5新增: <Setter Property="SnapsToDevicePixels"
6新增: Value="true" />
7新增:
8新增:
9新增:
10新增: <Setter Property="Template">
11新增: <Setter.Value>
12新增: <ControlTemplate TargetType="{x:Type local:Placeholder}">
13新增: <Border CornerRadius="{TemplateBinding CornerRadius}" Background="#e0e0e0" ClipToBounds="True">
14新增: <Border x:Name="Flash" Background="White" Width="10" Height="{TemplateBinding Height}" Opacity=".5" RenderTransformOrigin="0,0.5">
15新增: <Border.Effect>
16新增: <BlurEffect Radius="30" ></BlurEffect>
17新增: </Border.Effect>
18新增: <Border.RenderTransform>
19新增: <TransformGroup>
20新增: <TranslateTransform X="-10" />
21新增: <RotateTransform Angle="15"/>
22新增: </TransformGroup>
23新增: </Border.RenderTransform>
24新增: </Border>
25新增:
26新增: </Border>
27新增:
28新增: </ControlTemplate>
29新增: </Setter.Value>
30新增: </Setter>
31新增: </Style>
32新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/Button/Button.xaml+92 −0看文件
@@ -0,0 +1,92 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Button"
4新增: xmlns:base="clr-namespace:UI.Controls.Base"
5新增: xmlns:sys="clr-namespace:System;assembly=mscorlib">
6新增: <Style TargetType="{x:Type local:Button}">
7新增: <Setter Property="SnapsToDevicePixels"
8新增: Value="true" />
9新增: <Setter Property="UseLayoutRounding" Value="True"/>
10新增:
11新增: <!--<Setter Property="MinWidth" Value="150"/>-->
12新增: <Setter Property="Height" Value="35"/>
13新增: <Setter Property="Background" Value="Transparent"/>
14新增: <Setter Property="Template">
15新增: <Setter.Value>
16新增: <ControlTemplate TargetType="{x:Type local:Button}">
17新增: <Border Background="{TemplateBinding Background}" x:Name="Border">
18新增:
19新增: <Border BorderBrush="#f3f3f3" BorderThickness="1" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" x:Name="BoxBorder" CornerRadius="4" Background="White">
20新增: <Border.Effect>
21新增: <DropShadowEffect BlurRadius="5" ShadowDepth="2" Direction="315" Color="Gray" Opacity=".1"/>
22新增: </Border.Effect>
23新增: <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
24新增: <Grid.ColumnDefinitions>
25新增: <ColumnDefinition Width="auto"/>
26新增: <ColumnDefinition Width="auto"/>
27新增: </Grid.ColumnDefinitions>
28新增: <base:Icon x:Name="Icon" Margin="0,0,5,0" IconType="{TemplateBinding Icon}" VerticalAlignment="Center" FontSize="12" >
29新增:
30新增: </base:Icon>
31新增: <ContentPresenter
32新增: Grid.Column="1"
33新增: HorizontalAlignment="Center"
34新增: VerticalAlignment="Center"
35新增: RecognizesAccessKey="True"/>
36新增: </Grid>
37新增:
38新增: </Border>
39新增:
40新增: <VisualStateManager.VisualStateGroups>
41新增: <VisualStateGroup x:Name="CommonStates">
42新增: <VisualStateGroup.Transitions>
43新增: <VisualTransition GeneratedDuration="0:0:0.18" />
44新增: <VisualTransition GeneratedDuration="0"
45新增: To="Pressed" />
46新增: </VisualStateGroup.Transitions>
47新增: <VisualState x:Name="Normal" />
48新增: <VisualState x:Name="MouseOver">
49新增: <Storyboard>
50新增: <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Effect).(DropShadowEffect.Color)"
51新增: Storyboard.TargetName="BoxBorder">
52新增: <EasingColorKeyFrame KeyTime="0"
53新增: Value="#2b20d9" />
54新增: </ColorAnimationUsingKeyFrames>
55新增: <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
56新增: Storyboard.TargetName="BoxBorder">
57新增: <EasingColorKeyFrame KeyTime="0"
58新增: Value="#2b20d9" />
59新增: </ColorAnimationUsingKeyFrames>
60新增: <!--<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
61新增: Storyboard.TargetName="BoxBorder">
62新增: <EasingColorKeyFrame KeyTime="0"
63新增: Value="#2b20d9" />
64新增: </ColorAnimationUsingKeyFrames>
65新增: <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Button.Foreground).(SolidColorBrush.Color)"
66新增: >
67新增: <EasingColorKeyFrame KeyTime="0"
68新增: Value="White" />
69新增: </ColorAnimationUsingKeyFrames>-->
70新增: </Storyboard>
71新增: </VisualState>
72新增: <VisualState x:Name="Pressed">
73新增:
74新增: </VisualState>
75新增: </VisualStateGroup>
76新增: </VisualStateManager.VisualStateGroups>
77新增:
78新增: </Border>
79新增: <ControlTemplate.Triggers>
80新增: <Trigger Property="Icon" Value="None">
81新增: <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
82新增: </Trigger>
83新增: <Trigger Property="IsMouseOver" Value="True">
84新增: <Setter TargetName="BoxBorder" Property="BorderThickness" Value="0"/>
85新增: <Setter Property="Foreground" Value="White"/>
86新增: </Trigger>
87新增: </ControlTemplate.Triggers>
88新增: </ControlTemplate>
89新增: </Setter.Value>
90新增: </Setter>
91新增: </Style>
92新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/Button/IconButton.xaml+54 −0看文件
@@ -0,0 +1,54 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Button"
4新增: xmlns:base="clr-namespace:UI.Controls.Base"
5新增: xmlns:sys="clr-namespace:System;assembly=mscorlib">
6新增: <Style TargetType="{x:Type local:IconButton}">
7新增: <Setter Property="SnapsToDevicePixels"
8新增: Value="true" />
9新增: <Setter Property="Width" Value="35"/>
10新增: <Setter Property="Height" Value="35"/>
11新增: <Setter Property="Background" Value="Transparent"/>
12新增: <Setter Property="Template">
13新增: <Setter.Value>
14新增: <ControlTemplate TargetType="{x:Type local:IconButton}">
15新增: <Border Background="{TemplateBinding Background}" x:Name="Border">
16新增:
17新增: <Border Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" x:Name="BoxBorder" CornerRadius="4" Padding="5" Background="Transparent">
18新增: <base:Icon x:Name="Icon" IconType="{TemplateBinding Icon}" Foreground="#5c5c5c" VerticalAlignment="Center" FontSize="16" >
19新增:
20新增: </base:Icon>
21新增: </Border>
22新增:
23新增: <VisualStateManager.VisualStateGroups>
24新增: <VisualStateGroup x:Name="CommonStates">
25新增: <VisualStateGroup.Transitions>
26新增: <VisualTransition GeneratedDuration="0:0:0.15" />
27新增: <VisualTransition GeneratedDuration="0"
28新增: To="Pressed" />
29新增: </VisualStateGroup.Transitions>
30新增: <VisualState x:Name="Normal" />
31新增: <VisualState x:Name="MouseOver">
32新增: <Storyboard>
33新增: <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
34新增: Storyboard.TargetName="BoxBorder">
35新增: <EasingColorKeyFrame KeyTime="0"
36新增: Value="#eaeaea" />
37新增: </ColorAnimationUsingKeyFrames>
38新增: </Storyboard>
39新增: </VisualState>
40新增: <VisualState x:Name="Pressed">
41新增:
42新增: </VisualState>
43新增: </VisualStateGroup>
44新增: </VisualStateManager.VisualStateGroups>
45新增:
46新增: </Border>
47新增: <ControlTemplate.Triggers>
48新增:
49新增: </ControlTemplate.Triggers>
50新增: </ControlTemplate>
51新增: </Setter.Value>
52新增: </Setter>
53新增: </Style>
54新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/Charts/Charts.xaml+50 −0看文件
@@ -0,0 +1,50 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Charts">
4新增: <Style TargetType="{x:Type local:Charts}">
5新增: <Setter Property="SnapsToDevicePixels"
6新增: Value="true" />
7新增:
8新增:
9新增: <Setter Property="FontSize" Value="14"/>
10新增: <Setter Property="Background" Value="Transparent"/>
11新增:
12新增: <Setter Property="Template">
13新增: <Setter.Value>
14新增: <ControlTemplate TargetType="{x:Type local:Charts}">
15新增: <Border Background="{TemplateBinding Background}">
16新增: <Grid>
17新增: <Grid x:Name="HorizontalA" Visibility="Collapsed">
18新增: <StackPanel x:Name="Container">
19新增: </StackPanel>
20新增: </Grid>
21新增: <Grid x:Name="Card" Visibility="Collapsed">
22新增: <WrapPanel x:Name="CardContainer">
23新增: </WrapPanel>
24新增: </Grid>
25新增: <Grid x:Name="Month" Visibility="Collapsed">
26新增: <Grid x:Name="MonthContainer">
27新增: </Grid>
28新增: </Grid>
29新增: </Grid>
30新增: </Border>
31新增:
32新增: <ControlTemplate.Triggers>
33新增: <Trigger Property="ChartsType"
34新增: Value="HorizontalA">
35新增: <Setter TargetName="HorizontalA" Property="Visibility" Value="Visible"/>
36新增: </Trigger>
37新增: <Trigger Property="ChartsType"
38新增: Value="Card">
39新增: <Setter TargetName="Card" Property="Visibility" Value="Visible"/>
40新增: </Trigger>
41新增: <Trigger Property="ChartsType"
42新增: Value="Month">
43新增: <Setter TargetName="Month" Property="Visibility" Value="Visible"/>
44新增: </Trigger>
45新增: </ControlTemplate.Triggers>
46新增: </ControlTemplate>
47新增: </Setter.Value>
48新增: </Setter>
49新增: </Style>
50新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/Charts/ChartsItemTypeA.xaml+87 −0看文件
@@ -0,0 +1,87 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Charts"
4新增: xmlns:base="clr-namespace:UI.Controls.Base">
5新增: <Style TargetType="{x:Type local:ChartsItemTypeA}">
6新增: <Setter Property="SnapsToDevicePixels"
7新增: Value="true" />
8新增:
9新增: <Setter Property="Background" Value="Transparent"/>
10新增: <Setter Property="Margin" Value="0,5"/>
11新增:
12新增: <Setter Property="Template">
13新增: <Setter.Value>
14新增: <ControlTemplate TargetType="{x:Type local:ChartsItemTypeA}">
15新增: <Border Background="{TemplateBinding Background}">
16新增: <Grid>
17新增: <Grid x:Name="Normal">
18新增: <Grid.ColumnDefinitions>
19新增: <ColumnDefinition Width="auto"/>
20新增: <ColumnDefinition Width="*"/>
21新增: </Grid.ColumnDefinitions>
22新增: <Grid Margin="0,0,10,0">
23新增: <Border Background="#f3f3f3" CornerRadius="6" Width="50" Height="50" HorizontalAlignment="Left">
24新增: <Image x:Name="IconObj" Width="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
25新增: </Border>
26新增: </Grid>
27新增: <StackPanel Grid.Column="1" x:Name="ValueContainer" VerticalAlignment="Center" >
28新增: <TextBlock x:Name="NameTextObj" Foreground="#5c5c5c" HorizontalAlignment="Left"/>
29新增: <StackPanel Orientation="Horizontal" >
30新增: <Rectangle
31新增: x:Name="ValueBlockObj"
32新增: RadiusX="4"
33新增: RadiusY="4"
34新增: Fill="#cccccc"
35新增: Height="8"
36新增: VerticalAlignment="Center"
37新增: HorizontalAlignment="Left"
38新增: />
39新增:
40新增: <TextBlock x:Name="ValueTextObj" VerticalAlignment="Center" Foreground="#5c5c5c" FontSize="12" Margin="5,0,0,0"/>
41新增: </StackPanel>
42新增: </StackPanel>
43新增:
44新增: </Grid>
45新增:
46新增: <Grid x:Name="Loading" Visibility="Collapsed">
47新增: <Grid.ColumnDefinitions>
48新增: <ColumnDefinition Width="auto"/>
49新增: <ColumnDefinition Width="*"/>
50新增: </Grid.ColumnDefinitions>
51新增: <Grid Margin="0,0,10,0">
52新增:
53新增: <base:Placeholder CornerRadius="6" Width="50" Height="50" HorizontalAlignment="Left">
54新增: <!--<Rectangle Height="25" Fill="" Width="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>-->
55新增: </base:Placeholder>
56新增: </Grid>
57新增: <StackPanel Grid.Column="1" VerticalAlignment="Center" >
58新增: <base:Placeholder Width="100" Height="12" HorizontalAlignment="Left" Margin="0,0,0,6"/>
59新增: <StackPanel Orientation="Horizontal" >
60新增: <Rectangle
61新增: RadiusX="0"
62新增: RadiusY="0"
63新增: Fill="#e0e0e0"
64新增: Height="8"
65新增: Width="256"
66新增: VerticalAlignment="Center"
67新增: HorizontalAlignment="Left"
68新增: />
69新增:
70新增: <!--<TextBlock VerticalAlignment="Center" Foreground="#5c5c5c" FontSize="12" Margin="5,0,0,0"/>-->
71新增: </StackPanel>
72新增: </StackPanel>
73新增: </Grid>
74新增: </Grid>
75新增: </Border>
76新增:
77新增: <ControlTemplate.Triggers>
78新增: <Trigger Property="IsLoading" Value="True">
79新增: <Setter TargetName="Loading" Property="Visibility" Value="Visible"/>
80新增: <Setter TargetName="Normal" Property="Visibility" Value="Hidden"/>
81新增: </Trigger>
82新增: </ControlTemplate.Triggers>
83新增: </ControlTemplate>
84新增: </Setter.Value>
85新增: </Setter>
86新增: </Style>
87新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/Charts/ChartsItemTypeCard.xaml+80 −0看文件
@@ -0,0 +1,80 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Charts"
4新增: xmlns:base="clr-namespace:UI.Controls.Base">
5新增: <Style TargetType="{x:Type local:ChartsItemTypeCard}">
6新增: <Setter Property="SnapsToDevicePixels"
7新增: Value="true" />
8新增:
9新增: <Setter Property="Background" Value="Transparent"/>
10新增: <Setter Property="Margin" Value="5"/>
11新增:
12新增: <Setter Property="Template">
13新增: <Setter.Value>
14新增: <ControlTemplate TargetType="{x:Type local:ChartsItemTypeCard}">
15新增: <Grid >
16新增: <Grid x:Name="Normal">
17新增: <Border CornerRadius="12">
18新增: <!--<Border.Effect>
19新增: <DropShadowEffect BlurRadius="14" ShadowDepth="0" Direction="0" Opacity="0.05"/>
20新增: </Border.Effect>-->
21新增: <Border Margin="0" Background="White" CornerRadius="12" Width="150" Height="150" >
22新增:
23新增: <Border.Clip>
24新增: <RectangleGeometry RadiusX="12" RadiusY="12" Rect="0,0,150,150"/>
25新增: </Border.Clip>
26新增:
27新增: <Grid>
28新增: <Rectangle
29新增: x:Name="ValueBlockObj"
30新增:
31新增:
32新增: HorizontalAlignment="Stretch"
33新增: VerticalAlignment="Center"
34新增: >
35新增: <Rectangle.Effect>
36新增: <BlurEffect KernelType="Gaussian" Radius="100"/>
37新增: </Rectangle.Effect>
38新增: <Rectangle.Fill>
39新增: <LinearGradientBrush EndPoint="2,1" StartPoint="-2,0">
40新增: <GradientStop Color="White"/>
41新增: <GradientStop Color="#ff305b" Offset="1"/>
42新增: </LinearGradientBrush>
43新增: </Rectangle.Fill>
44新增: </Rectangle>
45新增: <Border VerticalAlignment="Center" HorizontalAlignment="Center">
46新增: <Image x:Name="IconObj" Width="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
47新增: </Border>
48新增:
49新增: <TextBlock x:Name="NameTextObj" Foreground="#5c5c5c" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="10"/>
50新增:
51新增: <Border VerticalAlignment="Top" CornerRadius="5" Padding="5" HorizontalAlignment="Left" Margin="10" >
52新增: <Border.Background>
53新增: <SolidColorBrush Color="#ff305b" Opacity="0.7"/>
54新增: </Border.Background>
55新增: <TextBlock x:Name="ValueTextObj" Foreground="White" FontSize="12" />
56新增:
57新增: </Border>
58新增:
59新增: </Grid>
60新增:
61新增: </Border>
62新增: </Border>
63新增:
64新增: </Grid>
65新增:
66新增: <Grid x:Name="Loading" Visibility="Collapsed">
67新增: <base:Placeholder CornerRadius="12" Width="150" Height="150"/>
68新增: </Grid>
69新增: </Grid>
70新增: <ControlTemplate.Triggers>
71新增: <Trigger Property="IsLoading" Value="True">
72新增: <Setter TargetName="Loading" Property="Visibility" Value="Visible"/>
73新增: <Setter TargetName="Normal" Property="Visibility" Value="Hidden"/>
74新增: </Trigger>
75新增: </ControlTemplate.Triggers>
76新增: </ControlTemplate>
77新增: </Setter.Value>
78新增: </Setter>
79新增: </Style>
80新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/Charts/ChartsItemTypeMonth.xaml+74 −0看文件
@@ -0,0 +1,74 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Charts"
4新增: xmlns:base="clr-namespace:UI.Controls.Base">
5新增: <Style TargetType="{x:Type local:ChartsItemTypeMonth}">
6新增: <Setter Property="SnapsToDevicePixels"
7新增: Value="true" />
8新增:
9新增: <Setter Property="Background" Value="Transparent"/>
10新增: <Setter Property="Margin" Value="5"/>
11新增: <Setter Property="HorizontalAlignment" Value="Center"/>
12新增: <Setter Property="VerticalAlignment" Value="Center"/>
13新增:
14新增: <Setter Property="Template">
15新增: <Setter.Value>
16新增: <ControlTemplate TargetType="{x:Type local:ChartsItemTypeMonth}">
17新增: <Grid >
18新增: <Grid x:Name="Normal">
19新增: <Border>
20新增: <!--<Border.Effect>
21新增: <DropShadowEffect BlurRadius="14" ShadowDepth="0" Direction="0" Opacity="0.05"/>
22新增: </Border.Effect>-->
23新增: <Border x:Name="Border" Margin="0" Background="#f3f3f3" CornerRadius="4" Width="20" Height="20" BorderThickness="0" BorderBrush="#2b20d9">
24新增:
25新增: <Border.Clip>
26新增: <RectangleGeometry RadiusX="4" RadiusY="4" Rect="0,0,20,20"/>
27新增: </Border.Clip>
28新增:
29新增: <Grid>
30新增: <!--<TextBlock x:Name="ValueTextObj"/>-->
31新增: <Rectangle
32新增: x:Name="ValueBlockObj"
33新增:
34新增:
35新增: HorizontalAlignment="Stretch"
36新增: VerticalAlignment="Center"
37新增: >
38新增: <Rectangle.Effect>
39新增: <BlurEffect KernelType="Gaussian" Radius="20"/>
40新增: </Rectangle.Effect>
41新增: <Rectangle.Fill>
42新增: <LinearGradientBrush EndPoint="2,1" StartPoint="-2,0">
43新增: <GradientStop Color="White"/>
44新增: <GradientStop Color="#ff305b" Offset="1"/>
45新增: </LinearGradientBrush>
46新增: </Rectangle.Fill>
47新增: </Rectangle>
48新增: </Grid>
49新增:
50新增: </Border>
51新增: </Border>
52新增:
53新增: </Grid>
54新增:
55新增: <Grid x:Name="Loading" Visibility="Collapsed">
56新增: <base:Placeholder CornerRadius="12" Width="150" Height="150"/>
57新增: </Grid>
58新增: </Grid>
59新增: <ControlTemplate.Triggers>
60新增: <Trigger Property="IsLoading" Value="True">
61新增: <Setter TargetName="Loading" Property="Visibility" Value="Visible"/>
62新增: <Setter TargetName="Normal" Property="Visibility" Value="Hidden"/>
63新增: </Trigger>
64新增: <Trigger Property="IsSelected" Value="True">
65新增: <Setter TargetName="Border" Property="BorderThickness" Value="1"/>
66新增: <Setter TargetName="Border" Property="Background" Value="White"/>
67新增:
68新增: </Trigger>
69新增: </ControlTemplate.Triggers>
70新增: </ControlTemplate>
71新增: </Setter.Value>
72新增: </Setter>
73新增: </Style>
74新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/DatePickerBar/DatePickerBar.xaml+36 −0看文件
@@ -0,0 +1,36 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.DatePickerBar"
4新增: xmlns:base="clr-namespace:UI.Controls.Base">
5新增: <Style TargetType="{x:Type local:DatePickerBar}">
6新增: <Setter Property="SnapsToDevicePixels"
7新增: Value="true" />
8新增:
9新增: <Setter Property="Background" Value="Transparent"/>
10新增: <Setter Property="Template">
11新增: <Setter.Value>
12新增: <ControlTemplate TargetType="{x:Type local:DatePickerBar}">
13新增: <Border>
14新增: <StackPanel>
15新增: <TextBlock Foreground="#5c5c5c" FontSize="15" Text="{TemplateBinding SelectedDateString}" HorizontalAlignment="Center" Margin="0,10"/>
16新增: <Grid>
17新增: <Border Background="White" Padding="10" CornerRadius="10">
18新增: <ScrollViewer x:Name="ScrollViewer" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden">
19新增: <StackPanel
20新增: Orientation="Horizontal"
21新增: x:Name="Container">
22新增:
23新增: </StackPanel>
24新增: </ScrollViewer>
25新增: </Border>
26新增: </Grid>
27新增: </StackPanel>
28新增: </Border>
29新增: <ControlTemplate.Triggers>
30新增:
31新增: </ControlTemplate.Triggers>
32新增: </ControlTemplate>
33新增: </Setter.Value>
34新增: </Setter>
35新增: </Style>
36新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/DatePickerBar/DatePickerBarItem.xaml+42 −0看文件
@@ -0,0 +1,42 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.DatePickerBar"
4新增: xmlns:base="clr-namespace:UI.Controls.Base">
5新增: <Style TargetType="{x:Type local:DatePickerBarItem}">
6新增: <Setter Property="SnapsToDevicePixels"
7新增: Value="true" />
8新增:
9新增: <Setter Property="Background" Value="Transparent"/>
10新增: <Setter Property="Template">
11新增: <Setter.Value>
12新增: <ControlTemplate TargetType="{x:Type local:DatePickerBarItem}">
13新增: <Border>
14新增:
15新增:
16新增: <Grid Margin="2">
17新增:
18新增: <Border x:Name="Bg" Background="#f9f9f9" Width="45" Height="45" CornerRadius="25">
19新增: <TextBlock x:Name="Text" Foreground="#5c5c5c" Text="{TemplateBinding Title}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
20新增: </Border>
21新增: </Grid>
22新增:
23新增: </Border>
24新增: <ControlTemplate.Triggers>
25新增: <Trigger Property="IsSelected"
26新增: Value="True">
27新增: <Setter TargetName="Bg" Property="Background" Value="#2b20d9"/>
28新增: <Setter TargetName="Text" Property="Foreground" Value="white"/>
29新增:
30新增: </Trigger>
31新增: <Trigger Property="IsDisabled"
32新增: Value="True">
33新增: <!--<Setter TargetName="Bg" Property="Background" Value="#2b20d9"/>-->
34新增: <Setter TargetName="Text" Property="Foreground" Value="#ccc"/>
35新增:
36新增: </Trigger>
37新增: </ControlTemplate.Triggers>
38新增: </ControlTemplate>
39新增: </Setter.Value>
40新增: </Setter>
41新增: </Style>
42新增:</ResourceDictionary>
文件末尾没有换行
修改UI/Themes/Generic.xaml+23 −2看文件
@@ -1,4 +1,4 @@
1删除:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
33 <ResourceDictionary.MergedDictionaries>
44 <ResourceDictionary Source="/Tai;component/Themes/Window/HideWindow.xaml" />
@@ -6,7 +6,28 @@
66 <ResourceDictionary Source="/Tai;component/Themes/Navigation/NavigationItem.xaml"/>
77 <ResourceDictionary Source="/Tai;component/Themes/Navigation/Navigation.xaml"/>
88 <ResourceDictionary Source="/Tai;component/Themes/Base/Icon.xaml"/>
9新增: <ResourceDictionary Source="/Tai;component/Themes/Base/Placeholder.xaml"/>
10新增: <ResourceDictionary Source="/Tai;component/Themes/Base/EmptyData.xaml"/>
11新增:
912 <ResourceDictionary Source="/Tai;component/Themes/PageContainer.xaml"/>
13新增: <ResourceDictionary Source="/Tai;component/Themes/Charts/Charts.xaml"/>
14新增: <ResourceDictionary Source="/Tai;component/Themes/Charts/ChartsItemTypeA.xaml"/>
15新增: <ResourceDictionary Source="/Tai;component/Themes/Charts/ChartsItemTypeCard.xaml"/>
16新增: <ResourceDictionary Source="/Tai;component/Themes/Charts/ChartsItemTypeMonth.xaml"/>
17新增:
18新增: <ResourceDictionary Source="/Tai;component/Themes/Tabbar/Tabbar.xaml"/>
19新增: <ResourceDictionary Source="/Tai;component/Themes/DatePickerBar/DatePickerBar.xaml"/>
20新增: <ResourceDictionary Source="/Tai;component/Themes/DatePickerBar/DatePickerBarItem.xaml"/>
21新增: <ResourceDictionary Source="/Tai;component/Themes/SettingPanel/SettingPanel.xaml"/>
22新增: <ResourceDictionary Source="/Tai;component/Themes/Toggle/Toggle.xaml"/>
23新增: <ResourceDictionary Source="/Tai;component/Themes/SettingPanel/SettingPanelItem.xaml"/>
24新增: <ResourceDictionary Source="/Tai;component/Themes/SettingPanel/SettingPanelMultiItem.xaml"/>
25新增: <ResourceDictionary Source="/Tai;component/Themes/Input/InputBox.xaml"/>
26新增: <ResourceDictionary Source="/Tai;component/Themes/Button/IconButton.xaml"/>
27新增: <ResourceDictionary Source="/Tai;component/Themes/Button/Button.xaml"/>
28新增: <ResourceDictionary Source="/Tai;component/Themes/List/BaseList.xaml"/>
29新增: <ResourceDictionary Source="/Tai;component/Themes/List/BaseListItem.xaml"/>
1030
1131 </ResourceDictionary.MergedDictionaries>
12删除:</ResourceDictionary>
文件末尾没有换行
32新增:
33新增:</ResourceDictionary>
新增UI/Themes/Input/InputBox.xaml+59 −0看文件
@@ -0,0 +1,59 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Input"
4新增: xmlns:base="clr-namespace:UI.Controls.Base"
5新增: xmlns:sys="clr-namespace:System;assembly=mscorlib">
6新增: <Style TargetType="{x:Type local:InputBox}">
7新增: <Setter Property="SnapsToDevicePixels"
8新增: Value="true" />
9新增: <Setter Property="Width" Value="auto"/>
10新增:
11新增: <Setter Property="Height" Value="35"/>
12新增: <Setter Property="Cursor" Value="IBeam"/>
13新增:
14新增: <Setter Property="Background" Value="Transparent"/>
15新增: <Setter Property="Template">
16新增: <Setter.Value>
17新增: <ControlTemplate TargetType="{x:Type local:InputBox}">
18新增: <Border Background="{TemplateBinding Background}" x:Name="Border">
19新增:
20新增: <Grid>
21新增: <Border x:Name="BoxBorder" BorderBrush="#a3a3a3" BorderThickness="2" CornerRadius="4">
22新增: <Grid>
23新增: <TextBlock Margin="5,0" x:Name="Placeholder" Text="{TemplateBinding Placeholder}" Foreground="#a3a3a3" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="Center" Visibility="Collapsed"/>
24新增: <ScrollViewer Margin="5,0"
25新增: x:Name="PART_ContentHost" VerticalAlignment="Center"/>
26新增: </Grid>
27新增:
28新增: </Border>
29新增:
30新增:
31新增: </Grid>
32新增: <VisualStateManager.VisualStateGroups>
33新增: <VisualStateGroup Name="FocusStates">
34新增: <VisualState Name="Unfocused"/>
35新增: <!--Right here-->
36新增: <VisualState Name="Focused">
37新增: <Storyboard>
38新增: <ColorAnimation Storyboard.TargetName="BoxBorder" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"
39新增: To="#2b20d9"
40新增: Duration="0:0:.4">
41新增: <ColorAnimation.EasingFunction>
42新增: <QuadraticEase/>
43新增: </ColorAnimation.EasingFunction>
44新增: </ColorAnimation>
45新增: </Storyboard>
46新增: </VisualState>
47新增: </VisualStateGroup>
48新增: </VisualStateManager.VisualStateGroups>
49新增: </Border>
50新增: <ControlTemplate.Triggers>
51新增: <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value="{x:Static sys:String.Empty}">
52新增: <Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
53新增: </DataTrigger>
54新增: </ControlTemplate.Triggers>
55新增: </ControlTemplate>
56新增: </Setter.Value>
57新增: </Setter>
58新增: </Style>
59新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/List/BaseList.xaml+38 −0看文件
@@ -0,0 +1,38 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.List"
4新增: xmlns:base="clr-namespace:UI.Controls.Base"
5新增: xmlns:sys="clr-namespace:System;assembly=mscorlib">
6新增: <Style TargetType="{x:Type local:BaseList}">
7新增: <Setter Property="SnapsToDevicePixels"
8新增: Value="true" />
9新增: <Setter Property="UseLayoutRounding" Value="True"/>
10新增:
11新增: <!--<Setter Property="MinWidth" Value="150"/>-->
12新增: <Setter Property="Height" Value="auto"/>
13新增: <Setter Property="Background" Value="Transparent"/>
14新增: <Setter Property="Template">
15新增: <Setter.Value>
16新增: <ControlTemplate TargetType="{x:Type local:BaseList}">
17新增: <Border Background="{TemplateBinding Background}" x:Name="Border">
18新增:
19新增: <Grid>
20新增: <StackPanel x:Name="Container">
21新增:
22新增: </StackPanel>
23新增: </Grid>
24新增:
25新增: </Border>
26新增: <ControlTemplate.Triggers>
27新增: <!--<Trigger Property="Icon" Value="None">
28新增: <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
29新增: </Trigger>
30新增: <Trigger Property="IsMouseOver" Value="True">
31新增: <Setter TargetName="BoxBorder" Property="BorderThickness" Value="0"/>
32新增: </Trigger>-->
33新增: </ControlTemplate.Triggers>
34新增: </ControlTemplate>
35新增: </Setter.Value>
36新增: </Setter>
37新增: </Style>
38新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/List/BaseListItem.xaml+83 −0看文件
@@ -0,0 +1,83 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.List"
4新增: xmlns:base="clr-namespace:UI.Controls.Base"
5新增: xmlns:sys="clr-namespace:System;assembly=mscorlib">
6新增: <Style TargetType="{x:Type local:BaseListItem}">
7新增: <Setter Property="SnapsToDevicePixels"
8新增: Value="true" />
9新增: <Setter Property="UseLayoutRounding" Value="True"/>
10新增:
11新增: <!--<Setter Property="MinWidth" Value="150"/>-->
12新增: <Setter Property="Height" Value="35"/>
13新增: <Setter Property="Margin" Value="0,10,0,0"/>
14新增:
15新增: <Setter Property="Background" Value="Transparent"/>
16新增: <Setter Property="Template">
17新增: <Setter.Value>
18新增: <ControlTemplate TargetType="{x:Type local:BaseListItem}">
19新增: <Border Background="{TemplateBinding Background}" x:Name="Border">
20新增:
21新增: <Border BorderBrush="#f3f3f3" BorderThickness="1" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" x:Name="BoxBorder" CornerRadius="4" Background="White" >
22新增: <Border.Effect>
23新增: <DropShadowEffect BlurRadius="5" ShadowDepth="2" Direction="315" Color="#ccc" Opacity=".05"/>
24新增: </Border.Effect>
25新增: <Grid VerticalAlignment="Center" Margin="10,0">
26新增: <Grid.ColumnDefinitions>
27新增: <ColumnDefinition Width="9*"/>
28新增: <ColumnDefinition Width="1*"/>
29新增: </Grid.ColumnDefinitions>
30新增: <TextBlock Text="{TemplateBinding Text}"/>
31新增: </Grid>
32新增:
33新增: </Border>
34新增:
35新增: <VisualStateManager.VisualStateGroups>
36新增: <VisualStateGroup x:Name="CommonStates">
37新增: <VisualStateGroup.Transitions>
38新增: <VisualTransition GeneratedDuration="0:0:0.18" />
39新增: <VisualTransition GeneratedDuration="0"
40新增: To="Pressed" />
41新增: </VisualStateGroup.Transitions>
42新增: <VisualState x:Name="Normal" />
43新增: <VisualState x:Name="MouseOver">
44新增: <Storyboard>
45新增: <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Effect).(DropShadowEffect.Color)"
46新增: Storyboard.TargetName="BoxBorder">
47新增: <EasingColorKeyFrame KeyTime="0"
48新增: Value="#2b20d9"/>
49新增: </ColorAnimationUsingKeyFrames>
50新增: <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
51新增: Storyboard.TargetName="BoxBorder">
52新增: <EasingColorKeyFrame KeyTime="0"
53新增: Value="#192B20D9" />
54新增: </ColorAnimationUsingKeyFrames>
55新增: <!--<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Button.Foreground).(SolidColorBrush.Color)"
56新增: >
57新增: <EasingColorKeyFrame KeyTime="0"
58新增: Value="White" />
59新增: </ColorAnimationUsingKeyFrames>-->
60新增: </Storyboard>
61新增: </VisualState>
62新增: <VisualState x:Name="Pressed">
63新增:
64新增: </VisualState>
65新增: </VisualStateGroup>
66新增: </VisualStateManager.VisualStateGroups>
67新增:
68新增: </Border>
69新增: <ControlTemplate.Triggers>
70新增: <Trigger Property="IsSelected" Value="True">
71新增: <Setter TargetName="BoxBorder" Property="Background" Value="#2b20d9"/>
72新增: <Setter Property="Foreground" Value="White"/>
73新增:
74新增: </Trigger>
75新增: <!--<Trigger Property="IsMouseOver" Value="True">
76新增: <Setter TargetName="BoxBorder" Property="BorderThickness" Value="0"/>
77新增: </Trigger>-->
78新增: </ControlTemplate.Triggers>
79新增: </ControlTemplate>
80新增: </Setter.Value>
81新增: </Setter>
82新增: </Style>
83新增:</ResourceDictionary>
文件末尾没有换行
修改UI/Themes/Navigation/Navigation.xaml+1 −1看文件
@@ -21,7 +21,7 @@
2121 </Grid.RowDefinitions>
2222 <ContentPresenter Content="{TemplateBinding TopExtContent}"/>
2323 <Grid Grid.Row="1" Background="Transparent" x:Name="MenuGrid">
24删除: <Border x:Name="ActiveBlock" Width="5" Height="25" CornerRadius="2" Background="#0067c0" HorizontalAlignment="Left" VerticalAlignment="Top" Panel.ZIndex="9" RenderTransformOrigin="0,0">
24新增: <Border x:Name="ActiveBlock" Width="5" Height="25" CornerRadius="2" Background="#2b20d9" HorizontalAlignment="Left" VerticalAlignment="Top" Panel.ZIndex="9" RenderTransformOrigin="0,0">
2525 <Border.RenderTransform>
2626 <TransformGroup>
2727 <TranslateTransform X="0" Y="0"></TranslateTransform>
修改UI/Themes/Navigation/NavigationItem.xaml+1 −1看文件
@@ -79,7 +79,7 @@
7979 </Trigger>
8080 <Trigger Property="IsSelected" Value="True">
8181 <!--<Setter Property="Background" Value="White"/>-->
82删除: <Setter TargetName="Title" Property="Foreground" Value="#0067c0"/>
82新增: <Setter TargetName="Title" Property="Foreground" Value="#2b20d9"/>
8383 <Setter TargetName="Title" Property="Visibility" Value="Collapsed"/>
8484
8585 <!--<Setter Property="Visibility" TargetName="CheckMark" Value="Visible"/>-->
新增UI/Themes/SettingPanel/SettingPanel.xaml+26 −0看文件
@@ -0,0 +1,26 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.SettingPanel"
4新增: xmlns:base="clr-namespace:UI.Controls.Base">
5新增: <Style TargetType="{x:Type local:SettingPanel}">
6新增: <Setter Property="SnapsToDevicePixels"
7新增: Value="true" />
8新增:
9新增: <Setter Property="Background" Value="Transparent"/>
10新增: <Setter Property="Template">
11新增: <Setter.Value>
12新增: <ControlTemplate TargetType="{x:Type local:SettingPanel}">
13新增: <Border Background="{TemplateBinding Background}" CornerRadius="5" x:Name="Border">
14新增: <StackPanel x:Name="Container">
15新增:
16新增: </StackPanel>
17新增:
18新增: </Border>
19新增: <ControlTemplate.Triggers>
20新增:
21新增: </ControlTemplate.Triggers>
22新增: </ControlTemplate>
23新增: </Setter.Value>
24新增: </Setter>
25新增: </Style>
26新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/SettingPanel/SettingPanelItem.xaml+47 −0看文件
@@ -0,0 +1,47 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.SettingPanel"
4新增: xmlns:base="clr-namespace:UI.Controls.Base">
5新增: <Style TargetType="{x:Type local:SettingPanelItem}">
6新增: <Setter Property="SnapsToDevicePixels"
7新增: Value="true" />
8新增:
9新增: <Setter Property="Background" Value="Transparent"/>
10新增: <Setter Property="Template">
11新增: <Setter.Value>
12新增: <ControlTemplate TargetType="{x:Type local:SettingPanelItem}">
13新增: <Border Background="{TemplateBinding Background}" Margin="15,16" x:Name="Border">
14新增:
15新增: <Grid>
16新增: <Grid.ColumnDefinitions>
17新增: <ColumnDefinition Width="8*"/>
18新增: <ColumnDefinition Width="2*"/>
19新增:
20新增: </Grid.ColumnDefinitions>
21新增:
22新增: <Grid>
23新增: <StackPanel VerticalAlignment="Center" HorizontalAlignment="Left">
24新增: <TextBlock Text="{TemplateBinding Name}" FontSize="14" Foreground="#060606"/>
25新增: <TextBlock Text="{TemplateBinding Description}" FontSize="12" Margin="0,4,0,0" Foreground="#989CA1"/>
26新增: </StackPanel>
27新增: </Grid>
28新增: <Grid Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right">
29新增: <Border HorizontalAlignment="Left">
30新增: <ContentPresenter HorizontalAlignment="Center"
31新增: VerticalAlignment="Center"
32新增: RecognizesAccessKey="True"
33新增: SnapsToDevicePixels="False" Content="{TemplateBinding Content}"
34新增: />
35新增: </Border>
36新增: </Grid>
37新增: </Grid>
38新增:
39新增: </Border>
40新增: <ControlTemplate.Triggers>
41新增:
42新增: </ControlTemplate.Triggers>
43新增: </ControlTemplate>
44新增: </Setter.Value>
45新增: </Setter>
46新增: </Style>
47新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/SettingPanel/SettingPanelMultiItem.xaml+53 −0看文件
@@ -0,0 +1,53 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.SettingPanel"
4新增: xmlns:base="clr-namespace:UI.Controls.Base"
5新增: xmlns:btn="clr-namespace:UI.Controls.Button">
6新增: <Style TargetType="{x:Type local:SettingPanelMultiItem}">
7新增: <Setter Property="SnapsToDevicePixels"
8新增: Value="true" />
9新增: <Setter Property="Margin" Value="0,0,0,20"/>
10新增:
11新增: <Setter Property="Background" Value="White"/>
12新增: <Setter Property="Template">
13新增: <Setter.Value>
14新增: <ControlTemplate TargetType="{x:Type local:SettingPanelMultiItem}">
15新增: <Border Background="{TemplateBinding Background}" x:Name="Border" CornerRadius="6" >
16新增:
17新增: <Grid>
18新增: <Grid.RowDefinitions>
19新增: <RowDefinition Height="auto"/>
20新增: <RowDefinition Height="*"/>
21新增:
22新增: </Grid.RowDefinitions>
23新增: <Grid Margin="10,10,10,10">
24新增: <TextBlock Text="{TemplateBinding Title}" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="16" FontWeight="Bold"/>
25新增:
26新增: <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
27新增: <btn:IconButton ToolTip="收起" x:Name="FoldBtn" Command="{TemplateBinding OnFoldAction}" Icon="ChevronUp" Margin="0"></btn:IconButton>
28新增: <btn:IconButton Icon="Delete" Command="{TemplateBinding OnRemoveAction}" ToolTip="移除此项"></btn:IconButton>
29新增: </StackPanel>
30新增:
31新增: </Grid>
32新增: <StackPanel x:Name="Container" Grid.Row="1">
33新增:
34新增: </StackPanel>
35新增:
36新增: </Grid>
37新增:
38新增: </Border>
39新增: <ControlTemplate.Triggers>
40新增: <Trigger Property="Fold"
41新增: Value="True">
42新增: <Setter TargetName="Container" Property="Visibility" Value="Collapsed"/>
43新增: </Trigger>
44新增: <Trigger Property="Fold"
45新增: Value="False">
46新增: <Setter TargetName="Container" Property="Visibility" Value="Visible"/>
47新增: </Trigger>
48新增: </ControlTemplate.Triggers>
49新增: </ControlTemplate>
50新增: </Setter.Value>
51新增: </Setter>
52新增: </Style>
53新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/Tabbar/Tabbar.xaml+34 −0看文件
@@ -0,0 +1,34 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Tabbar"
4新增: >
5新增: <Style TargetType="{x:Type local:Tabbar}">
6新增: <Setter Property="SnapsToDevicePixels"
7新增: Value="true" />
8新增: <Setter Property="MinWidth" Value="44"/>
9新增: <Setter Property="Height" Value="auto"/>
10新增: <Setter Property="Background" Value="Transparent"/>
11新增: <Setter Property="Template">
12新增: <Setter.Value>
13新增: <ControlTemplate TargetType="{x:Type local:Tabbar}">
14新增: <Border Background="{TemplateBinding Background}">
15新增: <Grid>
16新增: <Border x:Name="ActiveBlock" Width="35" Height="4" CornerRadius="2" Background="#2b20d9" HorizontalAlignment="Left" VerticalAlignment="Top" Panel.ZIndex="9" RenderTransformOrigin="0,0">
17新增: <Border.RenderTransform>
18新增: <TransformGroup>
19新增: <TranslateTransform X="0" Y="0"></TranslateTransform>
20新增: <ScaleTransform CenterX="0" CenterY="0" ScaleY="1"/>
21新增: </TransformGroup>
22新增: </Border.RenderTransform>
23新增: </Border>
24新增: <Border Height="30" Margin="0,10,0,20">
25新增: <StackPanel Orientation="Horizontal" x:Name="ItemsPanel" VerticalAlignment="Bottom"/>
26新增: </Border>
27新增: </Grid>
28新增: </Border>
29新增:
30新增: </ControlTemplate>
31新增: </Setter.Value>
32新增: </Setter>
33新增: </Style>
34新增:</ResourceDictionary>
文件末尾没有换行
新增UI/Themes/Toggle/Toggle.xaml+78 −0看文件
@@ -0,0 +1,78 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Toggle">
4新增:
5新增: <Style TargetType="{x:Type local:Toggle}">
6新增: <Setter Property="Width" Value="auto"/>
7新增: <Setter Property="Height" Value="22"/>
8新增: <Setter Property="Cursor" Value="Hand"/>
9新增:
10新增: <Setter Property="Background" Value="Transparent"/>
11新增: <Setter Property="Template">
12新增: <Setter.Value>
13新增: <ControlTemplate TargetType="{x:Type local:Toggle}">
14新增: <Border x:Name="Border" Background="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" CornerRadius="4" Margin="{TemplateBinding Margin}">
15新增: <Grid>
16新增: <Grid.ColumnDefinitions>
17新增: <ColumnDefinition Width="50"/>
18新增: <ColumnDefinition Width="*"/>
19新增: </Grid.ColumnDefinitions>
20新增: <Border x:Name="Button" Background="#f5f5f5" CornerRadius="10" Padding="5">
21新增: <Border x:Name="Mark" Width="12" Height="12" CornerRadius="15" Background="#5d5d5d" VerticalAlignment="Center" HorizontalAlignment="Left">
22新增: <Border.RenderTransform>
23新增: <TranslateTransform X="0"/>
24新增: </Border.RenderTransform>
25新增: </Border>
26新增: </Border>
27新增: <TextBlock x:Name="Text" Grid.Column="1" VerticalAlignment="Center" Margin="10,0,0,0" Text="{TemplateBinding Text}"/>
28新增: </Grid>
29新增:
30新增: <VisualStateManager.VisualStateGroups>
31新增: <VisualStateGroup x:Name="CommonStates">
32新增: <VisualState x:Name="On">
33新增: <Storyboard>
34新增: <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.RenderTransform).
35新增: (TranslateTransform.X)"
36新增: Storyboard.TargetName="Mark">
37新增: <EasingDoubleKeyFrame KeyTime="00:00:0.2"
38新增: Value="28" />
39新增: </DoubleAnimationUsingKeyFrames>
40新增: <!--更改标记点颜色-->
41新增: <ColorAnimationUsingKeyFrames
42新增: Storyboard.TargetName="Mark"
43新增: Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
44新增: <EasingColorKeyFrame KeyTime="00:00:0.2"
45新增: Value="White"/>
46新增: </ColorAnimationUsingKeyFrames>
47新增: <!--更改背景颜色-->
48新增: <ColorAnimationUsingKeyFrames
49新增: Storyboard.TargetName="Button"
50新增: Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
51新增: <EasingColorKeyFrame KeyTime="00:00:0.2"
52新增: Value="#2b20d9"/>
53新增: </ColorAnimationUsingKeyFrames>
54新增: </Storyboard>
55新增: </VisualState>
56新增: <VisualState x:Name="Off">
57新增: <Storyboard>
58新增: <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.RenderTransform).
59新增: (TranslateTransform.X)"
60新增: Storyboard.TargetName="Mark">
61新增: <EasingDoubleKeyFrame KeyTime="00:00:0.2"
62新增: Value="0" />
63新增: </DoubleAnimationUsingKeyFrames>
64新增: </Storyboard>
65新增: </VisualState>
66新增: </VisualStateGroup>
67新增: </VisualStateManager.VisualStateGroups>
68新增: </Border>
69新增: <ControlTemplate.Triggers>
70新增:
71新增: </ControlTemplate.Triggers>
72新增:
73新增: </ControlTemplate>
74新增: </Setter.Value>
75新增: </Setter>
76新增:
77新增: </Style>
78新增:</ResourceDictionary>
文件末尾没有换行
修改UI/Themes/Window/DefaultWindow.xaml+4 −4看文件
@@ -28,14 +28,14 @@
2828 <!--<Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}"/>-->
2929 </Trigger>
3030 <Trigger Property="IsMouseOver" Value="True">
31删除: <Setter Property="Background" Value="{DynamicResource StandardMouseHoverBrush}" />
31新增: <Setter Property="Background" Value="#eaeaea" />
3232 <Setter Property="Foreground" Value="{DynamicResource PrimaryColorBrush}"/>
3333 </Trigger>
3434 <Trigger Property="IsPressed" Value="True">
35删除: <Setter Property="Background" Value="{DynamicResource StandardMousePressedBrush}" />
35新增: <Setter Property="Background" Value="#2b20d9" />
3636 <!--<Setter Property="Background" Value="{DynamicResource ButtonBackgroundPressed}" />
37删除: <Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderPressed}"/>
38删除: <Setter Property="Foreground" Value="{DynamicResource ButtonTextPressed}"/>-->
37新增: <Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderPressed}"/>-->
38新增: <Setter Property="Foreground" Value="White"/>
3939 </Trigger>
4040 <Trigger Property="IsFocused" Value="true">
4141 <!--<Setter TargetName="Chrome" Property="BorderBrush" Value="{DynamicResource Accent}" />-->
修改UI/UI.csproj+175 −3看文件
@@ -14,6 +14,21 @@
1414 <WarningLevel>4</WarningLevel>
1515 <Deterministic>true</Deterministic>
1616 <TargetFrameworkProfile />
17新增: <PublishUrl>publish\</PublishUrl>
18新增: <Install>true</Install>
19新增: <InstallFrom>Disk</InstallFrom>
20新增: <UpdateEnabled>false</UpdateEnabled>
21新增: <UpdateMode>Foreground</UpdateMode>
22新增: <UpdateInterval>7</UpdateInterval>
23新增: <UpdateIntervalUnits>Days</UpdateIntervalUnits>
24新增: <UpdatePeriodically>false</UpdatePeriodically>
25新增: <UpdateRequired>false</UpdateRequired>
26新增: <MapFileExtensions>true</MapFileExtensions>
27新增: <ApplicationRevision>0</ApplicationRevision>
28新增: <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
29新增: <IsWebBootstrapper>false</IsWebBootstrapper>
30新增: <UseApplicationTrust>false</UseApplicationTrust>
31新增: <BootstrapperEnabled>true</BootstrapperEnabled>
1732 </PropertyGroup>
1833 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1934 <PlatformTarget>AnyCPU</PlatformTarget>
@@ -35,7 +50,27 @@
3550 <WarningLevel>4</WarningLevel>
3651 </PropertyGroup>
3752 <PropertyGroup>
38删除: <ApplicationIcon>TextTemplate.ico</ApplicationIcon>
53新增: <ApplicationIcon>Resources\Icons\tai.ico</ApplicationIcon>
54新增: </PropertyGroup>
55新增: <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
56新增: <DebugSymbols>true</DebugSymbols>
57新增: <OutputPath>bin\x64\Debug\</OutputPath>
58新增: <DefineConstants>DEBUG;TRACE</DefineConstants>
59新增: <DebugType>full</DebugType>
60新增: <PlatformTarget>x64</PlatformTarget>
61新增: <LangVersion>7.3</LangVersion>
62新增: <ErrorReport>prompt</ErrorReport>
63新增: <Prefer32Bit>true</Prefer32Bit>
64新增: </PropertyGroup>
65新增: <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
66新增: <OutputPath>bin\x64\Release\</OutputPath>
67新增: <DefineConstants>TRACE</DefineConstants>
68新增: <Optimize>true</Optimize>
69新增: <DebugType>pdbonly</DebugType>
70新增: <PlatformTarget>x64</PlatformTarget>
71新增: <LangVersion>7.3</LangVersion>
72新增: <ErrorReport>prompt</ErrorReport>
73新增: <Prefer32Bit>true</Prefer32Bit>
3974 </PropertyGroup>
4075 <ItemGroup>
4176 <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
@@ -80,18 +115,59 @@
80115 </ApplicationDefinition>
81116 <Compile Include="Base\Color\Colors.cs" />
82117 <Compile Include="Base\Color\ColorTypes.cs" />
118新增: <Compile Include="Controls\Base\EmptyData.cs" />
119新增: <Compile Include="Controls\Base\Placeholder.cs" />
83120 <Compile Include="Controls\Base\Icon.cs" />
84121 <Compile Include="Controls\Base\IconConverter.cs" />
85122 <Compile Include="Controls\Base\IconTypes.cs" />
123新增: <Compile Include="Controls\Button\Button.cs" />
124新增: <Compile Include="Controls\Button\IconButton.cs" />
125新增: <Compile Include="Controls\Charts\ChartsItemTypeMonth.cs" />
126新增: <Compile Include="Controls\Charts\ChartsItemTypeCard.cs" />
127新增: <Compile Include="Controls\Charts\ChartsItemTypeA.cs" />
128新增: <Compile Include="Controls\Charts\Charts.cs" />
129新增: <Compile Include="Controls\Charts\ChartsType.cs" />
130新增: <Compile Include="Controls\Charts\Model\ChartsDataModel.cs" />
131新增: <Compile Include="Controls\DatePickerBar\DatePickerBarItem.cs" />
132新增: <Compile Include="Controls\DatePickerBar\DatePickerShowType.cs" />
133新增: <Compile Include="Controls\Input\InputBox.cs" />
134新增: <Compile Include="Controls\List\BaseList.cs" />
135新增: <Compile Include="Controls\List\BaseListItem.cs" />
86136 <Compile Include="Controls\Navigation\Models\NavigationItemModel.cs" />
87137 <Compile Include="Controls\Navigation\Navigation.cs" />
88138 <Compile Include="Controls\Navigation\NavigationItem.cs" />
139新增: <Compile Include="Controls\DatePickerBar\DatePickerBar.cs" />
140新增: <Compile Include="Controls\SettingPanel\SettingPanelMultiItem.cs" />
141新增: <Compile Include="Controls\SettingPanel\SettingPanelItem.cs" />
142新增: <Compile Include="Controls\SettingPanel\SettingPanel.cs" />
143新增: <Compile Include="Controls\Tabbar\Tabbar.cs" />
144新增: <Compile Include="Controls\Toggle\Toggle.cs" />
145新增: <Compile Include="Extensions\ListExtensions.cs" />
146新增: <Compile Include="Librays\Image\Imager.cs" />
147新增: <Compile Include="Librays\Timer.cs" />
148新增: <Compile Include="Models\DataPageModel.cs" />
149新增: <Compile Include="Models\DetailPageModel.cs" />
150新增: <Compile Include="Models\IndexPageModel.cs" />
89151 <Compile Include="Models\MainWindowModel.cs" />
152新增: <Compile Include="Models\SettingPageModel.cs" />
90153 <Compile Include="Models\UINotifyPropertyChanged.cs" />
154新增: <Compile Include="ViewModels\DataPageVM.cs" />
155新增: <Compile Include="ViewModels\DetailPageVM.cs" />
156新增: <Compile Include="ViewModels\IndexPageVM.cs" />
91157 <Compile Include="ViewModels\MainViewModel.cs" />
158新增: <Compile Include="ViewModels\SettingPageVM.cs" />
159新增: <Compile Include="Views\DataPage.xaml.cs">
160新增: <DependentUpon>DataPage.xaml</DependentUpon>
161新增: </Compile>
162新增: <Compile Include="Views\DetailPage.xaml.cs">
163新增: <DependentUpon>DetailPage.xaml</DependentUpon>
164新增: </Compile>
92165 <Compile Include="Views\IndexPage.xaml.cs">
93166 <DependentUpon>IndexPage.xaml</DependentUpon>
94167 </Compile>
168新增: <Compile Include="Views\SettingPage.xaml.cs">
169新增: <DependentUpon>SettingPage.xaml</DependentUpon>
170新增: </Compile>
95171 <Page Include="MainWindow.xaml">
96172 <Generator>MSBuild:Compile</Generator>
97173 <SubType>Designer</SubType>
@@ -109,14 +185,82 @@
109185 <DependentUpon>MainWindow.xaml</DependentUpon>
110186 <SubType>Code</SubType>
111187 </Compile>
188新增: <Page Include="Themes\Base\EmptyData.xaml">
189新增: <Generator>MSBuild:Compile</Generator>
190新增: <SubType>Designer</SubType>
191新增: </Page>
192新增: <Page Include="Themes\Base\Placeholder.xaml">
193新增: <Generator>MSBuild:Compile</Generator>
194新增: <SubType>Designer</SubType>
195新增: </Page>
112196 <Page Include="Themes\Base\Icon.xaml">
113197 <Generator>MSBuild:Compile</Generator>
114198 <SubType>Designer</SubType>
115199 </Page>
200新增: <Page Include="Themes\Button\Button.xaml">
201新增: <Generator>MSBuild:Compile</Generator>
202新增: <SubType>Designer</SubType>
203新增: </Page>
204新增: <Page Include="Themes\Charts\ChartsItemTypeMonth.xaml">
205新增: <Generator>MSBuild:Compile</Generator>
206新增: <SubType>Designer</SubType>
207新增: </Page>
208新增: <Page Include="Themes\Charts\ChartsItemTypeCard.xaml">
209新增: <Generator>MSBuild:Compile</Generator>
210新增: <SubType>Designer</SubType>
211新增: </Page>
212新增: <Page Include="Themes\Charts\ChartsItemTypeA.xaml">
213新增: <Generator>MSBuild:Compile</Generator>
214新增: <SubType>Designer</SubType>
215新增: </Page>
216新增: <Page Include="Themes\Charts\Charts.xaml">
217新增: <Generator>MSBuild:Compile</Generator>
218新增: <SubType>Designer</SubType>
219新增: </Page>
220新增: <Page Include="Themes\DatePickerBar\DatePickerBar.xaml">
221新增: <Generator>MSBuild:Compile</Generator>
222新增: <SubType>Designer</SubType>
223新增: </Page>
224新增: <Page Include="Themes\DatePickerBar\DatePickerBarItem.xaml">
225新增: <Generator>MSBuild:Compile</Generator>
226新增: <SubType>Designer</SubType>
227新增: </Page>
116228 <Page Include="Themes\Generic.xaml">
117229 <SubType>Designer</SubType>
118230 <Generator>MSBuild:Compile</Generator>
119231 </Page>
232新增: <Page Include="Themes\Button\IconButton.xaml">
233新增: <Generator>MSBuild:Compile</Generator>
234新增: <SubType>Designer</SubType>
235新增: </Page>
236新增: <Page Include="Themes\Input\InputBox.xaml">
237新增: <Generator>MSBuild:Compile</Generator>
238新增: <SubType>Designer</SubType>
239新增: </Page>
240新增: <Page Include="Themes\List\BaseListItem.xaml">
241新增: <Generator>MSBuild:Compile</Generator>
242新增: <SubType>Designer</SubType>
243新增: </Page>
244新增: <Page Include="Themes\List\BaseList.xaml">
245新增: <Generator>MSBuild:Compile</Generator>
246新增: <SubType>Designer</SubType>
247新增: </Page>
248新增: <Page Include="Themes\SettingPanel\SettingPanelMultiItem.xaml">
249新增: <Generator>MSBuild:Compile</Generator>
250新增: <SubType>Designer</SubType>
251新增: </Page>
252新增: <Page Include="Themes\SettingPanel\SettingPanelItem.xaml">
253新增: <Generator>MSBuild:Compile</Generator>
254新增: <SubType>Designer</SubType>
255新增: </Page>
256新增: <Page Include="Themes\SettingPanel\SettingPanel.xaml">
257新增: <Generator>MSBuild:Compile</Generator>
258新增: <SubType>Designer</SubType>
259新增: </Page>
260新增: <Page Include="Themes\Tabbar\Tabbar.xaml">
261新增: <Generator>MSBuild:Compile</Generator>
262新增: <SubType>Designer</SubType>
263新增: </Page>
120264 <Page Include="Themes\Navigation\Navigation.xaml">
121265 <Generator>MSBuild:Compile</Generator>
122266 <SubType>Designer</SubType>
@@ -129,6 +273,10 @@
129273 <Generator>MSBuild:Compile</Generator>
130274 <SubType>Designer</SubType>
131275 </Page>
276新增: <Page Include="Themes\Toggle\Toggle.xaml">
277新增: <SubType>Designer</SubType>
278新增: <Generator>MSBuild:Compile</Generator>
279新增: </Page>
132280 <Page Include="Themes\Window\DefaultWindow.xaml">
133281 <SubType>Designer</SubType>
134282 <Generator>MSBuild:Compile</Generator>
@@ -137,10 +285,22 @@
137285 <SubType>Designer</SubType>
138286 <Generator>MSBuild:Compile</Generator>
139287 </Page>
288新增: <Page Include="Views\DataPage.xaml">
289新增: <Generator>MSBuild:Compile</Generator>
290新增: <SubType>Designer</SubType>
291新增: </Page>
292新增: <Page Include="Views\DetailPage.xaml">
293新增: <SubType>Designer</SubType>
294新增: <Generator>MSBuild:Compile</Generator>
295新增: </Page>
140296 <Page Include="Views\IndexPage.xaml">
141297 <SubType>Designer</SubType>
142298 <Generator>MSBuild:Compile</Generator>
143299 </Page>
300新增: <Page Include="Views\SettingPage.xaml">
301新增: <SubType>Designer</SubType>
302新增: <Generator>MSBuild:Compile</Generator>
303新增: </Page>
144304 </ItemGroup>
145305 <ItemGroup>
146306 <Compile Include="Properties\AssemblyInfo.cs">
@@ -178,10 +338,22 @@
178338 </ProjectReference>
179339 </ItemGroup>
180340 <ItemGroup>
181删除: <Folder Include="Resources\Icons\" />
341新增: <Resource Include="Resources\Icons\tai.ico" />
342新增: </ItemGroup>
343新增: <ItemGroup>
344新增: <Resource Include="Resources\Icons\defaultIcon.png" />
182345 </ItemGroup>
183346 <ItemGroup>
184删除: <Resource Include="TextTemplate.ico" />
347新增: <BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
348新增: <Visible>False</Visible>
349新增: <ProductName>Microsoft .NET Framework 4.6.1 %28x86 和 x64%29</ProductName>
350新增: <Install>true</Install>
351新增: </BootstrapperPackage>
352新增: <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
353新增: <Visible>False</Visible>
354新增: <ProductName>.NET Framework 3.5 SP1</ProductName>
355新增: <Install>false</Install>
356新增: </BootstrapperPackage>
185357 </ItemGroup>
186358 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
187359</Project>
文件末尾没有换行
新增UI/ViewModels/DataPageVM.cs+95 −0看文件
@@ -0,0 +1,95 @@
1新增:using Core.Librarys;
2新增:using Core.Librarys.Image;
3新增:using Core.Servicers.Interfaces;
4新增:using System;
5新增:using System.Collections.Generic;
6新增:using System.Diagnostics;
7新增:using System.Drawing;
8新增:using System.Linq;
9新增:using System.Text;
10新增:using System.Threading.Tasks;
11新增:using System.Windows.Media.Imaging;
12新增:using UI.Controls;
13新增:using UI.Controls.Charts.Model;
14新增:using UI.Librays;
15新增:using UI.Models;
16新增:using UI.Views;
17新增:
18新增:namespace UI.ViewModels
19新增:{
20新增: public class DataPageVM : DataPageModel
21新增: {
22新增: public Command ToDetailCommand { get; set; }
23新增: private readonly IData data;
24新增: private readonly MainViewModel main;
25新增:
26新增: public DataPageVM(IData data, MainViewModel main)
27新增: {
28新增: this.data = data;
29新增: this.main = main;
30新增:
31新增: ToDetailCommand = new Command(new Action<object>(OnTodetailCommand));
32新增:
33新增: Init();
34新增: }
35新增:
36新增: private void Init()
37新增: {
38新增: LoadData(DateTime.Now.Date);
39新增: PropertyChanged += DataPageVM_PropertyChanged;
40新增: }
41新增:
42新增: private void OnTodetailCommand(object obj)
43新增: {
44新增: var data = obj as ChartsDataModel;
45新增:
46新增: if (data != null)
47新增: {
48新增: main.Data = data;
49新增: main.Uri = nameof(DetailPage);
50新增: }
51新增: }
52新增:
53新增: private void DataPageVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
54新增: {
55新增: if (e.PropertyName == nameof(Date))
56新增: {
57新增: LoadData(Date);
58新增: }
59新增: }
60新增:
61新增:
62新增:
63新增: #region 读取数据
64新增:
65新增:
66新增:
67新增:
68新增: private void LoadData(DateTime date)
69新增: {
70新增: var list = data.GetDateRangelogList(date, date);
71新增: Data = MapToChartsData(list);
72新增: }
73新增:
74新增: #region 处理数据
75新增: private List<ChartsDataModel> MapToChartsData(List<Core.Models.DailyLogModel> list)
76新增: {
77新增: var resData = new List<ChartsDataModel>();
78新增:
79新增: foreach (var item in list)
80新增: {
81新增: var bindModel = new ChartsDataModel();
82新增: bindModel.Name = string.IsNullOrEmpty(item.ProcessDescription) ? item.ProcessName : item.ProcessDescription;
83新增: bindModel.Value = item.Time;
84新增: bindModel.Tag = Timer.Fromat(item.Time);
85新增: bindModel.PopupText = item.File;
86新增: bindModel.Icon = Iconer.Get(item.ProcessName, item.ProcessDescription);
87新增: resData.Add(bindModel);
88新增: }
89新增:
90新增: return resData;
91新增: }
92新增: #endregion
93新增: #endregion
94新增: }
95新增:}
新增UI/ViewModels/DetailPageVM.cs+127 −0看文件
@@ -0,0 +1,127 @@
1新增:using Core.Librarys;
2新增:using Core.Servicers.Interfaces;
3新增:using System;
4新增:using System.Collections.Generic;
5新增:using System.Linq;
6新增:using System.Text;
7新增:using System.Threading.Tasks;
8新增:using UI.Controls.Charts.Model;
9新增:using UI.Librays;
10新增:using UI.Models;
11新增:
12新增:namespace UI.ViewModels
13新增:{
14新增: public class DetailPageVM : DetailPageModel
15新增: {
16新增: private readonly IData data;
17新增: private readonly MainViewModel main;
18新增: public DetailPageVM(
19新增: IData data, MainViewModel main)
20新增: {
21新增: this.data = data;
22新增: this.main = main;
23新增: Init();
24新增: }
25新增:
26新增: private async void Init()
27新增: {
28新增: Process = main.Data as ChartsDataModel;
29新增:
30新增: Date = DateTime.Now;
31新增:
32新增: PropertyChanged += DetailPageVM_PropertyChanged;
33新增:
34新增: await LoadData();
35新增:
36新增: await LoadInfo();
37新增: }
38新增:
39新增: private async void DetailPageVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
40新增: {
41新增: if (e.PropertyName == nameof(Date))
42新增: {
43新增: await LoadData();
44新增: }
45新增: }
46新增:
47新增: private async Task LoadInfo()
48新增: {
49新增: await Task.Run(() =>
50新增: {
51新增: if (Process != null)
52新增: {
53新增: var info = data.GetLast(Process.PopupText);
54新增: if (info != null)
55新增: {
56新增: ProcessName = info.ProcessName;
57新增:
58新增: }
59新增: }
60新增: }
61新增: );
62新增: }
63新增:
64新增: private async Task LoadData()
65新增: {
66新增: await Task.Run(() =>
67新增: {
68新增: if (Process != null)
69新增: {
70新增: var monthData = data.GetProcessMonthLogList(Process.PopupText, Date);
71新增: int monthTotal = monthData.Sum(m => m.Time);
72新增: Total = Timer.Fromat(monthTotal);
73新增:
74新增: DateTime start = new DateTime(Date.Year, Date.Month, 1);
75新增: DateTime end = new DateTime(Date.Year, Date.Month, DateTime.DaysInMonth(Date.Year, Date.Month));
76新增: var monthAllData = data.GetDateRangelogList(start, end);
77新增:
78新增: LongDay = "暂无数据";
79新增: if (monthData.Count > 0)
80新增: {
81新增: var longDayData = monthData.OrderByDescending(m => m.Time).FirstOrDefault();
82新增: LongDay = longDayData.Date.ToString("最长一天是在 dd 日,使用了 " + Timer.Fromat(longDayData.Time));
83新增:
84新增: }
85新增:
86新增:
87新增: int monthAllTotal = monthAllData.Sum(m => m.Time);
88新增: if (monthAllTotal > 0)
89新增: {
90新增: Ratio = (((double)monthTotal / (double)monthAllTotal)).ToString("P");
91新增: }
92新增: else
93新增: {
94新增: Ratio = "暂无数据";
95新增: }
96新增: Data = MapToChartsData(monthData);
97新增: if (Data.Count == 0)
98新增: {
99新增: Data.Add(new ChartsDataModel()
100新增: {
101新增: DateTime = Date,
102新增: });
103新增: }
104新增: }
105新增: });
106新增: }
107新增:
108新增: private List<ChartsDataModel> MapToChartsData(List<Core.Models.DailyLogModel> list)
109新增: {
110新增: var resData = new List<ChartsDataModel>();
111新增:
112新增: foreach (var item in list)
113新增: {
114新增: var bindModel = new ChartsDataModel();
115新增: bindModel.Name = string.IsNullOrEmpty(item.ProcessDescription) ? item.ProcessName : item.ProcessDescription;
116新增: bindModel.Value = item.Time;
117新增: bindModel.Tag = Timer.Fromat(item.Time);
118新增: bindModel.PopupText = item.File;
119新增: bindModel.Icon = Iconer.Get(item.ProcessName, item.ProcessDescription);
120新增: bindModel.DateTime = item.Date;
121新增: resData.Add(bindModel);
122新增: }
123新增:
124新增: return resData;
125新增: }
126新增: }
127新增:}
新增UI/ViewModels/IndexPageVM.cs+144 −0看文件
@@ -0,0 +1,144 @@
1新增:using Core.Librarys;
2新增:using Core.Librarys.Image;
3新增:using Core.Servicers.Interfaces;
4新增:using System;
5新增:using System.Collections.Generic;
6新增:using System.Diagnostics;
7新增:using System.Drawing;
8新增:using System.Linq;
9新增:using System.Text;
10新增:using System.Threading.Tasks;
11新增:using System.Windows.Media.Imaging;
12新增:using UI.Controls;
13新增:using UI.Controls.Charts.Model;
14新增:using UI.Librays;
15新增:using UI.Models;
16新增:using UI.Views;
17新增:
18新增:namespace UI.ViewModels
19新增:{
20新增: public class IndexPageVM : IndexPageModel
21新增: {
22新增: public Command ToDetailCommand { get; set; }
23新增: private readonly IData data;
24新增: private readonly MainViewModel main;
25新增: private readonly IMain mainServicer;
26新增: public IndexPageVM(
27新增: IData data, MainViewModel main, IMain mainServicer)
28新增: {
29新增: this.data = data;
30新增: this.main = main;
31新增: this.mainServicer = mainServicer;
32新增:
33新增: ToDetailCommand = new Command(new Action<object>(OnTodetailCommand));
34新增:
35新增: mainServicer.OnUpdateTime += MainServicer_OnUpdateTime;
36新增: Init();
37新增: }
38新增:
39新增: private void MainServicer_OnUpdateTime(object sender, EventArgs e)
40新增: {
41新增: if (TabbarSelectedIndex == 1)
42新增: {
43新增: LoadThisWeekData();
44新增: }
45新增: }
46新增:
47新增: private void Init()
48新增: {
49新增: TabbarData = new System.Collections.ObjectModel.ObservableCollection<string>()
50新增: {
51新增: "上周","本周"
52新增: };
53新增:
54新增: TabbarSelectedIndex = 1;
55新增: PropertyChanged += IndexPageVM_PropertyChanged;
56新增: LoadThisWeekData();
57新增: }
58新增:
59新增: private void OnTodetailCommand(object obj)
60新增: {
61新增: var data = obj as ChartsDataModel;
62新增:
63新增: if (data != null)
64新增: {
65新增: main.Data = data;
66新增: main.Uri = nameof(DetailPage);
67新增: }
68新增: }
69新增:
70新增: private void IndexPageVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
71新增: {
72新增: if (e.PropertyName == nameof(TabbarSelectedIndex))
73新增: {
74新增: if (TabbarSelectedIndex == 1)
75新增: {
76新增: LoadThisWeekData();
77新增: }
78新增: else
79新增: {
80新增: LoadLastWeekData();
81新增: }
82新增: }
83新增: }
84新增:
85新增: #region 读取数据
86新增:
87新增: #region 本周数据
88新增: private async void LoadThisWeekData()
89新增: {
90新增: IsLoading = true;
91新增:
92新增: var task = Task.Run(() =>
93新增: {
94新增: var list = data.GetThisWeeklogList();
95新增: var res = MapToChartsData(list);
96新增: IsLoading = false;
97新增: return res;
98新增:
99新增: });
100新增:
101新增: WeekData = await task;
102新增:
103新增: }
104新增: #endregion
105新增:
106新增:
107新增: #region 上周数据
108新增: private async void LoadLastWeekData()
109新增: {
110新增: IsLoading = true;
111新增: var task = Task.Run(() =>
112新增: {
113新增: var list = data.GetLastWeeklogList();
114新增: var res = MapToChartsData(list);
115新增: IsLoading = false;
116新增: return res;
117新增: });
118新增: WeekData = await task;
119新增: }
120新增: #endregion
121新增:
122新增: #region 处理数据
123新增: private List<ChartsDataModel> MapToChartsData(List<Core.Models.DailyLogModel> list)
124新增: {
125新增: var resData = new List<ChartsDataModel>();
126新增:
127新增: foreach (var item in list)
128新增: {
129新增: var bindModel = new ChartsDataModel();
130新增: bindModel.Name = string.IsNullOrEmpty(item.ProcessDescription) ? item.ProcessName : item.ProcessDescription;
131新增: bindModel.Value = item.Time;
132新增: bindModel.Tag = Timer.Fromat(item.Time);
133新增: bindModel.PopupText = item.File;
134新增: bindModel.Icon = Iconer.Get(item.ProcessName, item.ProcessDescription);
135新增: bindModel.DateTime = item.Date;
136新增: resData.Add(bindModel);
137新增: }
138新增:
139新增: return resData;
140新增: }
141新增: #endregion
142新增: #endregion
143新增: }
144新增:}
修改UI/ViewModels/MainViewModel.cs+3 −2看文件
@@ -79,8 +79,9 @@ namespace UI.ViewModels
7979 Items.Add(new Controls.Navigation.Models.NavigationItemModel()
8080 {
8181 Icon = Controls.Base.IconTypes.BIDashboard,
82删除: Title = "统计",
83删除: ID = 1
82新增: Title = "每日",
83新增: ID = 1,
84新增: Uri = nameof(DataPage),
8485
8586 });
8687 NavSelectedItem = Items[0];
新增UI/ViewModels/SettingPageVM.cs+87 −0看文件
@@ -0,0 +1,87 @@
1新增:using Core.Models.Config;
2新增:using Core.Models.Config.Link;
3新增:using Core.Servicers.Interfaces;
4新增:using System;
5新增:using System.Collections.Generic;
6新增:using System.Diagnostics;
7新增:using System.Linq;
8新增:using System.Reflection;
9新增:using System.Text;
10新增:using System.Threading.Tasks;
11新增:using UI.Models;
12新增:
13新增:namespace UI.ViewModels
14新增:{
15新增: public class SettingPageVM : SettingPageModel
16新增: {
17新增: private ConfigModel config;
18新增: private readonly IAppConfig appConfig;
19新增: public SettingPageVM(IAppConfig appConfig)
20新增: {
21新增: this.appConfig = appConfig;
22新增:
23新增:
24新增: Init();
25新增:
26新增: }
27新增:
28新增: private void Init()
29新增: {
30新增: config = appConfig.GetConfig();
31新增:
32新增: Data = config.General;
33新增:
34新增: TabbarData = new System.Collections.ObjectModel.ObservableCollection<string>()
35新增: {
36新增: "常规","关联","关于"
37新增: };
38新增:
39新增: PropertyChanged += SettingPageVM_PropertyChanged;
40新增:
41新增: Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
42新增: }
43新增:
44新增:
45新增:
46新增: private void SettingPageVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
47新增: {
48新增: if (e.PropertyName == nameof(Data))
49新增: {
50新增: if (TabbarSelectedIndex == 0)
51新增: {
52新增: config.General = Data as GeneralModel;
53新增: }
54新增: else if (TabbarSelectedIndex == 1)
55新增: {
56新增: if (Data != null)
57新增: {
58新增: var newData = new List<LinkModel>();
59新增: foreach (var item in Data as IEnumerable<object>)
60新增: {
61新增: newData.Add(item as LinkModel);
62新增: Debug.WriteLine(item.ToString());
63新增: }
64新增: config.Links = newData;
65新增: }
66新增:
67新增: }
68新增:
69新增: appConfig.Save();
70新增: }
71新增:
72新增: if (e.PropertyName == nameof(TabbarSelectedIndex))
73新增: {
74新增: if (TabbarSelectedIndex == 0)
75新增: {
76新增: // 常规
77新增: Data = config.General;
78新增: }
79新增: else if (TabbarSelectedIndex == 1)
80新增: {
81新增: // 关联
82新增: Data = config.Links;
83新增: }
84新增: }
85新增: }
86新增: }
87新增:}
新增UI/Views/DataPage.xaml+40 −0看文件
@@ -0,0 +1,40 @@
1新增:<Page
2新增: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4新增: xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5新增: xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6新增: xmlns:local="clr-namespace:UI.Views"
7新增: xmlns:Charts="clr-namespace:UI.Controls.Charts" xmlns:Tabbar="clr-namespace:UI.Controls.Tabbar" xmlns:DatePickerBar="clr-namespace:UI.Controls.DatePickerBar" x:Class="UI.Views.DataPage"
8新增: mc:Ignorable="d"
9新增: d:DesignHeight="450" d:DesignWidth="800"
10新增: Title="IndexPage">
11新增:
12新增: <Grid>
13新增: <StackPanel Margin="20">
14新增: <TextBlock Text="每日" FontSize="18" Margin="0,5,0,20"/>
15新增:
16新增: <!--<Border Width="60" Height="60" HorizontalAlignment="Left" RenderTransformOrigin="1,0.5">
17新增: <Border.Effect>
18新增: <DropShadowEffect BlurRadius="4" ShadowDepth="0" Direction="0" Opacity="1"/>
19新增: </Border.Effect>
20新增: <Border.Background>
21新增: <LinearGradientBrush EndPoint="2,1" StartPoint="-2,0">
22新增: <GradientStop Color="#FFEE0357"/>
23新增: <GradientStop Color="#FF2B20D9" Offset="1"/>
24新增: </LinearGradientBrush>
25新增: </Border.Background>
26新增:
27新增: </Border>-->
28新增: <!--<TextBlock Text="按月统计" FontSize="18" Margin="0,5,0,10"/>-->
29新增: <DatePickerBar:DatePickerBar SelectedDate="{Binding Date,Mode=TwoWay}"/>
30新增:
31新增: <Charts:Charts Data="{Binding Data}" ChartsType="HorizontalA" Margin="0,20,0,0" ClickCommand="{Binding ToDetailCommand}"/>
32新增:
33新增:
34新增:
35新增:
36新增:
37新增:
38新增: </StackPanel>
39新增: </Grid>
40新增:</Page>
新增UI/Views/DataPage.xaml.cs+30 −0看文件
@@ -0,0 +1,30 @@
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新增:using System.Windows.Data;
9新增:using System.Windows.Documents;
10新增:using System.Windows.Input;
11新增:using System.Windows.Media;
12新增:using System.Windows.Media.Imaging;
13新增:using System.Windows.Navigation;
14新增:using System.Windows.Shapes;
15新增:using UI.Controls.Charts.Model;
16新增:
17新增:namespace UI.Views
18新增:{
19新增: /// <summary>
20新增: /// IndexPage.xaml 的交互逻辑
21新增: /// </summary>
22新增: public partial class DataPage : Page
23新增: {
24新增: public DataPage()
25新增: {
26新增: InitializeComponent();
27新增:
28新增: }
29新增: }
30新增:}
新增UI/Views/DetailPage.xaml+72 −0看文件
@@ -0,0 +1,72 @@
1新增:<Page
2新增: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4新增: xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5新增: xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6新增: xmlns:local="clr-namespace:UI.Views" xmlns:Charts="clr-namespace:UI.Controls.Charts"
7新增: xmlns:DatePickerBar="clr-namespace:UI.Controls.DatePickerBar" x:Class="UI.Views.DetailPage"
8新增: mc:Ignorable="d"
9新增: d:DesignHeight="450" d:DesignWidth="800"
10新增: Title="DetailPage">
11新增:
12新增: <Grid>
13新增: <StackPanel Margin="20">
14新增: <TextBlock Text="查看" FontSize="18" Margin="0,0,0,20"/>
15新增:
16新增: <Border
17新增: Background="White"
18新增: CornerRadius="12"
19新增: Padding="0,20">
20新增: <Grid>
21新增: <Grid.ColumnDefinitions>
22新增: <ColumnDefinition Width="100"/>
23新增: <ColumnDefinition Width="9*"/>
24新增:
25新增: </Grid.ColumnDefinitions>
26新增: <Image Source="{Binding Process.Icon}" Width="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
27新增:
28新增: <StackPanel Grid.Column="1" VerticalAlignment="Center">
29新增: <StackPanel Orientation="Horizontal">
30新增: <TextBlock Text="{Binding Process.Name}" FontSize="18" />
31新增: <TextBlock ToolTip="进程名" Text="{Binding ProcessName}" FontSize="12" Foreground="Gray" VerticalAlignment="Center" Margin="15,0,0,0"/>
32新增:
33新增: </StackPanel>
34新增: <TextBlock ToolTip="进程文件路径" Foreground="Gray" Text="{Binding Process.PopupText}" Margin="0,5,0,0" TextWrapping="WrapWithOverflow"/>
35新增:
36新增: </StackPanel>
37新增: </Grid>
38新增: </Border>
39新增:
40新增: <Border
41新增: Background="White"
42新增: CornerRadius="12"
43新增: Padding="20,20"
44新增: Margin="0,20,0,0">
45新增: <StackPanel>
46新增: <DatePickerBar:DatePickerBar ShowType="Month" HorizontalAlignment="Left" SelectedDate="{Binding Date,Mode=TwoWay}"/>
47新增:
48新增: <Grid Margin="0,20,0,0">
49新增: <Grid.ColumnDefinitions>
50新增: <ColumnDefinition Width="256"/>
51新增: <ColumnDefinition Width="9*"/>
52新增:
53新增: </Grid.ColumnDefinitions>
54新增: <Charts:Charts Data="{Binding Data}" ChartsType="Month" HorizontalAlignment="Left"/>
55新增: <StackPanel Grid.Column="1">
56新增: <TextBlock FontSize="14"><Run Text="该月累计使用"/><Run Text="{Binding Total}"/>
57新增: </TextBlock>
58新增: <TextBlock Foreground="Gray" Margin="0,5,0,0" FontSize="14"><Run Text="{Binding LongDay}"/>
59新增: </TextBlock>
60新增: <TextBlock Text="在当月所有使用应用时长中占比" FontSize="14" Margin="0,20,0,0"/>
61新增:
62新增: <TextBlock Margin="0,10,0,0" FontSize="24"><Run Text="{Binding Ratio}"/>
63新增: </TextBlock>
64新增:
65新增: </StackPanel>
66新增: </Grid>
67新增: </StackPanel>
68新增: </Border>
69新增:
70新增: </StackPanel>
71新增: </Grid>
72新增:</Page>
新增UI/Views/DetailPage.xaml.cs+28 −0看文件
@@ -0,0 +1,28 @@
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新增:using System.Windows.Data;
9新增:using System.Windows.Documents;
10新增:using System.Windows.Input;
11新增:using System.Windows.Media;
12新增:using System.Windows.Media.Imaging;
13新增:using System.Windows.Navigation;
14新增:using System.Windows.Shapes;
15新增:
16新增:namespace UI.Views
17新增:{
18新增: /// <summary>
19新增: /// DetailPage.xaml 的交互逻辑
20新增: /// </summary>
21新增: public partial class DetailPage : Page
22新增: {
23新增: public DetailPage()
24新增: {
25新增: InitializeComponent();
26新增: }
27新增: }
28新增:}
修改UI/Views/IndexPage.xaml+24 −2看文件
@@ -1,14 +1,36 @@
1删除:<Page x:Class="UI.Views.IndexPage"
1新增:<Page
22 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66 xmlns:local="clr-namespace:UI.Views"
7新增: xmlns:Charts="clr-namespace:UI.Controls.Charts" xmlns:Tabbar="clr-namespace:UI.Controls.Tabbar" x:Class="UI.Views.IndexPage"
78 mc:Ignorable="d"
89 d:DesignHeight="450" d:DesignWidth="800"
910 Title="IndexPage">
1011
1112 <Grid>
12删除:
13新增: <StackPanel Margin="20">
14新增: <!--<Border Width="60" Height="60" HorizontalAlignment="Left" RenderTransformOrigin="1,0.5">
15新增: <Border.Effect>
16新增: <DropShadowEffect BlurRadius="4" ShadowDepth="0" Direction="0" Opacity="1"/>
17新增: </Border.Effect>
18新增: <Border.Background>
19新增: <LinearGradientBrush EndPoint="2,1" StartPoint="-2,0">
20新增: <GradientStop Color="#FFEE0357"/>
21新增: <GradientStop Color="#FF2B20D9" Offset="1"/>
22新增: </LinearGradientBrush>
23新增: </Border.Background>
24新增:
25新增: </Border>-->
26新增: <TextBlock Text="概览" FontSize="18" Margin="0,5,0,20"/>
27新增: <Tabbar:Tabbar Data="{Binding TabbarData}" SelectedIndex="{Binding TabbarSelectedIndex,Mode=TwoWay}"/>
28新增: <TextBlock Text="最为频繁" FontSize="15" Margin="0,5,0,10"/>
29新增: <Charts:Charts Data="{Binding WeekData}" ChartsType="HorizontalA" ShowLimit="3" IsLoading="{Binding IsLoading,Mode=TwoWay}" ClickCommand="{Binding ToDetailCommand}"/>
30新增: <TextBlock Text="更多" FontSize="15" Margin="0,20,0,10"/>
31新增: <Charts:Charts Data="{Binding WeekData}" ChartsType="Card" ShowLimit="12" IsLoading="{Binding IsLoading,Mode=TwoWay}" ClickCommand="{Binding ToDetailCommand}"/>
32新增:
33新增:
34新增: </StackPanel>
1335 </Grid>
1436</Page>
修改UI/Views/IndexPage.xaml.cs+2 −0看文件
@@ -12,6 +12,7 @@ using System.Windows.Media;
1212using System.Windows.Media.Imaging;
1313using System.Windows.Navigation;
1414using System.Windows.Shapes;
15新增:using UI.Controls.Charts.Model;
1516
1617namespace UI.Views
1718{
@@ -23,6 +24,7 @@ namespace UI.Views
2324 public IndexPage()
2425 {
2526 InitializeComponent();
27新增:
2628 }
2729 }
2830}
新增UI/Views/SettingPage.xaml+63 −0看文件
@@ -0,0 +1,63 @@
1新增:<Page
2新增: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4新增: xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5新增: xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6新增: xmlns:local="clr-namespace:UI.Views"
7新增: xmlns:SettingPanel="clr-namespace:UI.Controls.SettingPanel" x:Class="UI.Views.SettingPage"
8新增: mc:Ignorable="d"
9新增: d:DesignHeight="450" d:DesignWidth="800"
10新增: Title="SettingPage"
11新增: xmlns:Tabbar="clr-namespace:UI.Controls.Tabbar"
12新增: xmlns:Btn="clr-namespace:UI.Controls.Button">
13新增:
14新增: <Grid Margin="20">
15新增: <StackPanel>
16新增: <TextBlock Text="设置" FontSize="18" Margin="0,5,0,20"/>
17新增: <Tabbar:Tabbar Data="{Binding TabbarData}" SelectedIndex="{Binding TabbarSelectedIndex,Mode=TwoWay}"/>
18新增:
19新增: <TabControl
20新增: SelectedIndex="{Binding TabbarSelectedIndex}"
21新增: BorderThickness="0"
22新增: Margin="0"
23新增: Padding="0"
24新增: Background="Transparent"
25新增: >
26新增: <TabControl.Resources>
27新增: <Style TargetType="TabItem">
28新增: <Setter Property="Template">
29新增: <Setter.Value>
30新增: <ControlTemplate TargetType="TabItem">
31新增: </ControlTemplate>
32新增: </Setter.Value>
33新增: </Setter>
34新增: </Style>
35新增:
36新增: </TabControl.Resources>
37新增: <TabItem>
38新增: <SettingPanel:SettingPanel Data="{Binding Data,Mode=TwoWay}" />
39新增: </TabItem>
40新增: <TabItem>
41新增: <SettingPanel:SettingPanel Data="{Binding Data,Mode=TwoWay}" Margin="0,0,0,10"/>
42新增: </TabItem>
43新增: <TabItem>
44新增: <!--关于-->
45新增: <Border Background="White" Padding="20" CornerRadius="6">
46新增: <StackPanel HorizontalAlignment="Left">
47新增: <Image Width="25" Source="/Resources/Icons/tai.ico" HorizontalAlignment="Left"/>
48新增: <TextBlock Margin="0,20,0,0">
49新增: <Run Text="Tai "/><Run Text="{Binding Version}"/>
50新增: </TextBlock>
51新增:
52新增: <TextBlock Margin="0,30,0,0">
53新增: <Run Text="外部资源声明 "/>
54新增: </TextBlock>
55新增: <TextBlock Margin="0,5,0,0" Text="Icon 来自微软 Emoji"/>
56新增: </StackPanel>
57新增: </Border>
58新增: </TabItem>
59新增: </TabControl>
60新增: </StackPanel>
61新增:
62新增: </Grid>
63新增:</Page>
新增UI/Views/SettingPage.xaml.cs+28 −0看文件
@@ -0,0 +1,28 @@
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新增:using System.Windows.Data;
9新增:using System.Windows.Documents;
10新增:using System.Windows.Input;
11新增:using System.Windows.Media;
12新增:using System.Windows.Media.Imaging;
13新增:using System.Windows.Navigation;
14新增:using System.Windows.Shapes;
15新增:
16新增:namespace UI.Views
17新增:{
18新增: /// <summary>
19新增: /// SettingPage.xaml 的交互逻辑
20新增: /// </summary>
21新增: public partial class SettingPage : Page
22新增: {
23新增: public SettingPage()
24新增: {
25新增: InitializeComponent();
26新增: }
27新增: }
28新增:}