├── .gitignore ├── LICENSE.md ├── README.md ├── img ├── ColorPicker.png ├── FontPicker.png └── Theme.png └── src └── MaterialDesignInPrism.Full ├── MaterialDesignInPrism.ColorPicker ├── AssemblyInfo.cs ├── ColorPickerModule.cs ├── EKey.cs ├── HotKeyHelper.cs ├── HotKeyManager.cs ├── HotKeyModel.cs ├── HotKeySettingsManager.cs ├── MaterialDesignInPrism.ColorPicker.csproj ├── RegistryManager.cs ├── ViewModels │ ├── PickerViewModel.cs │ └── SettingViewModel.cs └── Views │ ├── PickerView.xaml │ ├── PickerView.xaml.cs │ ├── SettingView.xaml │ └── SettingView.xaml.cs ├── MaterialDesignInPrism.Core ├── Common │ ├── Inf.cs │ ├── ProgressDialog.xaml │ ├── ProgressDialog.xaml.cs │ ├── SkinView.xaml │ ├── SkinView.xaml.cs │ ├── SkinViewModel.cs │ └── StringEvent.cs ├── Extensions │ ├── IDialogHostServiceExtensions.cs │ ├── PaletteHelperExtensions.cs │ └── RegionNavigationExtensions.cs ├── MaterialDesignInPrism.Core.csproj ├── Mvvm │ └── BaseShowViewModel.cs └── Service │ ├── DialogHostService.cs │ ├── IDialogHostAware.cs │ └── IDialogHostService.cs ├── MaterialDesignInPrism.DeskTop ├── App.xaml ├── App.xaml.cs ├── MaterialDesignInPrism.DeskTop.csproj ├── ModuleInfo.cs ├── Properties │ └── PublishProfiles │ │ └── FolderProfile.pubxml ├── ViewModels │ └── MainWindowViewModel.cs ├── Views │ ├── MainWindow.xaml │ └── MainWindow.xaml.cs └── logo.ico ├── MaterialDesignInPrism.FontPicker ├── AssemblyInfo.cs ├── FontItem.cs ├── FontPickerModule.cs ├── MaterialDesignInPrism.FontPicker.csproj ├── Properties │ └── launchSettings.json ├── ViewModels │ └── FonPickerViewModel.cs └── Views │ ├── FonPickerView.xaml │ └── FonPickerView.xaml.cs └── MaterialDesignInPrism.Full.sln /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc 262 | /ZFS/ZFSDomain/obj 263 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2021 henji 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 魔法工具箱 2 | 开发工具: VisualStudio 2019 3 | 目标框架: .NET 5 4 | 开发语言: C#/WPF 5 | 第三方组件: 6 | - Prism8.x 7 | - MaterialDesign Toolkit 8 | 9 | ## 理念 10 | 集成一些日常开发当中使用到的小工具, 例如: 取色器、查看字体等(后面会陆续集成...)。 11 | 12 | ## 截图 13 | 14 | - 取色器 15 | 设置快捷键即可截取鼠标位置选中颜色, 同时具备查看截取颜色历史记录 16 | ![Screenshot](https://github.com/HenJigg/WeTool/blob/main/img/ColorPicker.png) 17 | 18 | - 字体查看器 19 | 可以快速打开ttf文件, 查看其中的字体目标代码,提供一键复制功能 20 | ![Screenshot](https://github.com/HenJigg/WeTool/blob/main/img/FontPicker.png) 21 | 22 | - 颜色主题 23 | ![Screenshot](https://github.com/HenJigg/WeTool/blob/main/img/Theme.png) 24 | -------------------------------------------------------------------------------- /img/ColorPicker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HenJigg/WeTool/ac28ffeeb9891bf4f0cf1c2b2c286c6f901cebcf/img/ColorPicker.png -------------------------------------------------------------------------------- /img/FontPicker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HenJigg/WeTool/ac28ffeeb9891bf4f0cf1c2b2c286c6f901cebcf/img/FontPicker.png -------------------------------------------------------------------------------- /img/Theme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HenJigg/WeTool/ac28ffeeb9891bf4f0cf1c2b2c286c6f901cebcf/img/Theme.png -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.Core.Common; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: Inf("颜色拾取器", "FonPickerView")] 5 | [assembly: ComVisible(false)] 6 | [assembly: Guid("48a4eeaf-919c-4733-87f9-31c764ad2539")] 7 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/ColorPickerModule.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.ColorPicker.ViewModels; 2 | using MaterialDesignInPrism.ColorPicker.Views; 3 | using Prism.Ioc; 4 | using Prism.Modularity; 5 | using Prism.Regions; 6 | 7 | namespace MaterialDesignInPrism.ColorPicker 8 | { 9 | public class ColorPickerModule : IModule 10 | { 11 | public void OnInitialized(IContainerProvider containerProvider) 12 | { 13 | } 14 | 15 | public void RegisterTypes(IContainerRegistry containerRegistry) 16 | { 17 | containerRegistry.RegisterForNavigation(); 18 | containerRegistry.RegisterForNavigation(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/EKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MaterialDesignInPrism.ColorPicker 8 | { 9 | public enum EKey 10 | { 11 | Space = 32, 12 | Left = 37, 13 | Up = 38, 14 | Right = 39, 15 | Down = 40, 16 | A = 65, 17 | B = 66, 18 | C = 67, 19 | D = 68, 20 | E = 69, 21 | F = 70, 22 | G = 71, 23 | H = 72, 24 | I = 73, 25 | J = 74, 26 | K = 75, 27 | L = 76, 28 | M = 77, 29 | N = 78, 30 | O = 79, 31 | P = 80, 32 | Q = 81, 33 | R = 82, 34 | S = 83, 35 | T = 84, 36 | U = 85, 37 | V = 86, 38 | W = 87, 39 | X = 88, 40 | Y = 89, 41 | Z = 90, 42 | F1 = 112, 43 | F2 = 113, 44 | F3 = 114, 45 | F4 = 115, 46 | F5 = 116, 47 | F6 = 117, 48 | F7 = 118, 49 | F8 = 119, 50 | F9 = 120, 51 | F10 = 121, 52 | F11 = 122, 53 | F12 = 123, 54 | } 55 | 56 | public enum EType 57 | { 58 | Ctrl, 59 | Alt, 60 | Shift 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/HotKeyHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Input; 7 | 8 | namespace MaterialDesignInPrism.ColorPicker 9 | { 10 | /// 11 | /// 热键注册帮助 12 | /// 13 | public class HotKeyHelper 14 | { 15 | /// 16 | /// 注册热键 17 | /// 18 | /// 热键待注册项 19 | /// 窗口句柄 20 | /// 成功返回true,失败返回false 21 | public static bool RegisterHotKey(HotKeyModel hotKeyModel, IntPtr hWnd) 22 | { 23 | var fsModifierKey = new ModifierKeys(); 24 | 25 | HotKeyManager.UnregisterHotKey(hWnd, HotKeyManager.COPY_ID); 26 | 27 | // 注册热键 28 | if (hotKeyModel.SelectType == EType.Alt) 29 | fsModifierKey = ModifierKeys.Alt; 30 | else if (hotKeyModel.SelectType == EType.Ctrl) 31 | fsModifierKey = ModifierKeys.Control; 32 | else if (hotKeyModel.SelectType == EType.Shift) 33 | fsModifierKey = ModifierKeys.Shift; 34 | 35 | var result = HotKeyManager.RegisterHotKey(hWnd, HotKeyManager.COPY_ID, fsModifierKey, (int)hotKeyModel.SelectKey); 36 | if (result) { RegistryManager.Register(hotKeyModel); } 37 | return result; 38 | } 39 | 40 | /// 41 | /// 注册注册表热键 42 | /// 43 | /// 44 | public static void DefaultRegisterHotKey(IntPtr hWnd) 45 | { 46 | RegisterHotKey(RegistryManager.ReadKey(), hWnd); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/HotKeyManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Input; 8 | 9 | namespace MaterialDesignInPrism.ColorPicker 10 | { 11 | /// 12 | /// 热键管理器 13 | /// 14 | public class HotKeyManager 15 | { 16 | /// 17 | /// 热键消息,在用户键入被RegisterHotKey函数注册的热键时发送 18 | /// 19 | public const int WM_HOTKEY = 0x312; 20 | 21 | public static int COPY_ID = GlobalAddAtom("复制"); 22 | 23 | /// 24 | /// 注册热键。要得到扩展错误信息,调用GetLastError。.NET方法:Marshal.GetLastWin32Error() 25 | /// 26 | /// 要定义热键的窗口的句柄 27 | /// 定义热键ID(不能与其他ID重复) 28 | /// 标识热键是否在按Alt、Ctrl、Shift、Windows等键时才会生效 29 | /// 标识热键的内容,WinForm中可以使用Keys枚举转换,WPF中Key枚举是不正确的,应该使用system.Windows.Froms.Keys枚举,或者自定义正确的枚举或int常量 30 | /// 是否成功 31 | [DllImport("user32.dll", SetLastError = true)] 32 | public static extern bool RegisterHotKey(IntPtr hWnd, int id, ModifierKeys fsModifiers, int vk); 33 | 34 | /// 35 | /// 注销热键。 36 | /// 37 | /// 要取消热键的窗口的句柄 38 | /// 要取消热键的ID 39 | /// 是否成功 40 | [DllImport("user32.dll", SetLastError = true)] 41 | public static extern bool UnregisterHotKey(IntPtr hWnd, int id); 42 | 43 | /// 44 | /// 向全局原子表添加一个字符串,并返回这个字符串的唯一标识符 45 | /// 46 | /// 字符串,这个字符串的长度最大为255字节 47 | /// 成功:返回原子;失败:返回值为0 48 | [DllImport("kernel32.dll", SetLastError = true)] 49 | public static extern short GlobalAddAtom(string lpString); 50 | 51 | /// 52 | /// 在表中搜索全局原子 53 | /// 54 | /// 字符串,这个字符串的长度最大为255字节 55 | /// 成功:返回原子;失败:返回值为0 56 | [DllImport("kernel32.dll", SetLastError = true)] 57 | public static extern short GlobalFindAtom(string lpString); 58 | 59 | /// 60 | /// 在表中删除全局原子 61 | /// 62 | /// 全局原子 63 | /// 成功:返回原子;失败:返回值为0 64 | [DllImport("kernel32.dll", SetLastError = true)] 65 | public static extern short GlobalDeleteAtom(short nAtom); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/HotKeyModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MaterialDesignInPrism.ColorPicker 8 | { 9 | public class HotKeyModel 10 | { 11 | public EType SelectType { get; set; } 12 | 13 | public EKey SelectKey { get; set; } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/HotKeySettingsManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MaterialDesignInPrism.ColorPicker 8 | { 9 | public class HotKeySettingsManager 10 | { 11 | private static HotKeySettingsManager m_Instance; 12 | /// 13 | /// 单例实例 14 | /// 15 | public static HotKeySettingsManager Instance 16 | { 17 | get { return m_Instance ?? (m_Instance = new HotKeySettingsManager()); } 18 | } 19 | 20 | /// 21 | /// 通知注册系统快捷键委托 22 | /// 23 | /// 24 | public delegate bool RegisterGlobalHotKeyHandler(HotKeyModel hotKeyModelList); 25 | public event RegisterGlobalHotKeyHandler RegisterGlobalHotKeyEvent; 26 | public bool RegisterGlobalHotKey(HotKeyModel hotKeyModelList) 27 | { 28 | if (RegisterGlobalHotKeyEvent != null) 29 | { 30 | return RegisterGlobalHotKeyEvent(hotKeyModelList); 31 | } 32 | return false; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/MaterialDesignInPrism.ColorPicker.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net5.0-windows 5 | true 6 | MaterialDesignInPrism.ColorPicker 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/RegistryManager.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Win32; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MaterialDesignInPrism.ColorPicker 9 | { 10 | public class RegistryManager 11 | { 12 | public readonly static RegistryKey ColorPickerKey = Registry.CurrentUser.CreateSubKey("ColorPickerKey"); 13 | 14 | public static void Register(HotKeyModel model) 15 | { 16 | var config = ColorPickerKey.CreateSubKey("Config"); 17 | config.SetValue("Type", model.SelectType); 18 | config.SetValue("Key", model.SelectKey); 19 | } 20 | 21 | public static HotKeyModel ReadKey() 22 | { 23 | var config = ColorPickerKey.OpenSubKey("Config"); 24 | if (config == null) 25 | return new HotKeyModel() { SelectType = EType.Ctrl, SelectKey = EKey.A }; 26 | EType type = EType.Ctrl; 27 | EKey eKey = EKey.A; 28 | Enum.TryParse(config.GetValue("Type").ToString(), true, out type); 29 | Enum.TryParse(config.GetValue("Key").ToString(), true, out eKey); 30 | return new HotKeyModel() { SelectKey = eKey, SelectType = type }; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/ViewModels/PickerViewModel.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.Core.Common; 2 | using MaterialDesignInPrism.Core.Service; 3 | using Prism.Commands; 4 | using Prism.Events; 5 | using Prism.Mvvm; 6 | using Prism.Regions; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Collections.ObjectModel; 10 | using System.Drawing; 11 | using System.Linq; 12 | using System.Runtime.InteropServices; 13 | using System.Text; 14 | using System.Threading.Tasks; 15 | using System.Windows; 16 | 17 | namespace MaterialDesignInPrism.ColorPicker.ViewModels 18 | { 19 | public class PickerViewModel : BindableBase 20 | { 21 | private readonly IDialogHostService dialogHost; 22 | private readonly IEventAggregator aggregator; 23 | 24 | public PickerViewModel(IDialogHostService dialogHost, IEventAggregator aggregator) 25 | { 26 | this.dialogHost = dialogHost; 27 | this.aggregator = aggregator; 28 | ColorList = new ObservableCollection(); 29 | CopyCommand = new DelegateCommand(Copy); 30 | ExecuteCommand = new DelegateCommand(Execute); 31 | } 32 | 33 | private void Copy(string obj) 34 | { 35 | if (string.IsNullOrWhiteSpace(obj)) return; 36 | Clipboard.SetDataObject(obj, false); 37 | } 38 | 39 | private ObservableCollection _ColorList; 40 | 41 | /// 42 | /// 颜色列表 43 | /// 44 | public ObservableCollection ColorList 45 | { 46 | get { return _ColorList; } 47 | set { _ColorList = value; RaisePropertyChanged(); } 48 | } 49 | 50 | public void Add(string value) 51 | { 52 | if (ColorList.FirstOrDefault(t => t.Equals(value)) == null) 53 | { 54 | ColorList.Add(value); 55 | aggregator.GetEvent().Publish("复制成功!"); 56 | } 57 | } 58 | 59 | private void Execute(string obj) 60 | { 61 | switch (obj) 62 | { 63 | case "快捷键": NavigationPage("SettingView"); break; 64 | } 65 | } 66 | 67 | void NavigationPage(string pageName) 68 | { 69 | dialogHost.ShowDialog(pageName); 70 | } 71 | 72 | public DelegateCommand ExecuteCommand { get; private set; } 73 | public DelegateCommand CopyCommand { get; private set; } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/ViewModels/SettingViewModel.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.Core.Service; 2 | using MaterialDesignThemes.Wpf; 3 | using Prism.Commands; 4 | using Prism.Mvvm; 5 | using Prism.Regions; 6 | using Prism.Services.Dialogs; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | namespace MaterialDesignInPrism.ColorPicker.ViewModels 14 | { 15 | public class SettingViewModel : BindableBase, IDialogHostAware 16 | { 17 | public SettingViewModel() 18 | { 19 | SaveCommand = new DelegateCommand(Save); 20 | CancelCommand = new DelegateCommand(Cancel); 21 | } 22 | 23 | private void Cancel() 24 | { 25 | DialogHost.Close(IdentifierName); 26 | } 27 | 28 | private void Save() 29 | { 30 | HotKeySettingsManager.Instance.RegisterGlobalHotKey(new HotKeyModel() 31 | { 32 | SelectType = SelectType, 33 | SelectKey = SelectKey 34 | }); 35 | DialogHost.Close(IdentifierName); 36 | } 37 | 38 | public Task OnDialogOpenedAsync(IDialogParameters parameters) 39 | { 40 | var hostKey = RegistryManager.ReadKey(); 41 | SelectType = hostKey.SelectType; 42 | SelectKey = hostKey.SelectKey; 43 | return Task.FromResult(true); 44 | } 45 | 46 | public DelegateCommand SaveCommand { get; private set; } 47 | public DelegateCommand CancelCommand { get; private set; } 48 | 49 | public Array Keys { get { return Enum.GetValues(typeof(EKey)); } } 50 | 51 | public Array Types { get { return Enum.GetValues(typeof(EType)); } } 52 | 53 | private EKey _selectKey; 54 | private EType _selectType; 55 | public EKey SelectKey 56 | { 57 | get { return _selectKey; } 58 | set { _selectKey = value; RaisePropertyChanged(); } 59 | } 60 | 61 | public EType SelectType 62 | { 63 | get { return _selectType; } 64 | set { _selectType = value; RaisePropertyChanged(); } 65 | } 66 | 67 | public string Title => "快捷键设置"; 68 | 69 | public string IdentifierName { get; set; } = "Root"; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/Views/PickerView.xaml: -------------------------------------------------------------------------------- 1 |  15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 27 | 28 | 29 | 30 | 31 | 32 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/Views/PickerView.xaml.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.ColorPicker.ViewModels; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Drawing; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using System.Windows.Controls; 11 | using System.Windows.Input; 12 | using System.Windows.Interop; 13 | 14 | namespace MaterialDesignInPrism.ColorPicker.Views 15 | { 16 | /// 17 | /// ColorPicker.xaml 的交互逻辑 18 | /// 19 | public partial class PickerView : UserControl, IDisposable 20 | { 21 | CancellationTokenSource colorToken; 22 | private IntPtr m_Hwnd = new IntPtr(); 23 | 24 | public PickerView() 25 | { 26 | InitializeComponent(); 27 | ConfigurationService(); 28 | this.Loaded += PickerView_Loaded; 29 | HotKeySettingsManager.Instance.RegisterGlobalHotKeyEvent += Instance_RegisterGlobalHotKeyEvent; 30 | } 31 | 32 | private void PickerView_Loaded(object sender, RoutedEventArgs e) 33 | { 34 | // 获取窗体句柄 35 | m_Hwnd = ((HwndSource)PresentationSource.FromVisual(this)).Handle; 36 | HwndSource hWndSource = HwndSource.FromHwnd(m_Hwnd); 37 | // 添加处理程序 38 | if (hWndSource != null) hWndSource.AddHook(WndProc); 39 | HotKeyHelper.DefaultRegisterHotKey(m_Hwnd); 40 | } 41 | 42 | /// 43 | /// 窗体回调函数,接收所有窗体消息的事件处理函数 44 | /// 45 | /// 窗口句柄 46 | /// 消息 47 | /// 附加参数1 48 | /// 附加参数2 49 | /// 是否处理 50 | /// 返回句柄 51 | private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wideParam, IntPtr longParam, ref bool handled) 52 | { 53 | switch (msg) 54 | { 55 | case HotKeyManager.WM_HOTKEY: 56 | string value = txtValue.Text; 57 | Clipboard.SetDataObject(txtValue.Text, false); 58 | (this.DataContext as PickerViewModel).Add(value); 59 | handled = true; 60 | break; 61 | } 62 | return IntPtr.Zero; 63 | } 64 | 65 | #region Register 66 | 67 | /// 68 | /// 通知注册系统快捷键事件处理函数 69 | /// 70 | /// 71 | /// 72 | private bool Instance_RegisterGlobalHotKeyEvent(HotKeyModel hotKeyModel) 73 | { 74 | return InitHotKey(hotKeyModel); 75 | } 76 | 77 | /// 78 | /// 初始化注册快捷键 79 | /// 80 | /// 待注册热键的项 81 | /// true:保存快捷键的值;false:弹出设置窗体 82 | private bool InitHotKey(HotKeyModel hotKeyModel = null) 83 | { 84 | // 注册全局快捷键 85 | return HotKeyHelper.RegisterHotKey(hotKeyModel, m_Hwnd); 86 | } 87 | 88 | 89 | #endregion 90 | 91 | void ConfigurationService() 92 | { 93 | colorToken = new CancellationTokenSource(); 94 | Task.Run(async () => 95 | { 96 | while (!colorToken.IsCancellationRequested) 97 | { 98 | Application.Current.Dispatcher.Invoke(() => 99 | { 100 | var colorSelect = ColorPickerManager.GetColor(); 101 | var newcolor = System.Windows.Media.Color.FromArgb(colorSelect.A, colorSelect.R, colorSelect.G, colorSelect.B); 102 | borColor.Background = new System.Windows.Media.SolidColorBrush(newcolor); 103 | }); 104 | await Task.Delay(200); 105 | } 106 | }); 107 | } 108 | 109 | public void Dispose() 110 | { 111 | Dispose(true); 112 | GC.SuppressFinalize(this); 113 | } 114 | 115 | protected virtual void Dispose(bool disposing) 116 | { 117 | colorToken.Cancel(); 118 | } 119 | } 120 | 121 | /// 122 | /// 获取当前光标处颜色,win8下wpf测试成功 123 | /// 124 | public class ColorPickerManager 125 | { 126 | public static Color GetColor() 127 | { 128 | POINT p = new POINT(); 129 | GetCursorPos(out p); 130 | IntPtr hdc = GetDC(IntPtr.Zero); 131 | uint pixel = GetPixel(hdc, p.X, p.Y); 132 | ReleaseDC(IntPtr.Zero, hdc); 133 | Color color = Color.FromArgb((int)(pixel & 0x000000FF), (int)(pixel & 0x0000FF00) >> 8, (int)(pixel & 0x00FF0000) >> 16); 134 | return color; 135 | } 136 | 137 | [StructLayout(LayoutKind.Sequential)] 138 | public struct POINT 139 | { 140 | public int X; 141 | public int Y; 142 | public POINT(int x, int y) 143 | { 144 | this.X = x; 145 | this.Y = y; 146 | } 147 | } 148 | 149 | [DllImport("user32.dll", CharSet = CharSet.Auto)] 150 | public static extern bool GetCursorPos(out POINT pt); 151 | 152 | [DllImport("gdi32.dll")] 153 | private static extern bool BitBlt( 154 | IntPtr hdcDest, // 目标设备的句柄 155 | int nXDest, // 目标对象的左上角的X坐标 156 | int nYDest, // 目标对象的左上角的X坐标 157 | int nWidth, // 目标对象的矩形的宽度 158 | int nHeight, // 目标对象的矩形的长度 159 | IntPtr hdcSrc, // 源设备的句柄 160 | int nXSrc, // 源对象的左上角的X坐标 161 | int nYSrc, // 源对象的左上角的X坐标 162 | int dwRop // 光栅的操作值 163 | ); 164 | 165 | [DllImport("gdi32.dll")] 166 | private static extern IntPtr CreateDC( 167 | string lpszDriver, // 驱动名称 168 | string lpszDevice, // 设备名称 169 | string lpszOutput, // 无用,可以设定位"NULL" 170 | IntPtr lpInitData // 任意的打印机数据 171 | ); 172 | 173 | /// 174 | /// 获取指定窗口的设备场景 175 | /// 176 | /// 将获取其设备场景的窗口的句柄。若为0,则要获取整个屏幕的DC 177 | /// 指定窗口的设备场景句柄,出错则为0 178 | [DllImport("user32.dll")] 179 | private static extern IntPtr GetDC(IntPtr hwnd); 180 | 181 | /// 182 | /// 释放由调用GetDC函数获取的指定设备场景 183 | /// 184 | /// 要释放的设备场景相关的窗口句柄 185 | /// 要释放的设备场景句柄 186 | /// 执行成功为1,否则为0 187 | [DllImport("user32.dll")] 188 | private static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc); 189 | 190 | /// 191 | /// 在指定的设备场景中取得一个像素的RGB值 192 | /// 193 | /// 一个设备场景的句柄 194 | /// 逻辑坐标中要检查的横坐标 195 | /// 逻辑坐标中要检查的纵坐标 196 | /// 指定点的颜色 197 | [DllImport("gdi32.dll")] 198 | private static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos); 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/Views/SettingView.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 36 | 40 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.ColorPicker/Views/SettingView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | 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 MaterialDesignInPrism.ColorPicker.Views 17 | { 18 | /// 19 | /// SettingView.xaml 的交互逻辑 20 | /// 21 | public partial class SettingView : UserControl 22 | { 23 | public SettingView() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Common/Inf.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MaterialDesignInPrism.Core.Common 8 | { 9 | public class Inf : Attribute 10 | { 11 | public Inf(string Name,string Code) 12 | { 13 | this.Name = Name; 14 | this.Code = Code; 15 | } 16 | 17 | public string Name { get; } 18 | public string Code { get; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Common/ProgressDialog.xaml: -------------------------------------------------------------------------------- 1 |  9 | 16 | 17 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Common/ProgressDialog.xaml.cs: -------------------------------------------------------------------------------- 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.Data; 7 | using System.Windows.Documents; 8 | using System.Windows.Input; 9 | using System.Windows.Media; 10 | using System.Windows.Media.Imaging; 11 | using System.Windows.Navigation; 12 | using System.Windows.Shapes; 13 | 14 | namespace MaterialDesignInPrism.Core.Common 15 | { 16 | /// 17 | /// ProgressDialog.xaml 的交互逻辑 18 | /// 19 | public partial class ProgressDialog : UserControl 20 | { 21 | public ProgressDialog() 22 | { 23 | InitializeComponent(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Common/SkinView.xaml: -------------------------------------------------------------------------------- 1 |  13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 浅色 38 | 42 | 深色 43 | 44 | 45 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Common/SkinView.xaml.cs: -------------------------------------------------------------------------------- 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.Data; 7 | using System.Windows.Documents; 8 | using System.Windows.Input; 9 | using System.Windows.Media; 10 | using System.Windows.Media.Imaging; 11 | using System.Windows.Navigation; 12 | using System.Windows.Shapes; 13 | 14 | namespace MaterialDesignInPrism.Core.Common 15 | { 16 | /// 17 | /// SkinView.xaml 的交互逻辑 18 | /// 19 | public partial class SkinView : UserControl 20 | { 21 | public SkinView() 22 | { 23 | InitializeComponent(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Common/SkinViewModel.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignColors; 2 | using MaterialDesignInPrism.Core.Extensions; 3 | using MaterialDesignInPrism.Core.Service; 4 | using MaterialDesignThemes.Wpf; 5 | using Prism.Commands; 6 | using Prism.Mvvm; 7 | using Prism.Regions; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Collections.ObjectModel; 11 | using System.Diagnostics; 12 | using System.Linq; 13 | using System.Text; 14 | using System.Threading.Tasks; 15 | using System.Windows.Media; 16 | 17 | namespace MaterialDesignInPrism.Core.Common 18 | { 19 | /// 20 | /// 系统样式设置 21 | /// 22 | public class SkinViewModel : BindableBase, INavigationAware 23 | { 24 | public SkinViewModel() 25 | { 26 | Styles = new ObservableCollection(); 27 | 28 | ChangeHueCommand = new DelegateCommand(ChangeHue); 29 | ToggleBaseCommand = new DelegateCommand(ApplyBase); 30 | } 31 | 32 | PaletteHelper _paletteHelper; 33 | 34 | public string SelectPageTitle { get; } = "个性化设置"; 35 | 36 | private ObservableCollection _styles; 37 | 38 | public ObservableCollection Styles 39 | { 40 | get { return _styles; } 41 | set { _styles = value; RaisePropertyChanged(); } 42 | } 43 | 44 | //改变颜色 45 | public DelegateCommand ChangeHueCommand { get; } 46 | 47 | //改变主题 48 | public DelegateCommand ToggleBaseCommand { get; } 49 | 50 | private void ApplyBase(object isDark) 51 | { 52 | ModifyTheme(theme => theme.SetBaseTheme((bool)isDark ? Theme.Dark : Theme.Light)); 53 | } 54 | 55 | private void ModifyTheme(Action modificationAction) 56 | { 57 | PaletteHelper paletteHelper = new PaletteHelper(); 58 | ITheme theme = paletteHelper.GetTheme(); 59 | modificationAction?.Invoke(theme); 60 | paletteHelper.SetTheme(theme); 61 | } 62 | 63 | private void ChangeHue(object obj) 64 | { 65 | var hue = (Color)obj; 66 | _paletteHelper.ChangePrimaryColor(hue); 67 | } 68 | 69 | public void OnNavigatedTo(NavigationContext navigationContext) 70 | { 71 | var swatches = SwatchHelper.Swatches.ToList().SelectMany(t => t.Hues); 72 | 73 | foreach (var item in swatches) Styles.Add(item); 74 | 75 | _paletteHelper = new PaletteHelper(); 76 | } 77 | 78 | public bool IsNavigationTarget(NavigationContext navigationContext) 79 | { 80 | return true; 81 | } 82 | 83 | public void OnNavigatedFrom(NavigationContext navigationContext) 84 | { 85 | 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Common/StringEvent.cs: -------------------------------------------------------------------------------- 1 | using Prism.Events; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MaterialDesignInPrism.Core.Common 9 | { 10 | public class StringEvent : PubSubEvent 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Extensions/IDialogHostServiceExtensions.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.Core.Service; 2 | using Prism.Services.Dialogs; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MaterialDesignInPrism.Core.Extensions 9 | { 10 | /// 11 | /// 主机对话服务扩展类 12 | /// 13 | public static class IDialogHostServiceExtensions 14 | { 15 | /// 16 | /// 询问 17 | /// 18 | /// 19 | /// 20 | /// 21 | public static IDialogResult Question(this IDialogHostService hostService, string message) 22 | { 23 | return hostService.ShowDialog("QuestionView", new DialogParameters() 24 | { 25 | { "Value",message } 26 | }).Result; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Extensions/PaletteHelperExtensions.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignColors; 2 | using MaterialDesignColors.ColorManipulation; 3 | using MaterialDesignThemes.Wpf; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using System.Windows.Media; 8 | 9 | namespace MaterialDesignInPrism.Core.Extensions 10 | { 11 | /// 12 | /// MaterialDesign 主题扩展 13 | /// 14 | public static class PaletteHelperExtensions 15 | { 16 | public static void ChangePrimaryColor(this PaletteHelper paletteHelper, Color color) 17 | { 18 | ITheme theme = paletteHelper.GetTheme(); 19 | 20 | theme.PrimaryLight = new ColorPair(color.Lighten(), theme.PrimaryLight.ForegroundColor); 21 | theme.PrimaryMid = new ColorPair(color, theme.PrimaryMid.ForegroundColor); 22 | theme.PrimaryDark = new ColorPair(color.Darken(), theme.PrimaryDark.ForegroundColor); 23 | 24 | paletteHelper.SetTheme(theme); 25 | } 26 | 27 | public static void ChangeSecondaryColor(this PaletteHelper paletteHelper, Color color) 28 | { 29 | ITheme theme = paletteHelper.GetTheme(); 30 | 31 | theme.SecondaryLight = new ColorPair(color.Lighten(), theme.SecondaryLight.ForegroundColor); 32 | theme.SecondaryMid = new ColorPair(color, theme.SecondaryMid.ForegroundColor); 33 | theme.SecondaryDark = new ColorPair(color.Darken(), theme.SecondaryDark.ForegroundColor); 34 | 35 | paletteHelper.SetTheme(theme); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Extensions/RegionNavigationExtensions.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.Core.Common; 2 | using MaterialDesignThemes.Wpf; 3 | using Prism.Regions; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows; 9 | 10 | namespace MaterialDesignInPrism.Core.Extensions 11 | { 12 | public static class RegionNavigationExtensions 13 | { 14 | public static NavigationResult Navigate(this INavigateAsync navigation, string target) 15 | { 16 | if (navigation == null) 17 | throw new ArgumentNullException(nameof(navigation)); 18 | 19 | if (target == null) 20 | throw new ArgumentNullException(nameof(target)); 21 | 22 | var targetUri = new Uri(target, UriKind.RelativeOrAbsolute); 23 | 24 | NavigationResult navigationResult = null; 25 | navigation.RequestNavigate(targetUri, arg => 26 | { 27 | navigationResult = arg; 28 | }); 29 | return navigationResult; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/MaterialDesignInPrism.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Library 5 | net5.0-windows 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Mvvm/BaseShowViewModel.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.Core.Service; 2 | using MaterialDesignThemes.Wpf; 3 | using Prism.Commands; 4 | using Prism.Mvvm; 5 | using Prism.Services.Dialogs; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace MaterialDesignInPrism.Core.Mvvm 12 | { 13 | /// 14 | /// 弹出式窗口公共基类 15 | /// 16 | public class BaseShowViewModel : BindableBase, IDialogHostAware 17 | { 18 | public BaseShowViewModel() 19 | { 20 | SaveCommand = new DelegateCommand(Save); 21 | CancelCommand = new DelegateCommand(Cancel); 22 | } 23 | public string IdentifierName { get; set; } 24 | public DelegateCommand SaveCommand { get; } 25 | public DelegateCommand CancelCommand { get; } 26 | 27 | public virtual void Cancel() 28 | { 29 | Close(new DialogResult(ButtonResult.Cancel)); 30 | } 31 | 32 | public virtual void Save() 33 | { 34 | Close(new DialogResult(ButtonResult.OK)); 35 | } 36 | 37 | void Close(DialogResult result) 38 | { 39 | DialogHost.Close(IdentifierName, result); 40 | } 41 | 42 | public virtual Task OnDialogOpenedAsync(IDialogParameters parameters) 43 | { 44 | return Task.FromResult(true); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Service/DialogHostService.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.Core.Common; 2 | using MaterialDesignThemes.Wpf; 3 | using Prism.Common; 4 | using Prism.Ioc; 5 | using Prism.Mvvm; 6 | using Prism.Services.Dialogs; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows; 12 | 13 | namespace MaterialDesignInPrism.Core.Service 14 | { 15 | /// 16 | /// 对话主机服务 17 | /// 18 | public class DialogHostService : DialogService, IDialogHostService 19 | { 20 | private readonly IContainerExtension _containerExtension; 21 | 22 | public DialogHostService(IContainerExtension containerExtension) : base(containerExtension) 23 | { 24 | this._containerExtension = containerExtension; 25 | } 26 | 27 | public async Task ShowDialog(string name, IDialogParameters parameters = null, string IdentifierName = "Root") 28 | { 29 | if (parameters == null) 30 | parameters = new DialogParameters(); 31 | 32 | var content = _containerExtension.Resolve(name); 33 | if (!(content is FrameworkElement dialogContent)) 34 | throw new NullReferenceException("A dialog's content must be a FrameworkElement"); 35 | 36 | if (dialogContent is FrameworkElement view && view.DataContext is null && ViewModelLocator.GetAutoWireViewModel(view) is null) 37 | ViewModelLocator.SetAutoWireViewModel(view, true); 38 | 39 | if (!(dialogContent.DataContext is IDialogHostAware viewModel)) 40 | throw new NullReferenceException("A dialog's ViewModel must implement the IDialogAware interface"); 41 | 42 | viewModel.IdentifierName = IdentifierName; 43 | 44 | DialogOpenedEventHandler eventHandler = async 45 | (sender, eventArgs) => 46 | { 47 | var content = eventArgs.Session.Content; 48 | eventArgs.Session.UpdateContent(new ProgressDialog()); 49 | if (viewModel is IDialogHostAware aware) 50 | await aware.OnDialogOpenedAsync(parameters); 51 | eventArgs.Session.UpdateContent(content); 52 | }; 53 | 54 | return (IDialogResult)await DialogHost.Show(dialogContent, viewModel.IdentifierName, eventHandler); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Service/IDialogHostAware.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignThemes.Wpf; 2 | using Prism.Commands; 3 | using Prism.Services.Dialogs; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace MaterialDesignInPrism.Core.Service 10 | { 11 | /// 12 | /// 对话主机ViewModel基类 13 | /// 14 | public interface IDialogHostAware 15 | { 16 | /// 17 | /// DialogHost顶级节点 18 | /// 19 | string IdentifierName { get; set; } 20 | 21 | /// 22 | /// 页面初始化前传递参数事件 23 | /// 24 | /// 25 | /// 26 | Task OnDialogOpenedAsync(IDialogParameters parameters); 27 | 28 | /// 29 | /// 确认 30 | /// 31 | DelegateCommand SaveCommand { get; } 32 | 33 | /// 34 | /// 取消 35 | /// 36 | DelegateCommand CancelCommand { get; } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Core/Service/IDialogHostService.cs: -------------------------------------------------------------------------------- 1 | using Prism.Services.Dialogs; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MaterialDesignInPrism.Core.Service 8 | { 9 | /// 10 | /// 对话主机服务接口 11 | /// 12 | public interface IDialogHostService : IDialogService 13 | { 14 | Task ShowDialog(string name, IDialogParameters parameters = null, string IdentifierName = "Root"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.DeskTop/App.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.DeskTop/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.Core.Common; 2 | using MaterialDesignInPrism.Core.Service; 3 | using MaterialDesignInPrism.DeskTop.Views; 4 | using Prism.Ioc; 5 | using Prism.Modularity; 6 | using System.Windows; 7 | 8 | namespace MaterialDesignInPrism.DeskTop 9 | { 10 | /// 11 | /// Interaction logic for App.xaml 12 | /// 13 | public partial class App 14 | { 15 | protected override Window CreateShell() 16 | { 17 | return Container.Resolve(); 18 | } 19 | 20 | protected override void RegisterTypes(IContainerRegistry containerRegistry) 21 | { 22 | containerRegistry.Register(); 23 | containerRegistry.RegisterForNavigation(); 24 | } 25 | 26 | protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) 27 | { 28 | moduleCatalog.AddModule($"颜色拾取器,PickerView"); 29 | moduleCatalog.AddModule($"字体查看器,FonPickerView"); 30 | base.ConfigureModuleCatalog(moduleCatalog); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.DeskTop/MaterialDesignInPrism.DeskTop.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | WinExe 4 | net5.0-windows 5 | true 6 | 魔法工具箱 7 | logo.ico 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.DeskTop/ModuleInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MaterialDesignInPrism.DeskTop 8 | { 9 | public class ModuleInfo 10 | { 11 | public string ModuleCode { get; set; } 12 | public string ModuleName { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.DeskTop/Properties/PublishProfiles/FolderProfile.pubxml: -------------------------------------------------------------------------------- 1 |  2 | 5 | 6 | 7 | Release 8 | Any CPU 9 | bin\Release\net5.0-windows\publish\ 10 | FileSystem 11 | net5.0-windows 12 | win-x86 13 | false 14 | True 15 | True 16 | 17 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.DeskTop/ViewModels/MainWindowViewModel.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.Core.Service; 2 | using MaterialDesignInPrism.Core.Extensions; 3 | using Prism.Commands; 4 | using Prism.Mvvm; 5 | using Prism.Regions; 6 | using System.Collections.ObjectModel; 7 | using Prism.Modularity; 8 | using System.Reflection; 9 | using System; 10 | 11 | namespace MaterialDesignInPrism.DeskTop.ViewModels 12 | { 13 | public class MainWindowViewModel : BindableBase 14 | { 15 | private readonly IRegionManager regionManager; 16 | private readonly IModuleCatalog moduleCatalog; 17 | 18 | public MainWindowViewModel(IRegionManager regionManager, IModuleCatalog moduleCatalog) 19 | { 20 | this.moduleCatalog = moduleCatalog; 21 | this.regionManager = regionManager; 22 | ModuleInfos = new ObservableCollection(); 23 | InitModuleConfig(); 24 | NavigationCommand = new DelegateCommand(NavigationPage); 25 | } 26 | 27 | public DelegateCommand NavigationCommand { get; private set; } 28 | 29 | private ObservableCollection moduleInfos; 30 | 31 | public ObservableCollection ModuleInfos 32 | { 33 | get { return moduleInfos; } 34 | set { moduleInfos = value; RaisePropertyChanged(); } 35 | } 36 | 37 | public void InitModuleConfig() 38 | { 39 | var modules = moduleCatalog.Modules; 40 | 41 | foreach (var item in modules) 42 | { 43 | var itr = item.ModuleName.Split(","); 44 | ModuleInfos.Add(new ModuleInfo() 45 | { 46 | ModuleCode = itr[1], 47 | ModuleName = itr[0] 48 | }); 49 | } 50 | } 51 | 52 | private void NavigationPage(string obj) 53 | { 54 | regionManager.Regions["ContentRegion"].RequestNavigate(obj); 55 | } 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.DeskTop/Views/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  22 | 23 | 28 | 29 | 30 | 31 | 32 | 33 | 38 | 39 | 40 | 44 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | 60 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.FontPicker/Views/FonPickerView.xaml.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignInPrism.FontPicker.ViewModels; 2 | using Prism.Events; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using System.Windows.Controls; 11 | using System.Windows.Data; 12 | using System.Windows.Documents; 13 | using System.Windows.Input; 14 | using System.Windows.Media; 15 | using System.Windows.Media.Imaging; 16 | using System.Windows.Navigation; 17 | using System.Windows.Shapes; 18 | 19 | namespace MaterialDesignInPrism.FontPicker.Views 20 | { 21 | /// 22 | /// Interaction logic for ViewA.xaml 23 | /// 24 | public partial class FonPickerView : UserControl 25 | { 26 | public FonPickerView() 27 | { 28 | InitializeComponent(); 29 | this.Drop += ViewA_Drop; 30 | } 31 | 32 | private void ViewA_Drop(object sender, DragEventArgs e) 33 | { 34 | string msg = string.Empty; 35 | if (e.Data.GetDataPresent(DataFormats.FileDrop)) 36 | msg = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); 37 | (this.DataContext as FonPickerViewModel).AddFile(msg); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/MaterialDesignInPrism.Full/MaterialDesignInPrism.Full.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialDesignInPrism.DeskTop", "MaterialDesignInPrism.DeskTop\MaterialDesignInPrism.DeskTop.csproj", "{6BB847E5-42BC-4902-8186-424908FFE117}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialDesignInPrism.Core", "MaterialDesignInPrism.Core\MaterialDesignInPrism.Core.csproj", "{42900BF5-B23B-420C-BF02-1A278D4144C0}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialDesignInPrism.ColorPicker", "MaterialDesignInPrism.ColorPicker\MaterialDesignInPrism.ColorPicker.csproj", "{72BC9FD0-30B9-486F-8707-7D8CA3E82E9D}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialDesignInPrism.FontPicker", "MaterialDesignInPrism.FontPicker\MaterialDesignInPrism.FontPicker.csproj", "{F07AAAB0-F3E9-41F9-B3EC-F6E55BE8DF73}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {6BB847E5-42BC-4902-8186-424908FFE117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {6BB847E5-42BC-4902-8186-424908FFE117}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {6BB847E5-42BC-4902-8186-424908FFE117}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {6BB847E5-42BC-4902-8186-424908FFE117}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {42900BF5-B23B-420C-BF02-1A278D4144C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {42900BF5-B23B-420C-BF02-1A278D4144C0}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {42900BF5-B23B-420C-BF02-1A278D4144C0}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {42900BF5-B23B-420C-BF02-1A278D4144C0}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {72BC9FD0-30B9-486F-8707-7D8CA3E82E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {72BC9FD0-30B9-486F-8707-7D8CA3E82E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {72BC9FD0-30B9-486F-8707-7D8CA3E82E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {72BC9FD0-30B9-486F-8707-7D8CA3E82E9D}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {F07AAAB0-F3E9-41F9-B3EC-F6E55BE8DF73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {F07AAAB0-F3E9-41F9-B3EC-F6E55BE8DF73}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {F07AAAB0-F3E9-41F9-B3EC-F6E55BE8DF73}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {F07AAAB0-F3E9-41F9-B3EC-F6E55BE8DF73}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {9D6C322D-BA77-403D-8EFD-B50FF67E487F} 42 | EndGlobalSection 43 | EndGlobal 44 | --------------------------------------------------------------------------------