├── .gitattributes ├── .gitignore ├── AnyExeToService.sln ├── AnyExeToService ├── AdvInstallHelper.cs ├── AnyExeToService.csproj ├── App.config ├── App.xaml ├── App.xaml.cs ├── ExeServiceConfig.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ ├── Settings.settings │ └── app.manifest ├── Resources │ ├── MaterialDesignColors.dll │ ├── MaterialDesignThemes.Wpf.dll │ ├── Newtonsoft.Json.dll │ ├── ServiceApp.exe │ ├── ServiceBridge.exe │ ├── install.exe │ └── log4net.dll ├── ServiceInfo.cs ├── main.ico ├── packages.config └── preferences_management_service_128px_1172109_easyicon.net.ico ├── LICENSE ├── README.md ├── ServiceApp ├── ExeProcess.cs ├── MainService.Designer.cs ├── MainService.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Resources │ ├── Newtonsoft.Json.dll │ └── log4net.dll.dat ├── ServiceApp.csproj ├── ServiceConfig.cs └── log4net.config ├── images └── index.PNG └── packages ├── MaterialDesignColors.1.1.2 ├── .signature.p7s ├── MaterialDesignColors.1.1.2.nupkg └── lib │ └── net45 │ └── MaterialDesignColors.dll ├── MaterialDesignThemes.2.5.1 ├── .signature.p7s ├── MaterialDesignThemes.2.5.1.nupkg ├── lib │ └── net45 │ │ ├── MaterialDesignThemes.Wpf.XML │ │ └── MaterialDesignThemes.Wpf.dll └── src │ └── net45 │ ├── Badged.cs │ ├── BaseTheme.cs │ ├── ButtonProgressAssist.cs │ ├── Card.cs │ ├── Chip.cs │ ├── Clock.cs │ ├── ClockChoiceMadeEventArgs.cs │ ├── ClockItemButton.cs │ ├── ColorZone.cs │ ├── ColorZoneAssist.cs │ ├── ComboBoxAssist.cs │ ├── ComboBoxPopup.cs │ ├── Converters │ ├── BooleanToVisibilityConverter.cs │ ├── BrushRoundConverter.cs │ ├── BrushToRadialGradientBrushConverter.cs │ ├── CalendarDateCoalesceConverter.cs │ ├── CircularProgressBar │ │ ├── ArcEndPointConverter.cs │ │ ├── ArcSizeConverter.cs │ │ ├── LargeArcConverter.cs │ │ ├── LocalEx.cs │ │ ├── RotateTransformCentreConverter.cs │ │ └── StartPointConverter.cs │ ├── ClockItemIsCheckedConverter.cs │ ├── ClockLineConverter.cs │ ├── DrawerOffsetConverter.cs │ ├── EqualityToVisibilityConverter.cs │ ├── HintProxyFabricConverter.cs │ ├── ListViewItemContainerStyleConverter.cs │ ├── MathConverter.cs │ ├── MathMultipleConverter.cs │ ├── NotConverter.cs │ ├── NotZeroConverter.cs │ ├── NotZeroToVisibilityConverter.cs │ ├── NullToVisibilityConverter.cs │ ├── NullableDateTimeToCurrentDateConverter.cs │ ├── PointValueConverter.cs │ ├── RangeLengthConverter.cs │ ├── RangePositionConverterConverter.cs │ ├── ShadowConverter.cs │ ├── ShadowEdgeConverter.cs │ ├── ShadowInfo.cs │ ├── SizeToRectConverter.cs │ ├── SnackbarMessageTypeConverter.cs │ ├── TextFieldHintVisibilityConverter.cs │ └── TimeToVisibilityConverter.cs │ ├── CustomPopupPlacementCallbackHelper.cs │ ├── DataGridAssist.cs │ ├── DateTimeEx.cs │ ├── DialogClosingEventArgs.cs │ ├── DialogClosingEventHandler.cs │ ├── DialogHost.cs │ ├── DialogHostEx.cs │ ├── DialogOpenedEventArgs.cs │ ├── DialogOpenedEventHandler.cs │ ├── DialogSession.cs │ ├── DpiHelper.cs │ ├── DrawerHost.cs │ ├── ExpanderAssist.cs │ ├── Extensions.cs │ ├── Flipper.cs │ ├── HintAssist.cs │ ├── HintProxyFabric.ComboBox.cs │ ├── HintProxyFabric.PasswordBox.cs │ ├── HintProxyFabric.TextBox.cs │ ├── HintProxyFabric.cs │ ├── IHintProxy.cs │ ├── ISnackbarMessageQueue.cs │ ├── Icon.cs │ ├── IconType.cs │ ├── ListBoxAssist.cs │ ├── ListSortDirectionIndicator.cs │ ├── ListViewAssist.cs │ ├── MaterialDataGridComboBoxColumn.cs │ ├── MaterialDataGridTextColumn.cs │ ├── MaterialDateDisplay.cs │ ├── MessageQueueExtension.cs │ ├── PackIcon.cs │ ├── PackIconDataFactory.cs │ ├── PackIconExtension.cs │ ├── PackIconKind.cs │ ├── Palette.cs │ ├── PaletteHelper.cs │ ├── Plane3D.cs │ ├── PopupBox.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Settings.Designer.cs │ ├── RatingBar.cs │ ├── RatingBarButton.cs │ ├── Ripple.cs │ ├── RippleAssist.cs │ ├── ScaleHost.cs │ ├── Screen.cs │ ├── ScrollViewerAssist.cs │ ├── ShadowAssist.cs │ ├── SmartHint.cs │ ├── Snackbar.cs │ ├── SnackbarMessage.cs │ ├── SnackbarMessageEventArgs.cs │ ├── SnackbarMessageQueue.cs │ ├── SnackbarMessageQueueItem.cs │ ├── Spelling.cs │ ├── StringExtensions.cs │ ├── TextFieldAssist.cs │ ├── ThemeAssist.cs │ ├── TimePicker.cs │ ├── ToggleButtonAssist.cs │ ├── ToolTipAssist.cs │ ├── Transitions │ ├── CircleWipe.cs │ ├── FadeWipe.cs │ ├── ITransitionEffect.cs │ ├── ITransitionEffectSubject.cs │ ├── ITransitionWipe.cs │ ├── IZIndexController.cs │ ├── IndexedItemOffsetMultiplierExtension.cs │ ├── SlideDirection.cs │ ├── SlideOutWipe.cs │ ├── SlideWipe.cs │ ├── TransitionAssist.cs │ ├── TransitionEffect.cs │ ├── TransitionEffectBase.cs │ ├── TransitionEffectExtension.cs │ ├── TransitionEffectKind.cs │ ├── TransitionEffectTypeConverter.cs │ ├── Transitioner.cs │ ├── TransitionerSlide.cs │ ├── TransitionerSlideState.cs │ ├── TransitioningContent.cs │ └── TransitioningContentBase.cs │ ├── TreeHelper.cs │ ├── TreeViewAssist.cs │ ├── Underline.cs │ └── ValidationAssist.cs ├── Newtonsoft.Json.dll └── log4net.dll /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /AnyExeToService.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2050 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnyExeToService", "AnyExeToService\AnyExeToService.csproj", "{ADF4F772-01C7-4D07-A084-5F8069505323}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceApp", "ServiceApp\ServiceApp.csproj", "{5336321A-ED85-41BE-B03A-01EE82537455}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {ADF4F772-01C7-4D07-A084-5F8069505323}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {ADF4F772-01C7-4D07-A084-5F8069505323}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {ADF4F772-01C7-4D07-A084-5F8069505323}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {ADF4F772-01C7-4D07-A084-5F8069505323}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {5336321A-ED85-41BE-B03A-01EE82537455}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {5336321A-ED85-41BE-B03A-01EE82537455}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {5336321A-ED85-41BE-B03A-01EE82537455}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {5336321A-ED85-41BE-B03A-01EE82537455}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {C4B5404A-6CAA-4A6E-999B-B210967B4546} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /AnyExeToService/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /AnyExeToService/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /AnyExeToService/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using System.Windows; 5 | 6 | namespace AnyExeToService 7 | { 8 | /// 9 | /// App.xaml 的交互逻辑 10 | /// 11 | public partial class App : Application 12 | { 13 | static App() 14 | { 15 | File.WriteAllBytes("MaterialDesignThemes.Wpf.dll", AnyExeToService.Properties.Resources.MaterialDesignThemes_Wpf); 16 | File.WriteAllBytes("MaterialDesignColors.dll", AnyExeToService.Properties.Resources.MaterialDesignColors); 17 | AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; 18 | } 19 | 20 | private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) 21 | { 22 | return args.Name.Contains("Newtonsoft.Json") ? Assembly.Load(AnyExeToService.Properties.Resources.Newtonsoft_Json) : null; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AnyExeToService/ExeServiceConfig.cs: -------------------------------------------------------------------------------- 1 | namespace AnyExeToService 2 | { 3 | class ExeServiceConfig 4 | { 5 | public string Exe { get; set; } 6 | public string Argument { get; set; } 7 | public bool RedirectStandardInput { get; set; } = true; 8 | public bool RedirectStandardOutput { get; set; } = true; 9 | public bool UseShellExecute { get; set; } = false; 10 | public bool CreateNoWindow { get; set; } = true; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AnyExeToService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // 有关程序集的一般信息由以下 8 | // 控制。更改这些特性值可修改 9 | // 与程序集关联的信息。 10 | [assembly: AssemblyTitle("AnyExeToService")] 11 | [assembly: AssemblyDescription("将任意程序安装成Windows服务")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("HP Inc.")] 14 | [assembly: AssemblyProduct("AnyExeToService")] 15 | [assembly: AssemblyCopyright("Copyright © HP Inc. 2019")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // 将 ComVisible 设置为 false 会使此程序集中的类型 20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 21 | //请将此类型的 ComVisible 特性设置为 true。 22 | [assembly: ComVisible(false)] 23 | 24 | //若要开始生成可本地化的应用程序,请设置 25 | //.csproj 文件中的 CultureYouAreCodingWith 26 | //例如,如果您在源文件中使用的是美国英语, 27 | //使用的是美国英语,请将 设置为 en-US。 然后取消 28 | //对以下 NeutralResourceLanguage 特性的注释。 更新 29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置 36 | //(未在页面中找到资源时使用, 37 | //或应用程序资源字典中找到时使用) 38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 39 | //(未在页面中找到资源时使用, 40 | //、应用程序或任何主题专用资源字典中找到时使用) 41 | )] 42 | 43 | 44 | // 程序集的版本信息由下列四个值组成: 45 | // 46 | // 主版本 47 | // 次版本 48 | // 生成号 49 | // 修订号 50 | // 51 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 52 | // 方法是按如下所示使用“*”: : 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.2.0")] 55 | [assembly: AssemblyFileVersion("1.0.2.0")] 56 | -------------------------------------------------------------------------------- /AnyExeToService/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace AnyExeToService.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.6.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AnyExeToService/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /AnyExeToService/Properties/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 54 | 55 | 69 | -------------------------------------------------------------------------------- /AnyExeToService/Resources/MaterialDesignColors.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/AnyExeToService/Resources/MaterialDesignColors.dll -------------------------------------------------------------------------------- /AnyExeToService/Resources/MaterialDesignThemes.Wpf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/AnyExeToService/Resources/MaterialDesignThemes.Wpf.dll -------------------------------------------------------------------------------- /AnyExeToService/Resources/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/AnyExeToService/Resources/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /AnyExeToService/Resources/ServiceApp.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/AnyExeToService/Resources/ServiceApp.exe -------------------------------------------------------------------------------- /AnyExeToService/Resources/ServiceBridge.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/AnyExeToService/Resources/ServiceBridge.exe -------------------------------------------------------------------------------- /AnyExeToService/Resources/install.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/AnyExeToService/Resources/install.exe -------------------------------------------------------------------------------- /AnyExeToService/Resources/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/AnyExeToService/Resources/log4net.dll -------------------------------------------------------------------------------- /AnyExeToService/main.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/AnyExeToService/main.ico -------------------------------------------------------------------------------- /AnyExeToService/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /AnyExeToService/preferences_management_service_128px_1172109_easyicon.net.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/AnyExeToService/preferences_management_service_128px_1172109_easyicon.net.ico -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 cxwl3sxl 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AnyExeToService 将任意exe程序安装成windows服务 屏幕截图 ![](https://github.com/cxwl3sxl/AnyExeToService/blob/master/images/index.PNG) [下载地址](https://github.com/cxwl3sxl/AnyExeToService/releases "下载地址") # 原理 基于Instsrv.exe和srvany.exe实现 -------------------------------------------------------------------------------- /ServiceApp/ExeProcess.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Threading; 5 | using log4net; 6 | 7 | namespace ServiceApp 8 | { 9 | class ExeProcess 10 | { 11 | private readonly ServiceConfig _config; 12 | private Process _mainProcess; 13 | private readonly ILog _log = LogManager.GetLogger(typeof(ExeProcess)); 14 | private bool _stop = false; 15 | public ExeProcess(ServiceConfig config) 16 | { 17 | _config = config ?? throw new Exception("配置对象不能为空!"); 18 | } 19 | 20 | public void Start() 21 | { 22 | StartProcess(); 23 | ThreadPool.QueueUserWorkItem(ProcessEye); 24 | _log.Info("服务已经成功启动."); 25 | } 26 | 27 | private void _mainProcess_OutputDataReceived(object sender, DataReceivedEventArgs e) 28 | { 29 | _log.Debug(e.Data); 30 | } 31 | 32 | void StartProcess() 33 | { 34 | _mainProcess?.Kill(); 35 | _mainProcess?.Dispose(); 36 | _log.Debug($"程序路径:{_config.Exe}"); 37 | _log.Debug($"启动参数:{_config.Argument}"); 38 | _mainProcess = new Process 39 | { 40 | StartInfo = new ProcessStartInfo(_config.Exe) 41 | { 42 | WorkingDirectory = Path.GetDirectoryName(_config.Exe) ?? throw new InvalidOperationException(), 43 | Arguments = _config.Argument, 44 | RedirectStandardInput = _config.RedirectStandardInput, 45 | RedirectStandardOutput = _config.RedirectStandardOutput, 46 | UseShellExecute = _config.UseShellExecute, 47 | CreateNoWindow = _config.CreateNoWindow 48 | } 49 | }; 50 | if (_config.RedirectStandardOutput) 51 | _mainProcess.OutputDataReceived += _mainProcess_OutputDataReceived; 52 | _mainProcess.Start(); 53 | _log.Info($"服务进程{Path.GetFileName(_config.Exe)}已经启动,进程ID:{_mainProcess.Id}"); 54 | } 55 | 56 | void ProcessEye(object notUsed) 57 | { 58 | while (!_stop) 59 | { 60 | try 61 | { 62 | if (_mainProcess == null) 63 | { 64 | Thread.Sleep(1000); 65 | continue; 66 | } 67 | if (_mainProcess.HasExited) 68 | { 69 | _mainProcess.Dispose(); 70 | _mainProcess = null; 71 | _log.Warn($"检测到服务进程结束,正在重启..."); 72 | StartProcess(); 73 | } 74 | else 75 | { 76 | Thread.Sleep(500); 77 | } 78 | } 79 | catch (Exception ex) 80 | { 81 | _log.Warn($"监测出错", ex); 82 | } 83 | } 84 | } 85 | 86 | public void Stop() 87 | { 88 | _stop = true; 89 | _mainProcess?.Kill(); 90 | _log.Info("服务已经成功停止."); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /ServiceApp/MainService.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace ServiceApp 2 | { 3 | partial class MainService 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | /// 如果应释放托管资源,为 true;否则为 false。 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region 组件设计器生成的代码 24 | 25 | /// 26 | /// 设计器支持所需的方法 - 不要修改 27 | /// 使用代码编辑器修改此方法的内容。 28 | /// 29 | private void InitializeComponent() 30 | { 31 | components = new System.ComponentModel.Container(); 32 | this.ServiceName = "MainService"; 33 | } 34 | 35 | #endregion 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ServiceApp/MainService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using System.ServiceProcess; 5 | using log4net; 6 | using Newtonsoft.Json; 7 | 8 | namespace ServiceApp 9 | { 10 | partial class MainService : ServiceBase 11 | { 12 | private readonly ServiceConfig _config; 13 | private readonly ExeProcess _exeProcess; 14 | private readonly ILog _log = LogManager.GetLogger(typeof(MainService)); 15 | public MainService() 16 | { 17 | InitializeComponent(); 18 | var appName = Assembly.GetExecutingAssembly().Location; 19 | var configFile = $"{appName}.json"; 20 | if (!File.Exists(configFile)) return; 21 | var configContent = File.ReadAllText(configFile); 22 | try 23 | { 24 | _config = JsonConvert.DeserializeObject(configContent); 25 | if (!File.Exists(_config.Exe)) throw new Exception($"指定的启动程序{_config.Exe}不存在"); 26 | _exeProcess = new ExeProcess(_config); 27 | } 28 | catch (Exception ex) 29 | { 30 | _log.Warn("读取服务配置文件出错", ex); 31 | _log.Warn($"配置文件地址为:{configFile}"); 32 | _log.Warn($"配置文件内容为:{Environment.NewLine}{configContent}"); 33 | } 34 | } 35 | 36 | protected override void OnStart(string[] args) 37 | { 38 | if (_config == null) return; 39 | try 40 | { 41 | _exeProcess?.Start(); 42 | } 43 | catch (Exception ex) 44 | { 45 | _log.Warn("启动服务出错", ex); 46 | throw; 47 | } 48 | } 49 | 50 | protected override void OnStop() 51 | { 52 | if (_config == null) return; 53 | try 54 | { 55 | _exeProcess?.Stop(); 56 | } 57 | catch (Exception ex) 58 | { 59 | _log.Warn("停止服务出错", ex); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ServiceApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Reflection; 5 | using System.ServiceProcess; 6 | using System.Threading; 7 | using log4net; 8 | 9 | namespace ServiceApp 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | var processName = Process.GetCurrentProcess().ProcessName; 16 | var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), processName); 17 | if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); 18 | Trace.WriteLine($"当前正在使用的日志路径为:{dir}"); 19 | var logConfig = $"{dir}\\{processName}.log.config"; 20 | if (!File.Exists(logConfig)) 21 | { 22 | File.WriteAllText(logConfig, Properties.Resources.log4net1.Replace("$DIR$", dir).Replace("\\", "\\\\")); 23 | } 24 | 25 | AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; 26 | log4net.Config.XmlConfigurator.Configure(new Uri(logConfig)); 27 | 28 | var log = LogManager.GetLogger(typeof(Program)); 29 | try 30 | { 31 | var servicesToRun = new ServiceBase[] { new MainService() }; 32 | ServiceBase.Run(servicesToRun); 33 | } 34 | catch (Exception ex) 35 | { 36 | log.Fatal("启动服务出错", ex); 37 | } 38 | } 39 | 40 | private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) 41 | { 42 | if (args.Name.Contains("Newtonsoft.Json")) 43 | return Assembly.Load(Properties.Resources.Newtonsoft_Json); 44 | if (args.Name.Contains("log4net")) 45 | return Assembly.Load(Properties.Resources.log4net_dll); 46 | return null; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ServiceApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("ServiceApp")] 9 | [assembly: AssemblyDescription("将任意程序安装成Windows服务的辅助程序")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HP Inc.")] 12 | [assembly: AssemblyProduct("ServiceApp")] 13 | [assembly: AssemblyCopyright("Copyright © HP Inc. 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("5336321a-ed85-41be-b03a-01ee82537455")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.2.0")] 36 | [assembly: AssemblyFileVersion("1.0.2.0")] 37 | -------------------------------------------------------------------------------- /ServiceApp/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ServiceApp.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ServiceApp.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// 查找 System.Byte[] 类型的本地化资源。 65 | /// 66 | internal static byte[] log4net_dll { 67 | get { 68 | object obj = ResourceManager.GetObject("log4net_dll", resourceCulture); 69 | return ((byte[])(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// 查找类似 <?xml version="1.0" encoding="utf-8" ?> 75 | /// 76 | ///<configuration> 77 | /// <configSections> 78 | /// <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> 79 | /// </configSections> 80 | /// <log4net> 81 | /// <appender name="RootAppender" type="log4net.Appender.RollingFileAppender"> 82 | /// <param name="File" value="#ROOT#\\" /> 83 | /// <param name="AppendToFile" value="true" /> 84 | /// <param name="MaxFileSize" value="10240" /> 85 | /// <param name="MaxSizeRollBackups" value="100" /> 86 | /// <param name="S [字符串的其余部分被截断]"; 的本地化字符串。 87 | /// 88 | internal static string log4net1 { 89 | get { 90 | return ResourceManager.GetString("log4net1", resourceCulture); 91 | } 92 | } 93 | 94 | /// 95 | /// 查找 System.Byte[] 类型的本地化资源。 96 | /// 97 | internal static byte[] Newtonsoft_Json { 98 | get { 99 | object obj = ResourceManager.GetObject("Newtonsoft_Json", resourceCulture); 100 | return ((byte[])(obj)); 101 | } 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /ServiceApp/Resources/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/ServiceApp/Resources/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /ServiceApp/Resources/log4net.dll.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/ServiceApp/Resources/log4net.dll.dat -------------------------------------------------------------------------------- /ServiceApp/ServiceApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5336321A-ED85-41BE-B03A-01EE82537455} 8 | Exe 9 | ServiceApp 10 | ServiceApp 11 | v4.0 12 | 512 13 | true 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | ..\AnyExeToService\Resources\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | False 38 | ..\packages\log4net.dll 39 | 40 | 41 | False 42 | ..\packages\Newtonsoft.Json.dll 43 | False 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | Component 60 | 61 | 62 | MainService.cs 63 | 64 | 65 | 66 | 67 | True 68 | True 69 | Resources.resx 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | ResXFileCodeGenerator 79 | Resources.Designer.cs 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /ServiceApp/ServiceConfig.cs: -------------------------------------------------------------------------------- 1 | namespace ServiceApp 2 | { 3 | class ServiceConfig 4 | { 5 | public string Exe { get; set; } 6 | public string Argument { get; set; } 7 | public bool RedirectStandardInput { get; set; } = true; 8 | public bool RedirectStandardOutput { get; set; } = true; 9 | public bool UseShellExecute { get; set; } = false; 10 | public bool CreateNoWindow { get; set; } = true; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ServiceApp/log4net.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /images/index.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/images/index.PNG -------------------------------------------------------------------------------- /packages/MaterialDesignColors.1.1.2/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/packages/MaterialDesignColors.1.1.2/.signature.p7s -------------------------------------------------------------------------------- /packages/MaterialDesignColors.1.1.2/MaterialDesignColors.1.1.2.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/packages/MaterialDesignColors.1.1.2/MaterialDesignColors.1.1.2.nupkg -------------------------------------------------------------------------------- /packages/MaterialDesignColors.1.1.2/lib/net45/MaterialDesignColors.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/packages/MaterialDesignColors.1.1.2/lib/net45/MaterialDesignColors.dll -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/packages/MaterialDesignThemes.2.5.1/.signature.p7s -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/MaterialDesignThemes.2.5.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/packages/MaterialDesignThemes.2.5.1/MaterialDesignThemes.2.5.1.nupkg -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/lib/net45/MaterialDesignThemes.Wpf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/packages/MaterialDesignThemes.2.5.1/lib/net45/MaterialDesignThemes.Wpf.dll -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Badged.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Windows; 4 | using System.Windows.Media.Animation; 5 | using ControlzEx; 6 | 7 | namespace MaterialDesignThemes.Wpf 8 | { 9 | [TemplatePart(Name = BadgeContainerPartName, Type = typeof(UIElement))] 10 | public class Badged : BadgedEx 11 | { 12 | public static readonly DependencyProperty BadgeChangedStoryboardProperty = DependencyProperty.Register( 13 | "BadgeChangedStoryboard", typeof(Storyboard), typeof(Badged), new PropertyMetadata(default(Storyboard))); 14 | 15 | public Storyboard BadgeChangedStoryboard 16 | { 17 | get { return (Storyboard)this.GetValue(BadgeChangedStoryboardProperty); } 18 | set { this.SetValue(BadgeChangedStoryboardProperty, value); } 19 | } 20 | 21 | static Badged() 22 | { 23 | DefaultStyleKeyProperty.OverrideMetadata(typeof(Badged), new FrameworkPropertyMetadata(typeof(Badged))); 24 | } 25 | 26 | public static readonly DependencyProperty BadgeColorZoneModeProperty = DependencyProperty.Register( 27 | "BadgeColorZoneMode", typeof(ColorZoneMode), typeof(Badged), new PropertyMetadata(default(ColorZoneMode))); 28 | 29 | public ColorZoneMode BadgeColorZoneMode 30 | { 31 | get { return (ColorZoneMode) GetValue(BadgeColorZoneModeProperty); } 32 | set { SetValue(BadgeColorZoneModeProperty, value); } 33 | } 34 | 35 | public override void OnApplyTemplate() 36 | { 37 | this.BadgeChanged -= this.OnBadgeChanged; 38 | 39 | base.OnApplyTemplate(); 40 | 41 | this.BadgeChanged += this.OnBadgeChanged; 42 | } 43 | 44 | private void OnBadgeChanged(object sender, RoutedPropertyChangedEventArgs e) 45 | { 46 | var sb = this.BadgeChangedStoryboard; 47 | if (this._badgeContainer != null && sb != null) 48 | { 49 | try 50 | { 51 | this._badgeContainer.BeginStoryboard(sb); 52 | } 53 | catch (Exception exc) 54 | { 55 | Trace.WriteLine("Error during Storyboard execution, exception will be rethrown."); 56 | Trace.WriteLine($"{exc.Message} ({exc.GetType().FullName})"); 57 | Trace.WriteLine(exc.StackTrace); 58 | 59 | throw; 60 | } 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/BaseTheme.cs: -------------------------------------------------------------------------------- 1 | namespace MaterialDesignThemes.Wpf 2 | { 3 | public enum BaseTheme 4 | { 5 | Inherit, 6 | Light, 7 | Dark 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Card.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Media; 5 | 6 | namespace MaterialDesignThemes.Wpf 7 | { 8 | /// 9 | /// A card is a content control, styled according to Material Design guidelines. 10 | /// 11 | [TemplatePart(Name = ClipBorderPartName, Type = typeof(Border))] 12 | public class Card : ContentControl 13 | { 14 | public const string ClipBorderPartName = "PART_ClipBorder"; 15 | 16 | private Border _clipBorder; 17 | 18 | static Card() 19 | { 20 | DefaultStyleKeyProperty.OverrideMetadata(typeof(Card), new FrameworkPropertyMetadata(typeof(Card))); 21 | } 22 | 23 | public override void OnApplyTemplate() 24 | { 25 | base.OnApplyTemplate(); 26 | 27 | _clipBorder = Template.FindName(ClipBorderPartName, this) as Border; 28 | } 29 | 30 | protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) 31 | { 32 | base.OnRenderSizeChanged(sizeInfo); 33 | 34 | if (_clipBorder == null) return; 35 | 36 | var farPoint = new Point( 37 | Math.Max(0, _clipBorder.ActualWidth), 38 | Math.Max(0, _clipBorder.ActualHeight)); 39 | 40 | var clipRect = new Rect( 41 | new Point(), 42 | new Point(farPoint.X, farPoint.Y)); 43 | 44 | ContentClip = new RectangleGeometry(clipRect, UniformCornerRadius, UniformCornerRadius); 45 | } 46 | 47 | public static readonly DependencyProperty UniformCornerRadiusProperty = DependencyProperty.Register( 48 | nameof(UniformCornerRadius), typeof (double), typeof (Card), new FrameworkPropertyMetadata(2.0, FrameworkPropertyMetadataOptions.AffectsMeasure)); 49 | 50 | public double UniformCornerRadius 51 | { 52 | get { return (double) GetValue(UniformCornerRadiusProperty); } 53 | set { SetValue(UniformCornerRadiusProperty, value); } 54 | } 55 | 56 | private static readonly DependencyPropertyKey ContentClipPropertyKey = 57 | DependencyProperty.RegisterReadOnly( 58 | "ContentClip", typeof (Geometry), typeof (Card), 59 | new PropertyMetadata(default(Geometry))); 60 | 61 | public static readonly DependencyProperty ContentClipProperty = 62 | ContentClipPropertyKey.DependencyProperty; 63 | 64 | public Geometry ContentClip 65 | { 66 | get { return (Geometry) GetValue(ContentClipProperty); } 67 | private set { SetValue(ContentClipPropertyKey, value); } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ClockChoiceMadeEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | public delegate void ClockChoiceMadeEventHandler(object sender, ClockChoiceMadeEventArgs e); 6 | 7 | public class ClockChoiceMadeEventArgs : RoutedEventArgs 8 | { 9 | private readonly ClockDisplayMode _displayMode; 10 | 11 | public ClockChoiceMadeEventArgs(ClockDisplayMode displayMode) 12 | { 13 | _displayMode = displayMode; 14 | } 15 | 16 | public ClockChoiceMadeEventArgs(ClockDisplayMode displayMode, RoutedEvent routedEvent) : base(routedEvent) 17 | { 18 | _displayMode = displayMode; 19 | } 20 | 21 | public ClockChoiceMadeEventArgs(ClockDisplayMode displayMode, RoutedEvent routedEvent, object source) : base(routedEvent, source) 22 | { 23 | _displayMode = displayMode; 24 | } 25 | 26 | public ClockDisplayMode Mode 27 | { 28 | get { return _displayMode; } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ColorZone.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public enum ColorZoneMode 7 | { 8 | Standard, 9 | Inverted, 10 | PrimaryLight, 11 | PrimaryMid, 12 | PrimaryDark, 13 | Accent, 14 | Light, 15 | Dark 16 | } 17 | 18 | /// 19 | /// User a colour zone to easily switch the background and foreground colours, whilst still remaining within the selected Material Design palette. 20 | /// 21 | public class ColorZone : ContentControl 22 | { 23 | static ColorZone() 24 | { 25 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorZone), new FrameworkPropertyMetadata(typeof(ColorZone))); 26 | } 27 | 28 | public static readonly DependencyProperty ModeProperty = DependencyProperty.Register( 29 | nameof(Mode), typeof (ColorZoneMode), typeof (ColorZone), new PropertyMetadata(default(ColorZoneMode))); 30 | 31 | public ColorZoneMode Mode 32 | { 33 | get { return (ColorZoneMode) GetValue(ModeProperty); } 34 | set { SetValue(ModeProperty, value); } 35 | } 36 | 37 | public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register( 38 | nameof(CornerRadius), typeof (CornerRadius), typeof (ColorZone), new PropertyMetadata(default(CornerRadius))); 39 | 40 | public CornerRadius CornerRadius 41 | { 42 | get { return (CornerRadius) GetValue(CornerRadiusProperty); } 43 | set { SetValue(CornerRadiusProperty, value); } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ColorZoneAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | public static class ColorZoneAssist 6 | { 7 | public static readonly DependencyProperty ModeProperty = DependencyProperty.RegisterAttached( 8 | "Mode", typeof(ColorZoneMode), typeof(ColorZoneAssist), new FrameworkPropertyMetadata(default(ColorZoneMode), FrameworkPropertyMetadataOptions.Inherits)); 9 | 10 | public static void SetMode(DependencyObject element, ColorZoneMode value) 11 | { 12 | element.SetValue(ModeProperty, value); 13 | } 14 | 15 | public static ColorZoneMode GetMode(DependencyObject element) 16 | { 17 | return (ColorZoneMode)element.GetValue(ModeProperty); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ComboBoxAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | public static class ComboBoxAssist 6 | { 7 | /// 8 | /// By default ComboBox uses the wrapper popup. Popup can be switched to classic Windows desktop view by means of this attached property. 9 | /// 10 | public static readonly DependencyProperty ClassicModeProperty = DependencyProperty.RegisterAttached( 11 | "ClassicMode", 12 | typeof (bool), 13 | typeof (ComboBoxAssist), 14 | new FrameworkPropertyMetadata(false, 15 | FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits)); 16 | 17 | public static bool GetClassicMode(DependencyObject element) 18 | { 19 | return (bool)element.GetValue(ClassicModeProperty); 20 | } 21 | 22 | public static void SetClassicMode(DependencyObject element, object value) 23 | { 24 | element.SetValue(ClassicModeProperty, value); 25 | } 26 | 27 | /// 28 | /// By default the selected item is hidden from the drop down list, as per Material Design specifications. 29 | /// To revert to a more classic Windows desktop behaviour, and show the currently selected item again in the drop 30 | /// down, set this attached propety to true. 31 | /// 32 | public static readonly DependencyProperty ShowSelectedItemProperty = DependencyProperty.RegisterAttached( 33 | "ShowSelectedItem", 34 | typeof (bool), 35 | typeof (ComboBoxAssist), 36 | new FrameworkPropertyMetadata(false, 37 | FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits)); 38 | 39 | public static bool GetShowSelectedItem(DependencyObject element) 40 | { 41 | return (bool)element.GetValue(ShowSelectedItemProperty); 42 | } 43 | 44 | public static void SetShowSelectedItem(DependencyObject element, object value) 45 | { 46 | element.SetValue(ShowSelectedItemProperty, value); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/BooleanToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class BooleanToVisibilityConverter : IValueConverter 9 | { 10 | public Visibility TrueValue { get; set; } = Visibility.Visible; 11 | public Visibility FalseValue { get; set; } = Visibility.Collapsed; 12 | 13 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 14 | { 15 | bool bValue = false; 16 | if (value is bool) 17 | { 18 | bValue = (bool)value; 19 | } 20 | 21 | return (bValue) ? TrueValue : FalseValue; 22 | } 23 | 24 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 25 | { 26 | return value as Visibility? == TrueValue; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/BrushRoundConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | using System.Windows.Media; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class BrushRoundConverter : IValueConverter 9 | { 10 | public Brush HighValue { get; set; } = Brushes.White; 11 | 12 | public Brush LowValue { get; set; } = Brushes.Black; 13 | 14 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | var solidColorBrush = value as SolidColorBrush; 17 | if (solidColorBrush == null) return null; 18 | 19 | var color = solidColorBrush.Color; 20 | 21 | var brightness = 0.3 * color.R + 0.59 * color.G + 0.11 * color.B; 22 | 23 | return brightness < 123 ? LowValue : HighValue; 24 | } 25 | 26 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 27 | { 28 | return Binding.DoNothing; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/BrushToRadialGradientBrushConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | using System.Windows.Media; 6 | 7 | namespace MaterialDesignThemes.Wpf.Converters 8 | { 9 | public class BrushToRadialGradientBrushConverter : IValueConverter 10 | { 11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 12 | { 13 | var solidColorBrush = value as SolidColorBrush; 14 | if (solidColorBrush == null) return Binding.DoNothing; 15 | 16 | return new RadialGradientBrush(solidColorBrush.Color, Colors.Transparent) 17 | { 18 | Center = new Point(.5, .5), 19 | GradientOrigin = new Point(.5, .5), 20 | RadiusX = .75, 21 | RadiusY = .75, 22 | Opacity = .39 23 | }; 24 | } 25 | 26 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 27 | { 28 | return Binding.DoNothing; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/CalendarDateCoalesceConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace MaterialDesignThemes.Wpf.Converters 6 | { 7 | /// 8 | /// Help us format the content of a header button in a calendar. 9 | /// 10 | /// 11 | /// Expected items, in the following order: 12 | /// 1) DateTime Calendar.DisplayDate 13 | /// 2) DateTime? Calendar.SelectedDate 14 | /// 15 | public class CalendarDateCoalesceConverter : IMultiValueConverter 16 | { 17 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 18 | { 19 | if (values.Length != 2) throw new ArgumentException("Unexpected", "values"); 20 | if (!(values[0] is DateTime)) throw new ArgumentException("Unexpected", "values"); 21 | if (values[1] != null && !(values[1] is DateTime?)) throw new ArgumentException("Unexpected", "values"); 22 | 23 | var selectedDate = (DateTime?) values[1]; 24 | 25 | return selectedDate ?? values[0]; 26 | } 27 | 28 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 29 | { 30 | return null; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/CircularProgressBar/ArcEndPointConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters.CircularProgressBar 7 | { 8 | public class ArcEndPointConverter : IMultiValueConverter 9 | { 10 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | var actualWidth = values[0].ExtractDouble(); 13 | var value = values[1].ExtractDouble(); 14 | var minimum = values[2].ExtractDouble(); 15 | var maximum = values[3].ExtractDouble(); 16 | 17 | if (new[] {actualWidth, value, minimum, maximum}.AnyNan()) 18 | return Binding.DoNothing; 19 | 20 | if (values.Length == 5) 21 | { 22 | var fullIndeterminateScaling = values[4].ExtractDouble(); 23 | if (!double.IsNaN(fullIndeterminateScaling) && fullIndeterminateScaling > 0.0) 24 | { 25 | value = (maximum - minimum)*fullIndeterminateScaling; 26 | } 27 | } 28 | 29 | var percent = maximum <= minimum ? 1.0 : (value - minimum)/(maximum - minimum); 30 | var degrees = 360*percent; 31 | var radians = degrees*(Math.PI/180); 32 | 33 | var centre = new Point(actualWidth/2, actualWidth/2); 34 | var hypotenuseRadius = (actualWidth/2); 35 | 36 | var adjacent = Math.Cos(radians)*hypotenuseRadius; 37 | var opposite = Math.Sin(radians)*hypotenuseRadius; 38 | 39 | return new Point(centre.X + opposite, centre.Y - adjacent); 40 | } 41 | 42 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 43 | { 44 | throw new NotImplementedException(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/CircularProgressBar/ArcSizeConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters.CircularProgressBar 7 | { 8 | public class ArcSizeConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | if (value is double && ((double)value > 0.0)) 13 | { 14 | return new Size((double)value / 2, (double)value / 2); 15 | } 16 | 17 | return new Point(); 18 | } 19 | 20 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 21 | { 22 | return Binding.DoNothing; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/CircularProgressBar/LargeArcConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace MaterialDesignThemes.Wpf.Converters.CircularProgressBar 6 | { 7 | public class LargeArcConverter : IMultiValueConverter 8 | { 9 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 10 | { 11 | var value = values[0].ExtractDouble(); 12 | var minimum = values[1].ExtractDouble(); 13 | var maximum = values[2].ExtractDouble(); 14 | 15 | if (new[] { value, minimum, maximum }.AnyNan()) 16 | return Binding.DoNothing; 17 | 18 | if (values.Length == 4) 19 | { 20 | var fullIndeterminateScaling = values[3].ExtractDouble(); 21 | if (!double.IsNaN(fullIndeterminateScaling) && fullIndeterminateScaling > 0.0) 22 | { 23 | value = (maximum - minimum) * fullIndeterminateScaling; 24 | } 25 | } 26 | 27 | var percent = maximum <= minimum ? 1.0 : (value - minimum) / (maximum - minimum); 28 | 29 | return percent > 0.5; 30 | } 31 | 32 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 33 | { 34 | throw new NotImplementedException(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/CircularProgressBar/LocalEx.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace MaterialDesignThemes.Wpf.Converters.CircularProgressBar 5 | { 6 | internal static class LocalEx 7 | { 8 | public static double ExtractDouble(this object val) 9 | { 10 | var d = val as double? ?? double.NaN; 11 | return double.IsInfinity(d) ? double.NaN : d; 12 | } 13 | 14 | 15 | public static bool AnyNan(this IEnumerable vals) 16 | { 17 | return vals.Any(double.IsNaN); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/CircularProgressBar/RotateTransformCentreConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace MaterialDesignThemes.Wpf.Converters.CircularProgressBar 6 | { 7 | public class RotateTransformCentreConverter : IValueConverter 8 | { 9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 10 | { 11 | //value == actual width 12 | return (double) value/2; 13 | } 14 | 15 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | return Binding.DoNothing; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/CircularProgressBar/StartPointConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters.CircularProgressBar 7 | { 8 | public class StartPointConverter : IValueConverter 9 | { 10 | [Obsolete] 11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 12 | { 13 | if (value is double && ((double) value > 0.0)) 14 | { 15 | return new Point((double)value / 2, 0); 16 | } 17 | 18 | return new Point(); 19 | } 20 | 21 | [Obsolete] 22 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 23 | { 24 | return Binding.DoNothing; 25 | } 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/ClockItemIsCheckedConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace MaterialDesignThemes.Wpf.Converters 6 | { 7 | internal class ClockItemIsCheckedConverter : IValueConverter 8 | { 9 | private readonly Func _currentTimeGetter; 10 | private readonly ClockDisplayMode _displayMode; 11 | private readonly bool _is24Hours; 12 | 13 | public ClockItemIsCheckedConverter(Func currentTimeGetter, ClockDisplayMode displayMode, bool is24Hours) 14 | { 15 | _currentTimeGetter = currentTimeGetter ?? throw new ArgumentNullException(nameof(currentTimeGetter)); 16 | _displayMode = displayMode; 17 | _is24Hours = is24Hours; 18 | } 19 | 20 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 21 | { 22 | var dateTime = (DateTime)value; 23 | var i = (int)parameter; 24 | 25 | int converted = 0; 26 | if (_displayMode == ClockDisplayMode.Hours) 27 | converted = MassageHour(dateTime.Hour, _is24Hours); 28 | else if (_displayMode == ClockDisplayMode.Minutes) 29 | converted = MassageMinuteSecond(dateTime.Minute); 30 | else 31 | converted = MassageMinuteSecond(dateTime.Second); 32 | return converted == i; 33 | } 34 | 35 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 36 | { 37 | if ((bool)value != true) return Binding.DoNothing; 38 | 39 | var currentTime = _currentTimeGetter(); 40 | 41 | return new DateTime( 42 | currentTime.Year, currentTime.Month, currentTime.Day, 43 | (_displayMode == ClockDisplayMode.Hours) ? ReverseMassageHour((int)parameter, currentTime, _is24Hours) : currentTime.Hour, 44 | (_displayMode == ClockDisplayMode.Minutes) ? ReverseMassageMinuteSecond((int)parameter) : currentTime.Minute, 45 | (_displayMode == ClockDisplayMode.Seconds) ? ReverseMassageMinuteSecond((int)parameter) : currentTime.Second); 46 | } 47 | 48 | private static int MassageHour(int val, bool is24Hours) 49 | { 50 | if (is24Hours) 51 | { 52 | return val == 0 ? 24 : val; 53 | } 54 | 55 | if (val == 0) return 12; 56 | if (val > 12) return val - 12; 57 | return val; 58 | } 59 | 60 | private static int MassageMinuteSecond(int val) 61 | { 62 | return val == 0 ? 60 : val; 63 | } 64 | 65 | private static int ReverseMassageHour(int val, DateTime currentTime, bool is24Hours) 66 | { 67 | if (is24Hours) 68 | { 69 | return val == 24 ? 0 : val; 70 | } 71 | 72 | return currentTime.Hour < 12 73 | ? (val == 12 ? 0 : val) 74 | : (val == 12 ? 12 : val + 12); 75 | } 76 | 77 | private static int ReverseMassageMinuteSecond(int val) 78 | { 79 | return val == 60 ? 0 : val; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/ClockLineConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | using System.Windows.Markup; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class ClockLineConverter : MarkupExtension, IValueConverter 9 | { 10 | public ClockDisplayMode DisplayMode { get; set; } 11 | 12 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 13 | { 14 | var time = (DateTime) value; 15 | 16 | return DisplayMode == ClockDisplayMode.Hours 17 | ? ((time.Hour > 13) ? time.Hour - 12 : time.Hour)*(360/12) 18 | : DisplayMode == ClockDisplayMode.Minutes 19 | ? (time.Minute == 0 ? 60 : time.Minute)*(360/60) 20 | : (time.Second == 0 ? 60 : time.Second)*(360/60); 21 | } 22 | 23 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 24 | { 25 | return Binding.DoNothing; 26 | } 27 | 28 | public override object ProvideValue(IServiceProvider serviceProvider) 29 | { 30 | return this; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/DrawerOffsetConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Data; 6 | 7 | namespace MaterialDesignThemes.Wpf.Converters 8 | { 9 | public class DrawerOffsetConverter : IValueConverter 10 | { 11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 12 | { 13 | var d = value as double? ?? 0; 14 | if (double.IsInfinity(d) || double.IsNaN(d)) d = 0; 15 | 16 | var dock = (parameter is Dock) ? (Dock)parameter : Dock.Left; 17 | switch (dock) 18 | { 19 | case Dock.Top: 20 | return new Thickness(0, 0 - d, 0, 0); 21 | case Dock.Bottom: 22 | return new Thickness(0, 0, 0, 0 - d); 23 | case Dock.Right: 24 | return new Thickness(0, 0, 0 - d, 0); 25 | case Dock.Left: 26 | default: 27 | return new Thickness(0 - d, 0, 0, 0); 28 | } 29 | } 30 | 31 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 32 | { 33 | throw new NotImplementedException(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/EqualityToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class EqualityToVisibilityConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | if (value != null && value.Equals(parameter)) return Visibility.Visible; 13 | 14 | return Visibility.Collapsed; 15 | } 16 | 17 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/HintProxyFabricConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Controls; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | /// 9 | /// Converter for control. Can be extended by method. 10 | /// 11 | public class HintProxyFabricConverter : IValueConverter 12 | { 13 | private static readonly Lazy _instance = new Lazy(); 14 | 15 | public static HintProxyFabricConverter Instance => _instance.Value; 16 | 17 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 18 | { 19 | return HintProxyFabric.Get(value as Control); 20 | } 21 | 22 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 23 | { 24 | return Binding.DoNothing; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/ListViewItemContainerStyleConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Data; 6 | 7 | namespace MaterialDesignThemes.Wpf.Converters 8 | { 9 | /// 10 | /// Helps coerce the correct item container style for a , according to whether the list is displaying in standard mode, or using a , such as a . 11 | /// 12 | public class ListViewGridViewConverter : IValueConverter 13 | { 14 | /// 15 | /// Item container style to use when is null. 16 | /// 17 | public object DefaultValue { get; set; } 18 | 19 | /// 20 | /// Item container style to use when is not null, typically when a is applied. 21 | /// 22 | public object ViewValue { get; set; } 23 | 24 | /// 25 | /// Returns the item container to use for a . 26 | /// 27 | /// Should be a or instance. 28 | /// 29 | /// 30 | /// 31 | /// 32 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 33 | { 34 | var listView = value as ListView; 35 | if (listView != null) 36 | { 37 | return listView.View != null ? ViewValue : DefaultValue; 38 | } 39 | 40 | return value is ViewBase ? ViewValue : DefaultValue; 41 | } 42 | 43 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 44 | { 45 | return Binding.DoNothing; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/MathConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace MaterialDesignThemes.Wpf.Converters 6 | { 7 | public enum MathOperation 8 | { 9 | Add, 10 | Subtract, 11 | Multiply, 12 | Divide 13 | } 14 | 15 | public sealed class MathConverter : IValueConverter 16 | { 17 | public MathOperation Operation { get; set; } 18 | 19 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 20 | { 21 | try 22 | { 23 | double value1 = System.Convert.ToDouble(value, CultureInfo.InvariantCulture); 24 | double value2 = System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture); 25 | switch (Operation) 26 | { 27 | case MathOperation.Add: 28 | return value1 + value2; 29 | case MathOperation.Divide: 30 | return value1 / value2; 31 | case MathOperation.Multiply: 32 | return value1 * value2; 33 | case MathOperation.Subtract: 34 | return value1 - value2; 35 | default: 36 | return Binding.DoNothing; 37 | } 38 | } 39 | catch (FormatException) 40 | { 41 | return Binding.DoNothing; 42 | } 43 | } 44 | 45 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 46 | { 47 | return Binding.DoNothing; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/MathMultipleConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace MaterialDesignThemes.Wpf.Converters 6 | { 7 | public sealed class MathMultipleConverter : IMultiValueConverter 8 | { 9 | public MathOperation Operation { get; set; } 10 | 11 | public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture) 12 | { 13 | if (value == null || value.Length < 2 || value[0] == null || value[1] == null) return Binding.DoNothing; 14 | 15 | if (!double.TryParse(value[0].ToString(), out double value1) || !double.TryParse(value[1].ToString(), out double value2)) 16 | return 0; 17 | 18 | switch (Operation) 19 | { 20 | default: 21 | // (case MathOperation.Add:) 22 | return value1 + value2; 23 | case MathOperation.Divide: 24 | return value1 / value2; 25 | case MathOperation.Multiply: 26 | return value1 * value2; 27 | case MathOperation.Subtract: 28 | return value1 - value2; 29 | } 30 | 31 | } 32 | 33 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 34 | { 35 | throw new NotImplementedException(); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/NotConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace MaterialDesignThemes.Wpf.Converters 6 | { 7 | public class NotConverter : IValueConverter 8 | { 9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 10 | { 11 | return !(value as bool?) ?? !bool.Parse(value.ToString()); 12 | } 13 | 14 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | return !(value as bool?) ?? !bool.Parse(value.ToString()); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/NotZeroConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace MaterialDesignThemes.Wpf.Converters 6 | { 7 | public class NotZeroConverter : IValueConverter 8 | { 9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 10 | { 11 | if (double.TryParse((value ?? "").ToString(), out double val)) 12 | { 13 | return Math.Abs(val) > 0.0; 14 | } 15 | return null; 16 | } 17 | 18 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 19 | { 20 | return Binding.DoNothing; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/NotZeroToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class NotZeroToVisibilityConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | double val; 13 | double.TryParse((value ?? "").ToString(), out val); 14 | 15 | return Math.Abs(val) > 0.0 ? Visibility.Visible : Visibility.Collapsed; 16 | } 17 | 18 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 19 | { 20 | return Binding.DoNothing; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/NullToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class NullableToVisibilityConverter : IValueConverter 9 | { 10 | public Visibility NullValue { get; set; } = Visibility.Collapsed; 11 | public Visibility NotNullValue { get; set; } = Visibility.Visible; 12 | 13 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 14 | { 15 | return value == null ? NullValue : NotNullValue; 16 | } 17 | 18 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 19 | { 20 | return Binding.DoNothing; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/NullableDateTimeToCurrentDateConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace MaterialDesignThemes.Wpf.Converters 6 | { 7 | public class NullableDateTimeToCurrentDateConverter : IValueConverter 8 | { 9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 10 | { 11 | if (value is DateTime) 12 | return value; 13 | return DateTime.Now.Date; 14 | } 15 | 16 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 17 | { 18 | return value; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/PointValueConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class PointValueConverter : IMultiValueConverter 9 | { 10 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | if (values?.Length == 2 && values[0] != null && values[1] != null) 13 | { 14 | double x, y; 15 | if (double.TryParse(values[0].ToString(), out x) && 16 | double.TryParse(values[1].ToString(), out y)) 17 | 18 | return new Point(x, y); 19 | } 20 | 21 | return new Point(); 22 | } 23 | 24 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 25 | { 26 | if (value is Point) 27 | { 28 | var point = (Point) value; 29 | return new object[] { point.X, point.Y }; 30 | } 31 | 32 | return new object[0]; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/RangeLengthConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class RangeLengthConverter : IMultiValueConverter 9 | { 10 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | if (values == null || values.Length != 4 || values.Any(v => v == null)) 13 | return Binding.DoNothing; 14 | 15 | if (!double.TryParse(values[0].ToString(), out double min) 16 | || !double.TryParse(values[1].ToString(), out double max) 17 | || !double.TryParse(values[2].ToString(), out double value) 18 | || !double.TryParse(values[3].ToString(), out double containerLength)) 19 | 20 | return Binding.DoNothing; 21 | 22 | var percent = (value - min) / (max - min); 23 | var length = percent * containerLength; 24 | 25 | return length > containerLength ? containerLength : length; 26 | } 27 | 28 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 29 | { 30 | throw new NotImplementedException(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/RangePositionConverterConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class RangePositionConverter : IMultiValueConverter 9 | { 10 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | if(values == null || values.Length != 3 || values.Any(v => v == null)) 13 | return Binding.DoNothing; 14 | 15 | if (!double.TryParse(values[0].ToString(), out double positionAsScaleFactor) 16 | || !double.TryParse(values[1].ToString(), out double lower) 17 | || !double.TryParse(values[2].ToString(), out double upper)) 18 | 19 | return Binding.DoNothing; 20 | 21 | var result = upper + (lower - upper)*positionAsScaleFactor; 22 | 23 | return result; 24 | } 25 | 26 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 27 | { 28 | throw new NotImplementedException(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/ShadowConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class ShadowConverter : IValueConverter 9 | { 10 | public static readonly ShadowConverter Instance = new ShadowConverter(); 11 | 12 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 13 | { 14 | if (!(value is ShadowDepth)) return null; 15 | 16 | return Clone(ShadowInfo.GetDropShadow((ShadowDepth) value)); 17 | } 18 | 19 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 20 | { 21 | throw new NotImplementedException(); 22 | } 23 | 24 | private static DropShadowEffect Clone(DropShadowEffect dropShadowEffect) 25 | { 26 | if (dropShadowEffect == null) return null; 27 | return new DropShadowEffect() 28 | { 29 | BlurRadius = dropShadowEffect.BlurRadius, 30 | Color = dropShadowEffect.Color, 31 | Direction = dropShadowEffect.Direction, 32 | Opacity = dropShadowEffect.Opacity, 33 | RenderingBias = dropShadowEffect.RenderingBias, 34 | ShadowDepth = dropShadowEffect.ShadowDepth 35 | }; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/ShadowEdgeConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | using System.Windows.Media; 6 | using System.Windows.Media.Effects; 7 | 8 | namespace MaterialDesignThemes.Wpf.Converters 9 | { 10 | public class ShadowEdgeConverter : IMultiValueConverter 11 | { 12 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 13 | { 14 | if (values?.Length != 4) 15 | { 16 | return Binding.DoNothing; 17 | } 18 | 19 | if (!(values[0] is double) || !(values[1] is double) || !(values[2] is ShadowDepth) || 20 | !(values[3] is ShadowEdges)) 21 | { 22 | return Binding.DoNothing; 23 | } 24 | 25 | double width = (double)values[0]; 26 | double height = (double)values[1]; 27 | if (double.IsNaN(width) || double.IsInfinity(width) || double.IsNaN(height) || double.IsInfinity(height)) 28 | { 29 | return Binding.DoNothing; 30 | } 31 | DropShadowEffect dropShadow = ShadowInfo.GetDropShadow((ShadowDepth)values[2]); 32 | if (dropShadow == null) 33 | { 34 | return Binding.DoNothing; 35 | } 36 | 37 | ShadowEdges edges = (ShadowEdges)values[3]; 38 | double blurRadius = dropShadow.BlurRadius; 39 | 40 | var rect = new Rect(0, 0, width, height); 41 | 42 | if (edges.HasFlag(ShadowEdges.Left)) 43 | { 44 | rect = new Rect(rect.X - blurRadius, rect.Y, rect.Width + blurRadius, rect.Height); 45 | } 46 | if (edges.HasFlag(ShadowEdges.Top)) 47 | { 48 | rect = new Rect(rect.X, rect.Y - blurRadius, rect.Width, rect.Height + blurRadius); 49 | } 50 | if (edges.HasFlag(ShadowEdges.Right)) 51 | { 52 | rect = new Rect(rect.X, rect.Y, rect.Width + blurRadius, rect.Height); 53 | } 54 | if (edges.HasFlag(ShadowEdges.Bottom)) 55 | { 56 | rect = new Rect(rect.X, rect.Y, rect.Width, rect.Height + blurRadius); 57 | } 58 | 59 | var size = new GeometryDrawing(new SolidColorBrush(Colors.White), new Pen(), new RectangleGeometry(rect)); 60 | return new DrawingBrush(size) 61 | { 62 | Stretch = Stretch.None, 63 | TileMode = TileMode.None, 64 | Viewport = rect, 65 | ViewportUnits = BrushMappingMode.Absolute, 66 | Viewbox = rect, 67 | ViewboxUnits = BrushMappingMode.Absolute 68 | }; 69 | } 70 | 71 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 72 | { 73 | throw new NotImplementedException(); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/ShadowInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | internal static class ShadowInfo 9 | { 10 | private static readonly IDictionary ShadowsDictionary; 11 | 12 | static ShadowInfo() 13 | { 14 | var resourceDictionary = new ResourceDictionary { Source = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml", UriKind.Absolute) }; 15 | 16 | ShadowsDictionary = new Dictionary 17 | { 18 | { ShadowDepth.Depth0, null }, 19 | { ShadowDepth.Depth1, (DropShadowEffect)resourceDictionary["MaterialDesignShadowDepth1"] }, 20 | { ShadowDepth.Depth2, (DropShadowEffect)resourceDictionary["MaterialDesignShadowDepth2"] }, 21 | { ShadowDepth.Depth3, (DropShadowEffect)resourceDictionary["MaterialDesignShadowDepth3"] }, 22 | { ShadowDepth.Depth4, (DropShadowEffect)resourceDictionary["MaterialDesignShadowDepth4"] }, 23 | { ShadowDepth.Depth5, (DropShadowEffect)resourceDictionary["MaterialDesignShadowDepth5"] }, 24 | }; 25 | } 26 | 27 | public static DropShadowEffect GetDropShadow(ShadowDepth depth) 28 | { 29 | return ShadowsDictionary[depth]; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/SizeToRectConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class CardClipConverter : IMultiValueConverter 9 | { 10 | /// 11 | /// 1 - Content presenter render size, 12 | /// 2 - Clipping border padding (main control padding) 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 20 | { 21 | if (values.Length != 2 || !(values[0] is Size) || !(values[1] is Thickness)) 22 | return Binding.DoNothing; 23 | 24 | var size = (Size)values[0]; 25 | var farPoint = new Point( 26 | Math.Max(0, size.Width), 27 | Math.Max(0, size.Height)); 28 | var padding = (Thickness)values[1]; 29 | farPoint.Offset(padding.Left + padding.Right, padding.Top + padding.Bottom); 30 | 31 | return new Rect( 32 | new Point(), 33 | new Point(farPoint.X, farPoint.Y)); 34 | } 35 | 36 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 37 | { 38 | return null; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/SnackbarMessageTypeConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Globalization; 4 | 5 | namespace MaterialDesignThemes.Wpf.Converters 6 | { 7 | public class SnackbarMessageTypeConverter : TypeConverter 8 | { 9 | public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) 10 | { 11 | return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); 12 | } 13 | 14 | public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) 15 | { 16 | var s = value as string; 17 | if (s != null) 18 | { 19 | return new SnackbarMessage 20 | { 21 | Content = s 22 | }; 23 | } 24 | 25 | return base.ConvertFrom(context, culture, value); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/TextFieldHintVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace MaterialDesignThemes.Wpf.Converters 7 | { 8 | public class TextFieldHintVisibilityConverter : IValueConverter 9 | { 10 | public Visibility IsEmptyValue { get; set; } = Visibility.Visible; 11 | public Visibility IsNotEmptyValue { get; set; } = Visibility.Hidden; 12 | 13 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 14 | { 15 | return string.IsNullOrEmpty((value ?? "").ToString()) ? IsEmptyValue : IsNotEmptyValue; 16 | } 17 | 18 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 19 | { 20 | return Binding.DoNothing; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Converters/TimeToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | using System.Windows.Markup; 6 | 7 | namespace MaterialDesignThemes.Wpf.Converters 8 | { 9 | public class TimeToVisibilityConverter: MarkupExtension, IValueConverter 10 | { 11 | public override object ProvideValue(IServiceProvider serviceProvider) 12 | { 13 | return this; 14 | } 15 | 16 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 17 | { 18 | var time = (DateTime)value; 19 | 20 | var isPm = ((time.Hour >= 13) || (time.Hour == 0)); 21 | 22 | return isPm ? Visibility.Visible : Visibility.Collapsed; 23 | } 24 | 25 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 26 | { 27 | return Binding.DoNothing; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/CustomPopupPlacementCallbackHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls.Primitives; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public static class CustomPopupPlacementCallbackHelper 7 | { 8 | public static readonly CustomPopupPlacementCallback LargePopupCallback; 9 | 10 | static CustomPopupPlacementCallbackHelper() 11 | { 12 | LargePopupCallback = 13 | (size, targetSize, offset) => new[] {new CustomPopupPlacement(new Point(), PopupPrimaryAxis.Horizontal)}; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/DateTimeEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | 5 | namespace MaterialDesignThemes.Wpf 6 | { 7 | internal static class DateTimeEx 8 | { 9 | internal static DateTimeFormatInfo GetDateFormat(this CultureInfo culture) 10 | { 11 | if (culture == null) throw new ArgumentNullException(nameof(culture)); 12 | 13 | if (culture.Calendar is GregorianCalendar || culture.Calendar is PersianCalendar) 14 | { 15 | return culture.DateTimeFormat; 16 | } 17 | 18 | GregorianCalendar foundCal = null; 19 | DateTimeFormatInfo dtfi = null; 20 | foreach (var cal in culture.OptionalCalendars.OfType()) 21 | { 22 | // Return the first Gregorian calendar with CalendarType == Localized 23 | // Otherwise return the first Gregorian calendar 24 | if (foundCal == null) 25 | { 26 | foundCal = cal; 27 | } 28 | 29 | if (cal.CalendarType != GregorianCalendarTypes.Localized) continue; 30 | 31 | foundCal = cal; 32 | break; 33 | } 34 | 35 | 36 | if (foundCal == null) 37 | { 38 | // if there are no GregorianCalendars in the OptionalCalendars list, use the invariant dtfi 39 | dtfi = ((CultureInfo)CultureInfo.InvariantCulture.Clone()).DateTimeFormat; 40 | dtfi.Calendar = new GregorianCalendar(); 41 | } 42 | else 43 | { 44 | dtfi = ((CultureInfo)culture.Clone()).DateTimeFormat; 45 | dtfi.Calendar = foundCal; 46 | } 47 | 48 | return dtfi; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/DialogClosingEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public class DialogClosingEventArgs : RoutedEventArgs 7 | { 8 | public DialogClosingEventArgs(DialogSession session, object parameter) 9 | { 10 | if (session == null) throw new ArgumentNullException(nameof(session)); 11 | Session = session; 12 | 13 | Parameter = parameter; 14 | } 15 | 16 | public DialogClosingEventArgs(DialogSession session, object parameter, RoutedEvent routedEvent) : base(routedEvent) 17 | { 18 | if (session == null) throw new ArgumentNullException(nameof(session)); 19 | Session = session; 20 | 21 | Parameter = parameter; 22 | } 23 | 24 | public DialogClosingEventArgs(DialogSession session, object parameter, RoutedEvent routedEvent, object source) : base(routedEvent, source) 25 | { 26 | if (session == null) throw new ArgumentNullException(nameof(session)); 27 | Session = session; 28 | 29 | Parameter = parameter; 30 | } 31 | 32 | /// 33 | /// Cancel the close. 34 | /// 35 | public void Cancel() 36 | { 37 | IsCancelled = true; 38 | } 39 | 40 | /// 41 | /// Indicates if the close has already been cancelled. 42 | /// 43 | public bool IsCancelled { get; private set; } 44 | 45 | /// 46 | /// Gets the paramter originally provided to / 47 | /// 48 | public object Parameter { get; } 49 | 50 | /// 51 | /// Allows interation with the current dialog session. 52 | /// 53 | public DialogSession Session { get; } 54 | 55 | /// 56 | /// Gets the which is currently displayed, so this could be a view model or a UI element. 57 | /// 58 | [Obsolete("Prefer Session.Content")] 59 | public object Content => Session.Content; 60 | } 61 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/DialogClosingEventHandler.cs: -------------------------------------------------------------------------------- 1 | namespace MaterialDesignThemes.Wpf 2 | { 3 | public delegate void DialogClosingEventHandler(object sender, DialogClosingEventArgs eventArgs); 4 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/DialogOpenedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public class DialogOpenedEventArgs : RoutedEventArgs 7 | { 8 | public DialogOpenedEventArgs(DialogSession session, RoutedEvent routedEvent) 9 | { 10 | if (session == null) throw new ArgumentNullException(nameof(session)); 11 | 12 | Session = session; 13 | RoutedEvent = routedEvent; 14 | } 15 | 16 | /// 17 | /// Allows interation with the current dialog session. 18 | /// 19 | public DialogSession Session { get; } 20 | } 21 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/DialogOpenedEventHandler.cs: -------------------------------------------------------------------------------- 1 | namespace MaterialDesignThemes.Wpf 2 | { 3 | public delegate void DialogOpenedEventHandler(object sender, DialogOpenedEventArgs eventArgs); 4 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/DialogSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Threading; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | /// 7 | /// Allows an open dialog to be managed. Use is only permitted during a single display operation. 8 | /// 9 | public class DialogSession 10 | { 11 | private readonly DialogHost _owner; 12 | 13 | internal DialogSession(DialogHost owner) 14 | { 15 | _owner = owner ?? throw new ArgumentNullException(nameof(owner)); 16 | } 17 | 18 | /// 19 | /// Indicates if the dialog session has ended. Once ended no further method calls will be permitted. 20 | /// 21 | /// 22 | /// Client code cannot set this directly, this is internally managed. To end the dialog session use . 23 | /// 24 | public bool IsEnded { get; internal set; } 25 | 26 | /// 27 | /// Gets the which is currently displayed, so this could be a view model or a UI element. 28 | /// 29 | public object Content => _owner.DialogContent; 30 | 31 | /// 32 | /// Update the current content in the dialog. 33 | /// 34 | /// 35 | public void UpdateContent(object content) 36 | { 37 | _owner.AssertTargetableContent(); 38 | _owner.DialogContent = content ?? throw new ArgumentNullException(nameof(content)); 39 | _owner.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => 40 | { 41 | _owner.FocusPopup(); 42 | })); 43 | } 44 | 45 | /// 46 | /// Closes the dialog. 47 | /// 48 | /// Thrown if the dialog session has ended, or a close operation is currently in progress. 49 | public void Close() 50 | { 51 | if (IsEnded) throw new InvalidOperationException("Dialog session has ended."); 52 | 53 | _owner.Close(null); 54 | } 55 | 56 | /// 57 | /// Closes the dialog. 58 | /// 59 | /// Result parameter which will be returned in or from method. 60 | /// Thrown if the dialog session has ended, or a close operation is currently in progress. 61 | public void Close(object parameter) 62 | { 63 | if (IsEnded) throw new InvalidOperationException("Dialog session has ended."); 64 | 65 | _owner.Close(parameter); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/DpiHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | 5 | namespace MaterialDesignThemes.Wpf 6 | { 7 | internal static class DpiHelper 8 | { 9 | private static readonly int DpiX; 10 | private static readonly int DpiY; 11 | 12 | private const double StandardDpiX = 96.0; 13 | private const double StandardDpiY = 96.0; 14 | 15 | static DpiHelper() 16 | { 17 | var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static); 18 | var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static); 19 | 20 | DpiX = (int)dpiXProperty.GetValue(null, null); 21 | DpiY = (int)dpiYProperty.GetValue(null, null); 22 | } 23 | 24 | public static double TransformToDeviceY(Visual visual, double y) 25 | { 26 | var source = PresentationSource.FromVisual(visual); 27 | if (source?.CompositionTarget != null) return y * source.CompositionTarget.TransformToDevice.M22; 28 | 29 | return TransformToDeviceY(y); 30 | } 31 | 32 | public static double TransformToDeviceX(Visual visual, double x) 33 | { 34 | var source = PresentationSource.FromVisual(visual); 35 | if (source?.CompositionTarget != null) return x * source.CompositionTarget.TransformToDevice.M11; 36 | 37 | return TransformToDeviceX(x); 38 | } 39 | 40 | public static double TransformToDeviceY(double y) 41 | { 42 | return y * DpiY / StandardDpiY; 43 | } 44 | 45 | public static double TransformToDeviceX(double x) 46 | { 47 | return x * DpiX / StandardDpiX; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ExpanderAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | public static class ExpanderAssist 6 | { 7 | public static readonly DependencyProperty LeftHeaderPaddingProperty = 8 | DependencyProperty.RegisterAttached( 9 | "LeftHeaderPadding", typeof(Thickness), typeof(ExpanderAssist), 10 | new FrameworkPropertyMetadata(new Thickness(0, 0, 0, 0), FrameworkPropertyMetadataOptions.Inherits)); 11 | 12 | public static void SetLeftHeaderPadding(DependencyObject element, Thickness value) 13 | { 14 | element.SetValue(LeftHeaderPaddingProperty, value); 15 | } 16 | 17 | public static Thickness GetLeftHeaderPadding(DependencyObject element) 18 | { 19 | return (Thickness)element.GetValue(LeftHeaderPaddingProperty); 20 | } 21 | 22 | public static readonly DependencyProperty RightHeaderPaddingProperty = 23 | DependencyProperty.RegisterAttached( 24 | "RightHeaderPadding", typeof(Thickness), typeof(ExpanderAssist), 25 | new FrameworkPropertyMetadata(new Thickness(0, 0, 0, 0), FrameworkPropertyMetadataOptions.Inherits)); 26 | 27 | public static void SetRightHeaderPadding(DependencyObject element, Thickness value) 28 | { 29 | element.SetValue(RightHeaderPaddingProperty, value); 30 | } 31 | 32 | public static Thickness GetRightHeaderPadding(DependencyObject element) 33 | { 34 | return (Thickness)element.GetValue(RightHeaderPaddingProperty); 35 | } 36 | 37 | public static readonly DependencyProperty UpHeaderPaddingProperty = 38 | DependencyProperty.RegisterAttached( 39 | "UpHeaderPadding", typeof(Thickness), typeof(ExpanderAssist), 40 | new FrameworkPropertyMetadata(new Thickness(0, 0, 0, 0), FrameworkPropertyMetadataOptions.Inherits)); 41 | 42 | public static void SetUpHeaderPadding(DependencyObject element, Thickness value) 43 | { 44 | element.SetValue(UpHeaderPaddingProperty, value); 45 | } 46 | 47 | public static Thickness GetUpHeaderPadding(DependencyObject element) 48 | { 49 | return (Thickness)element.GetValue(UpHeaderPaddingProperty); 50 | } 51 | 52 | public static readonly DependencyProperty DownHeaderPaddingProperty = 53 | DependencyProperty.RegisterAttached( 54 | "DownHeaderPadding", typeof(Thickness), typeof(ExpanderAssist), 55 | new FrameworkPropertyMetadata(new Thickness(0, 0, 0, 0), FrameworkPropertyMetadataOptions.Inherits)); 56 | 57 | public static void SetDownHeaderPadding(DependencyObject element, Thickness value) 58 | { 59 | element.SetValue(DownHeaderPaddingProperty, value); 60 | } 61 | 62 | public static Thickness GetDownHeaderPadding(DependencyObject element) 63 | { 64 | return (Thickness)element.GetValue(DownHeaderPaddingProperty); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows; 5 | using System.Windows.Media; 6 | 7 | namespace MaterialDesignThemes.Wpf 8 | { 9 | internal static class Extensions 10 | { 11 | public static IEnumerable VisualDepthFirstTraversal(this DependencyObject node) 12 | { 13 | if (node == null) throw new ArgumentNullException(nameof(node)); 14 | 15 | yield return node; 16 | 17 | for (var i = 0; i < VisualTreeHelper.GetChildrenCount(node); i++) 18 | { 19 | var child = VisualTreeHelper.GetChild(node, i); 20 | foreach (var descendant in child.VisualDepthFirstTraversal()) 21 | { 22 | yield return descendant; 23 | } 24 | } 25 | } 26 | 27 | public static IEnumerable VisualBreadthFirstTraversal(this DependencyObject node) 28 | { 29 | if (node == null) throw new ArgumentNullException(nameof(node)); 30 | 31 | for (var i = 0; i < VisualTreeHelper.GetChildrenCount(node); i++) 32 | { 33 | var child = VisualTreeHelper.GetChild(node, i); 34 | yield return child; 35 | } 36 | 37 | for (var i = 0; i < VisualTreeHelper.GetChildrenCount(node); i++) 38 | { 39 | var child = VisualTreeHelper.GetChild(node, i); 40 | 41 | foreach (var descendant in child.VisualDepthFirstTraversal()) 42 | { 43 | yield return descendant; 44 | } 45 | } 46 | } 47 | 48 | public static bool IsAncestorOf(this DependencyObject parent, DependencyObject node) 49 | { 50 | return node != null && parent.VisualDepthFirstTraversal().Contains(node); 51 | } 52 | 53 | /// 54 | /// Returns full visual ancestry, starting at the leaf. 55 | /// 56 | /// 57 | /// 58 | public static IEnumerable GetVisualAncestry(this DependencyObject leaf) 59 | { 60 | while (leaf != null) 61 | { 62 | yield return leaf; 63 | leaf = VisualTreeHelper.GetParent(leaf); 64 | } 65 | } 66 | 67 | public static IEnumerable GetLogicalAncestry(this DependencyObject leaf) 68 | { 69 | while (leaf != null) 70 | { 71 | yield return leaf; 72 | leaf = LogicalTreeHelper.GetParent(leaf); 73 | } 74 | } 75 | 76 | public static bool IsDescendantOf(this DependencyObject leaf, DependencyObject ancestor) 77 | { 78 | DependencyObject parent = null; 79 | foreach (var node in leaf.GetVisualAncestry()) 80 | { 81 | if (Equals(node, ancestor)) 82 | return true; 83 | 84 | parent = node; 85 | } 86 | 87 | return parent.GetLogicalAncestry().Contains(ancestor); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/HintProxyFabric.ComboBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Controls.Primitives; 5 | 6 | namespace MaterialDesignThemes.Wpf 7 | { 8 | public static partial class HintProxyFabric 9 | { 10 | private sealed class ComboBoxHintProxy : IHintProxy 11 | { 12 | private readonly ComboBox _comboBox; 13 | private readonly TextChangedEventHandler _comboBoxTextChangedEventHandler; 14 | 15 | public ComboBoxHintProxy(ComboBox comboBox) 16 | { 17 | if (comboBox == null) throw new ArgumentNullException(nameof(comboBox)); 18 | 19 | _comboBox = comboBox; 20 | _comboBoxTextChangedEventHandler = ComboBoxTextChanged; 21 | _comboBox.AddHandler(TextBoxBase.TextChangedEvent, _comboBoxTextChangedEventHandler); 22 | _comboBox.SelectionChanged += ComboBoxSelectionChanged; 23 | _comboBox.Loaded += ComboBoxLoaded; 24 | _comboBox.IsVisibleChanged += ComboBoxIsVisibleChanged; 25 | _comboBox.IsKeyboardFocusWithinChanged += ComboBoxIsKeyboardFocusWithinChanged; 26 | } 27 | 28 | public object Content 29 | { 30 | get 31 | { 32 | if (_comboBox.IsEditable) 33 | { 34 | return _comboBox.Text; 35 | } 36 | 37 | var comboBoxItem = _comboBox.SelectedItem as ComboBoxItem; 38 | return comboBoxItem != null 39 | ? comboBoxItem.Content 40 | : _comboBox.SelectedItem; 41 | } 42 | } 43 | 44 | public bool IsLoaded => _comboBox.IsLoaded; 45 | 46 | public bool IsVisible => _comboBox.IsVisible; 47 | 48 | public bool IsEmpty() => string.IsNullOrEmpty(_comboBox.Text); 49 | 50 | public bool IsFocused() => _comboBox.IsEditable && _comboBox.IsKeyboardFocusWithin; 51 | 52 | public event EventHandler ContentChanged; 53 | 54 | public event EventHandler IsVisibleChanged; 55 | 56 | public event EventHandler Loaded; 57 | public event EventHandler FocusedChanged; 58 | 59 | private void ComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e) 60 | { 61 | _comboBox.Dispatcher.InvokeAsync(() => ContentChanged?.Invoke(sender, EventArgs.Empty)); 62 | } 63 | 64 | private void ComboBoxIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) 65 | { 66 | IsVisibleChanged?.Invoke(sender, EventArgs.Empty); 67 | } 68 | 69 | private void ComboBoxLoaded(object sender, RoutedEventArgs e) 70 | { 71 | Loaded?.Invoke(sender, EventArgs.Empty); 72 | } 73 | 74 | private void ComboBoxTextChanged(object sender, TextChangedEventArgs e) 75 | { 76 | ContentChanged?.Invoke(sender, EventArgs.Empty); 77 | } 78 | 79 | private void ComboBoxIsKeyboardFocusWithinChanged(object sender, DependencyPropertyChangedEventArgs e) 80 | { 81 | FocusedChanged?.Invoke(sender, EventArgs.Empty); 82 | } 83 | 84 | public void Dispose() 85 | { 86 | _comboBox.RemoveHandler(TextBoxBase.TextChangedEvent, _comboBoxTextChangedEventHandler); 87 | _comboBox.Loaded -= ComboBoxLoaded; 88 | _comboBox.IsVisibleChanged -= ComboBoxIsVisibleChanged; 89 | _comboBox.SelectionChanged -= ComboBoxSelectionChanged; 90 | _comboBox.IsKeyboardFocusWithinChanged -= ComboBoxIsKeyboardFocusWithinChanged; 91 | } 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/HintProxyFabric.PasswordBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Controls; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public static partial class HintProxyFabric 7 | { 8 | private sealed class PasswordBoxHintProxy : IHintProxy 9 | { 10 | private readonly PasswordBox _passwordBox; 11 | 12 | public bool IsEmpty() => string.IsNullOrEmpty(_passwordBox.Password); 13 | 14 | public object Content => _passwordBox.Password; 15 | 16 | public bool IsLoaded => _passwordBox.IsLoaded; 17 | 18 | public bool IsVisible => _passwordBox.IsVisible; 19 | 20 | public bool IsFocused() => _passwordBox.IsKeyboardFocused; 21 | 22 | public event EventHandler ContentChanged; 23 | public event EventHandler IsVisibleChanged; 24 | public event EventHandler Loaded; 25 | public event EventHandler FocusedChanged; 26 | 27 | public PasswordBoxHintProxy(PasswordBox passwordBox) 28 | { 29 | if (passwordBox == null) throw new ArgumentNullException(nameof(passwordBox)); 30 | 31 | _passwordBox = passwordBox; 32 | _passwordBox.PasswordChanged += PasswordBoxPasswordChanged; 33 | _passwordBox.Loaded += PasswordBoxLoaded; 34 | _passwordBox.IsVisibleChanged += PasswordBoxIsVisibleChanged; 35 | _passwordBox.IsKeyboardFocusedChanged += PasswordBoxIsKeyboardFocusedChanged; 36 | } 37 | 38 | private void PasswordBoxIsKeyboardFocusedChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e) 39 | { 40 | FocusedChanged?.Invoke(this, EventArgs.Empty); 41 | } 42 | 43 | private void PasswordBoxIsVisibleChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e) 44 | { 45 | IsVisibleChanged?.Invoke(this, EventArgs.Empty); 46 | } 47 | 48 | private void PasswordBoxLoaded(object sender, System.Windows.RoutedEventArgs e) 49 | { 50 | Loaded?.Invoke(this, EventArgs.Empty); 51 | } 52 | 53 | private void PasswordBoxPasswordChanged(object sender, System.Windows.RoutedEventArgs e) 54 | { 55 | ContentChanged?.Invoke(this, EventArgs.Empty); 56 | } 57 | 58 | public void Dispose() 59 | { 60 | _passwordBox.PasswordChanged -= PasswordBoxPasswordChanged; 61 | _passwordBox.Loaded -= PasswordBoxLoaded; 62 | _passwordBox.IsVisibleChanged -= PasswordBoxIsVisibleChanged; 63 | _passwordBox.IsKeyboardFocusedChanged -= PasswordBoxIsKeyboardFocusedChanged; 64 | } 65 | 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/HintProxyFabric.TextBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | 5 | namespace MaterialDesignThemes.Wpf 6 | { 7 | public static partial class HintProxyFabric 8 | { 9 | private sealed class TextBoxHintProxy : IHintProxy 10 | { 11 | private readonly TextBox _textBox; 12 | 13 | public object Content => _textBox.Text; 14 | 15 | public bool IsLoaded => _textBox.IsLoaded; 16 | 17 | public bool IsVisible => _textBox.IsVisible; 18 | 19 | public bool IsEmpty() => string.IsNullOrEmpty(_textBox.Text); 20 | 21 | public bool IsFocused() => _textBox.IsKeyboardFocused; 22 | 23 | public event EventHandler ContentChanged; 24 | public event EventHandler IsVisibleChanged; 25 | public event EventHandler Loaded; 26 | public event EventHandler FocusedChanged; 27 | 28 | public TextBoxHintProxy(TextBox textBox) 29 | { 30 | if (textBox == null) throw new ArgumentNullException(nameof(textBox)); 31 | 32 | _textBox = textBox; 33 | _textBox.TextChanged += TextBoxTextChanged; 34 | _textBox.Loaded += TextBoxLoaded; 35 | _textBox.IsVisibleChanged += TextBoxIsVisibleChanged; 36 | _textBox.IsKeyboardFocusedChanged += TextBoxIsKeyboardFocusedChanged; 37 | } 38 | 39 | private void TextBoxIsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e) 40 | { 41 | FocusedChanged?.Invoke(sender, EventArgs.Empty); 42 | } 43 | 44 | private void TextBoxIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) 45 | { 46 | IsVisibleChanged?.Invoke(sender, EventArgs.Empty); 47 | } 48 | 49 | private void TextBoxLoaded(object sender, RoutedEventArgs e) 50 | { 51 | Loaded?.Invoke(sender, EventArgs.Empty); 52 | } 53 | 54 | private void TextBoxTextChanged(object sender, TextChangedEventArgs e) 55 | { 56 | ContentChanged?.Invoke(sender, EventArgs.Empty); 57 | } 58 | 59 | public void Dispose() 60 | { 61 | _textBox.TextChanged -= TextBoxTextChanged; 62 | _textBox.Loaded -= TextBoxLoaded; 63 | _textBox.IsVisibleChanged -= TextBoxIsVisibleChanged; 64 | _textBox.IsKeyboardFocusedChanged -= TextBoxIsKeyboardFocusedChanged; 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/HintProxyFabric.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Controls; 5 | 6 | namespace MaterialDesignThemes.Wpf 7 | { 8 | public static partial class HintProxyFabric 9 | { 10 | private sealed class HintProxyBuilder 11 | { 12 | private readonly Func _canBuild; 13 | private readonly Func _build; 14 | 15 | public HintProxyBuilder(Func canBuild, Func build) 16 | { 17 | if (canBuild == null) throw new ArgumentNullException(nameof(canBuild)); 18 | if (build == null) throw new ArgumentNullException(nameof(build)); 19 | 20 | _canBuild = canBuild; 21 | _build = build; 22 | } 23 | 24 | public bool CanBuild(Control control) => _canBuild(control); 25 | public IHintProxy Build(Control control) => _build(control); 26 | } 27 | 28 | private static readonly List Builders = new List(); 29 | 30 | static HintProxyFabric() 31 | { 32 | Builders.Add(new HintProxyBuilder(c => c is ComboBox, c => new ComboBoxHintProxy((ComboBox) c))); 33 | Builders.Add(new HintProxyBuilder(c => c is TextBox, c => new TextBoxHintProxy((TextBox)c))); 34 | Builders.Add(new HintProxyBuilder(c => c is PasswordBox, c => new PasswordBoxHintProxy((PasswordBox)c))); 35 | } 36 | 37 | public static void RegisterBuilder(Func canBuild, Func build) 38 | { 39 | Builders.Add(new HintProxyBuilder(canBuild, build)); 40 | } 41 | 42 | public static IHintProxy Get(Control control) 43 | { 44 | var builder = Builders.FirstOrDefault(v => v.CanBuild(control)); 45 | 46 | if (builder == null) throw new NotImplementedException(); 47 | 48 | return builder.Build(control); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/IHintProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Controls; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | /// 7 | /// This interface is the adapter from UiControl (like , and others) to 8 | /// 9 | /// You should implement this interface in order to use SmartHint for your own control. 10 | /// 11 | public interface IHintProxy : IDisposable 12 | { 13 | /// 14 | /// Checks to see if the targetted control can be deemed as logically 15 | /// empty, even if not null, affecting the current hint display. 16 | /// 17 | /// 18 | bool IsEmpty(); 19 | 20 | /// 21 | /// Targeted control has keyboard focus 22 | /// 23 | /// 24 | bool IsFocused(); 25 | 26 | [Obsolete] 27 | object Content { get; } 28 | 29 | bool IsLoaded { get; } 30 | 31 | bool IsVisible { get; } 32 | 33 | event EventHandler ContentChanged; 34 | 35 | event EventHandler IsVisibleChanged; 36 | 37 | event EventHandler Loaded; 38 | 39 | event EventHandler FocusedChanged; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ISnackbarMessageQueue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | public interface ISnackbarMessageQueue 6 | { 7 | /// 8 | /// Queues a notificaton message for display in a snackbar. 9 | /// 10 | /// Message. 11 | void Enqueue(object content); 12 | 13 | /// 14 | /// Queues a notificaton message for display in a snackbar. 15 | /// 16 | /// Message. 17 | /// Content for the action button. 18 | /// Call back to be executed if user clicks the action button. 19 | void Enqueue(object content, object actionContent, Action actionHandler); 20 | 21 | /// 22 | /// Queues a notificaton message for display in a snackbar. 23 | /// 24 | /// Message. 25 | /// Content for the action button. 26 | /// Call back to be executed if user clicks the action button. 27 | /// Argument to pass to . 28 | void Enqueue(object content, object actionContent, Action actionHandler, TArgument actionArgument); 29 | 30 | /// 31 | /// Queues a notificaton message for display in a snackbar. 32 | /// 33 | /// Message. 34 | /// Subsequent, duplicate messages queued within a short time span will 35 | /// be discarded. To override this behaviour and ensure the message always gets displayed set to true. 36 | void Enqueue(object content, bool neverConsiderToBeDuplicate); 37 | 38 | /// 39 | /// Queues a notificaton message for display in a snackbar. 40 | /// 41 | /// Message. 42 | /// Content for the action button. 43 | /// Call back to be executed if user clicks the action button. 44 | /// The message will promoted to the front of the queue. 45 | void Enqueue(object content, object actionContent, Action actionHandler, bool promote); 46 | 47 | /// 48 | /// Queues a notificaton message for display in a snackbar. 49 | /// 50 | /// Message. 51 | /// Content for the action button. 52 | /// Call back to be executed if user clicks the action button. 53 | /// Argument to pass to . 54 | /// The message will be promoted to the front of the queue and never considered to be a duplicate. 55 | void Enqueue(object content, object actionContent, Action actionHandler, TArgument actionArgument, bool promote); 56 | 57 | /// 58 | /// Queues a notificaton message for display in a snackbar. 59 | /// 60 | /// Message. 61 | /// Content for the action button. 62 | /// Call back to be executed if user clicks the action button. 63 | /// Argument to pass to . 64 | /// The message will be promoted to the front of the queue. 65 | /// The message will never be considered a duplicate. 66 | void Enqueue(object content, object actionContent, Action actionHandler, 67 | TArgument actionArgument, bool promote, bool neverConsiderToBeDuplicate); 68 | 69 | /// 70 | /// Queues a notificaton message for display in a snackbar. 71 | /// 72 | /// Message. 73 | /// Content for the action button. 74 | /// Call back to be executed if user clicks the action button. 75 | /// Argument to pass to . 76 | /// The message will promoted to the front of the queue. 77 | /// The message will never be considered a duplicate. 78 | void Enqueue(object content, object actionContent, Action actionHandler, object actionArgument, 79 | bool promote, bool neverConsiderToBeDuplicate); 80 | } 81 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Icon.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | /// 7 | /// Displays an icon image/path, according to the specified name. 8 | /// 9 | /// 10 | /// All icons sourced from Material Design Icons Font - - in accordance of 11 | /// . 12 | /// 13 | public class Icon : Control 14 | { 15 | public static readonly DependencyProperty TypeProperty = DependencyProperty.Register( 16 | nameof(Type), typeof (IconType), typeof (Icon), new PropertyMetadata(default(IconType))); 17 | 18 | /// 19 | /// Gets or sets the name of icon being displayed. 20 | /// 21 | public IconType Type 22 | { 23 | get { return (IconType) GetValue(TypeProperty); } 24 | set { SetValue(TypeProperty, value); } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/IconType.cs: -------------------------------------------------------------------------------- 1 | namespace MaterialDesignThemes.Wpf 2 | { 3 | /// 4 | /// List of available icons for use with . 5 | /// 6 | /// 7 | /// All icons sourced from Material Design Icons Font - - in accordance of 8 | /// . 9 | /// 10 | public enum IconType 11 | { 12 | AutoGeneratedDoNotAmend 13 | } 14 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ListBoxAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Input; 5 | using System.Windows.Media; 6 | 7 | namespace MaterialDesignThemes.Wpf 8 | { 9 | public static class ListBoxAssist 10 | { 11 | static ListBoxAssist() 12 | { 13 | EventManager.RegisterClassHandler(typeof (ListBox), UIElement.PreviewMouseLeftButtonDownEvent, 14 | new MouseButtonEventHandler(ListBoxMouseButtonEvent)); 15 | } 16 | 17 | private static void ListBoxMouseButtonEvent(object sender, MouseButtonEventArgs mouseButtonEventArgs) 18 | { 19 | var senderElement = (UIElement) sender; 20 | 21 | if (!GetIsToggle(senderElement)) return; 22 | 23 | var point = mouseButtonEventArgs.GetPosition(senderElement); 24 | var result = VisualTreeHelper.HitTest(senderElement, point); 25 | 26 | if (result == null) return; 27 | 28 | ListBoxItem listBoxItem = null; 29 | Ripple ripple = null; 30 | foreach (var dependencyObject in result.VisualHit.GetVisualAncestry().TakeWhile(_ => listBoxItem == null)) 31 | { 32 | listBoxItem = dependencyObject as ListBoxItem; 33 | if (ripple == null) 34 | ripple = dependencyObject as Ripple; 35 | } 36 | 37 | if (listBoxItem == null) return; 38 | 39 | listBoxItem.SetCurrentValue(ListBoxItem.IsSelectedProperty, !listBoxItem.IsSelected); 40 | mouseButtonEventArgs.Handled = true; 41 | 42 | if (ripple != null && listBoxItem.IsSelected) 43 | { 44 | ripple.RaiseEvent(new MouseButtonEventArgs(mouseButtonEventArgs.MouseDevice, mouseButtonEventArgs.Timestamp, mouseButtonEventArgs.ChangedButton) 45 | { RoutedEvent = Control.PreviewMouseLeftButtonDownEvent, Source = ripple } 46 | ); 47 | } 48 | } 49 | 50 | public static readonly DependencyProperty IsToggleProperty = DependencyProperty.RegisterAttached( 51 | "IsToggle", typeof(bool), typeof(ListBoxAssist), new FrameworkPropertyMetadata(default(bool))); 52 | 53 | public static void SetIsToggle(DependencyObject element, bool value) 54 | { 55 | element.SetValue(IsToggleProperty, value); 56 | } 57 | 58 | public static bool GetIsToggle(DependencyObject element) 59 | { 60 | return (bool)element.GetValue(IsToggleProperty); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ListSortDirectionIndicator.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | 5 | namespace MaterialDesignThemes.Wpf 6 | { 7 | [TemplateVisualState(GroupName = DirectionGroupName, Name = NoneStateName)] 8 | [TemplateVisualState(GroupName = DirectionGroupName, Name = AscendingStateName)] 9 | [TemplateVisualState(GroupName = DirectionGroupName, Name = DescendingStateName)] 10 | public class ListSortDirectionIndicator : Control 11 | { 12 | public const string DirectionGroupName = "Direction"; 13 | public const string NoneStateName = "None"; 14 | public const string AscendingStateName = "Ascending"; 15 | public const string DescendingStateName = "Descending"; 16 | 17 | static ListSortDirectionIndicator() 18 | { 19 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ListSortDirectionIndicator), new FrameworkPropertyMetadata(typeof(ListSortDirectionIndicator))); 20 | } 21 | 22 | public override void OnApplyTemplate() 23 | { 24 | base.OnApplyTemplate(); 25 | 26 | GotoVisualState(true, ListSortDirection); 27 | } 28 | 29 | 30 | public static readonly DependencyProperty ListSortDirectionProperty = DependencyProperty.Register( 31 | nameof(ListSortDirection), typeof (ListSortDirection?), typeof (ListSortDirectionIndicator), new PropertyMetadata(default(ListSortDirection?), ListSortDirectionPropertyChangedCallback)); 32 | 33 | private static void ListSortDirectionPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) 34 | { 35 | var indicator = (ListSortDirectionIndicator) dependencyObject; 36 | indicator.GotoVisualState(true, indicator.ListSortDirection); 37 | indicator.IsNeutral = !indicator.ListSortDirection.HasValue; 38 | } 39 | 40 | public ListSortDirection? ListSortDirection 41 | { 42 | get { return (ListSortDirection?) GetValue(ListSortDirectionProperty); } 43 | set { SetValue(ListSortDirectionProperty, value); } 44 | } 45 | 46 | private static readonly DependencyPropertyKey IsNeutralPropertyKey = 47 | DependencyProperty.RegisterReadOnly( 48 | "IsNeutral", typeof (bool), typeof (ListSortDirectionIndicator), 49 | new PropertyMetadata(true)); 50 | 51 | public static readonly DependencyProperty IsNeutralProperty = 52 | IsNeutralPropertyKey.DependencyProperty; 53 | 54 | public bool IsNeutral 55 | { 56 | get { return (bool) GetValue(IsNeutralProperty); } 57 | private set { SetValue(IsNeutralPropertyKey, value); } 58 | } 59 | 60 | private void GotoVisualState(bool useTransitions, ListSortDirection? direction) 61 | { 62 | var stateName = direction.HasValue 63 | ? (direction.Value == System.ComponentModel.ListSortDirection.Ascending 64 | ? AscendingStateName 65 | : DescendingStateName) 66 | : NoneStateName; 67 | 68 | VisualStateManager.GoToState(this, stateName, useTransitions); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ListViewAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | public static class ListViewAssist 6 | { 7 | public static readonly DependencyProperty ListViewItemPaddingProperty = DependencyProperty.RegisterAttached( 8 | "ListViewItemPadding", 9 | typeof(Thickness), 10 | typeof(ListViewAssist), 11 | new FrameworkPropertyMetadata(new Thickness(8, 8, 8, 8), FrameworkPropertyMetadataOptions.Inherits)); 12 | 13 | public static void SetListViewItemPadding(DependencyObject element, Thickness value) 14 | { 15 | element.SetValue(ListViewItemPaddingProperty, value); 16 | } 17 | 18 | public static Thickness GetListViewItemPadding(DependencyObject element) 19 | { 20 | return (Thickness)element.GetValue(ListViewItemPaddingProperty); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/MaterialDataGridComboBoxColumn.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | using System.Windows.Data; 4 | 5 | namespace MaterialDesignThemes.Wpf 6 | { 7 | public class MaterialDataGridComboBoxColumn : DataGridComboBoxColumn //DataGridBoundColumn 8 | { 9 | static MaterialDataGridComboBoxColumn() 10 | { 11 | ElementStyleProperty.OverrideMetadata(typeof(MaterialDataGridComboBoxColumn), new FrameworkPropertyMetadata(DefaultElementStyle)); 12 | EditingElementStyleProperty.OverrideMetadata(typeof(MaterialDataGridComboBoxColumn), new FrameworkPropertyMetadata(DefaultEditingElementStyle)); 13 | } 14 | 15 | public Binding ItemsSourceBinding { get; set; } 16 | 17 | protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem) 18 | { 19 | var comboBox = base.GenerateElement(cell, cell); 20 | 21 | if (ItemsSourceBinding != null) 22 | comboBox.SetBinding(ItemsControl.ItemsSourceProperty, ItemsSourceBinding); 23 | ApplyStyle(false, false, comboBox); 24 | 25 | return comboBox; 26 | } 27 | 28 | protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) 29 | { 30 | var comboBox = (ComboBox)base.GenerateElement(cell, cell); 31 | 32 | if (ItemsSourceBinding != null) 33 | comboBox.SetBinding(ItemsControl.ItemsSourceProperty, ItemsSourceBinding); 34 | ApplyStyle(true, false, comboBox); 35 | 36 | return comboBox; 37 | } 38 | 39 | public static new Style DefaultElementStyle 40 | { 41 | get 42 | { 43 | var comboBox = new ComboBox(); 44 | 45 | var brushKey = new ComponentResourceKey(typeof(ComboBox), "MaterialDataGridComboBoxColumnStyle"); 46 | var style = (Style)comboBox.TryFindResource(brushKey); 47 | 48 | return style; 49 | } 50 | } 51 | 52 | public static new Style DefaultEditingElementStyle 53 | { 54 | get 55 | { 56 | var comboBox = new ComboBox(); 57 | 58 | var brushKey = new ComponentResourceKey(typeof(ComboBox), "MaterialDataGridComboBoxColumnEditingStyle"); 59 | var style = (Style)comboBox.TryFindResource(brushKey); 60 | 61 | return style; 62 | } 63 | } 64 | 65 | private void ApplyStyle(bool isEditing, bool defaultToElementStyle, FrameworkElement element) 66 | { 67 | var style = PickStyle(isEditing, defaultToElementStyle); 68 | if (style != null) 69 | { 70 | element.Style = style; 71 | } 72 | } 73 | 74 | private Style PickStyle(bool isEditing, bool defaultToElementStyle) 75 | { 76 | var style = isEditing ? EditingElementStyle : ElementStyle; 77 | if (isEditing && defaultToElementStyle && (style == null)) 78 | { 79 | style = ElementStyle; 80 | } 81 | 82 | return style; 83 | } 84 | 85 | /* 86 | /// 87 | /// Assigns the Binding to the desired property on the target object. 88 | /// 89 | private void ApplyBinding(DependencyObject target, DependencyProperty property) 90 | { 91 | var binding = Binding; 92 | if (binding != null) 93 | { 94 | BindingOperations.SetBinding(target, property, binding); 95 | } 96 | else 97 | { 98 | BindingOperations.ClearBinding(target, property); 99 | } 100 | } 101 | */ 102 | 103 | } 104 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/MaterialDataGridTextColumn.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public class MaterialDataGridTextColumn : DataGridTextColumn 7 | { 8 | protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs) 9 | { 10 | var textBox = editingElement as TextBox; 11 | if (textBox != null) 12 | { 13 | textBox.MaxLength = MaxLength; 14 | textBox.SelectionStart = textBox.Text.Length; 15 | } 16 | 17 | editingElement.Focus(); 18 | 19 | return null; 20 | } 21 | 22 | /// 23 | /// Set the maximum length for the text field. 24 | /// 25 | /// Not a dprop, as is only applied once. 26 | public int MaxLength { get; set; } 27 | } 28 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/MessageQueueExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Markup; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | /// 7 | /// Provides shorthand to initialise a new for a . 8 | /// 9 | [MarkupExtensionReturnType(typeof(SnackbarMessageQueue))] 10 | public class MessageQueueExtension : MarkupExtension 11 | { 12 | public override object ProvideValue(IServiceProvider serviceProvider) 13 | { 14 | return new SnackbarMessageQueue(); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/PackIcon.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using ControlzEx; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | /// 7 | /// Icon from the Material Design Icons project, . 8 | /// 9 | public class PackIcon : PackIconBase 10 | { 11 | static PackIcon() 12 | { 13 | DefaultStyleKeyProperty.OverrideMetadata(typeof(PackIcon), new FrameworkPropertyMetadata(typeof(PackIcon))); 14 | } 15 | 16 | public PackIcon() : base(PackIconDataFactory.Create) { } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/PackIconExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Markup; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | [MarkupExtensionReturnType(typeof(PackIcon))] 7 | public class PackIconExtension : MarkupExtension 8 | { 9 | public PackIconExtension() 10 | { } 11 | 12 | public PackIconExtension(PackIconKind kind) 13 | { 14 | Kind = kind; 15 | } 16 | 17 | public PackIconExtension(PackIconKind kind, double size) 18 | { 19 | Kind = kind; 20 | Size = size; 21 | } 22 | 23 | [ConstructorArgument("kind")] 24 | public PackIconKind Kind { get; set; } 25 | 26 | [ConstructorArgument("size")] 27 | public double? Size { get; set; } 28 | 29 | public override object ProvideValue(IServiceProvider serviceProvider) 30 | { 31 | var result = new PackIcon {Kind = Kind}; 32 | 33 | if (Size.HasValue) 34 | { 35 | result.Height = Size.Value; 36 | result.Width = Size.Value; 37 | } 38 | 39 | return result; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Palette.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignColors; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | /// 6 | /// Provides full information about a palette. 7 | /// 8 | public class Palette 9 | { 10 | public Palette(Swatch primarySwatch, Swatch accentSwatch, int primaryLightHueIndex, int primaryMidHueIndex, int primaryDarkHueIndex, int accentHueIndex) 11 | { 12 | PrimarySwatch = primarySwatch; 13 | AccentSwatch = accentSwatch; 14 | PrimaryLightHueIndex = primaryLightHueIndex; 15 | PrimaryMidHueIndex = primaryMidHueIndex; 16 | PrimaryDarkHueIndex = primaryDarkHueIndex; 17 | AccentHueIndex = accentHueIndex; 18 | } 19 | 20 | public Swatch PrimarySwatch { get; } 21 | 22 | public Swatch AccentSwatch { get; } 23 | 24 | public int PrimaryLightHueIndex { get; } 25 | 26 | public int PrimaryMidHueIndex { get; } 27 | 28 | public int PrimaryDarkHueIndex { get; } 29 | 30 | public int AccentHueIndex { get; } 31 | } 32 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using System.Windows; 4 | using System.Windows.Markup; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("MaterialDesignThemes.Wpf")] 10 | [assembly: AssemblyDescription("Material Design in XAML Toolkit - WPF Themes")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("Mulholland Software/James Willock")] 13 | [assembly: AssemblyProduct("MaterialDesignColors.Wpf")] 14 | [assembly: AssemblyCopyright("Copyright © 2015")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | [assembly: XmlnsPrefix("http://materialdesigninxaml.net/winfx/xaml/themes", "materialDesign")] 18 | [assembly: XmlnsDefinition("http://materialdesigninxaml.net/winfx/xaml/themes", "MaterialDesignThemes.Wpf")] 19 | [assembly: XmlnsDefinition("http://materialdesigninxaml.net/winfx/xaml/themes", "MaterialDesignThemes.Wpf.Transitions")] 20 | [assembly: XmlnsDefinition("http://materialdesigninxaml.net/winfx/xaml/themes", "MaterialDesignThemes.Wpf.Converters")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | [assembly: ComVisible(false)] 26 | 27 | //In order to begin building localizable applications, set 28 | //CultureYouAreCodingWith in your .csproj file 29 | //inside a . For example, if you are using US english 30 | //in your source files, set the to en-US. Then uncomment 31 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 32 | //the line below to match the UICulture setting in the project file. 33 | 34 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 35 | 36 | 37 | [assembly:ThemeInfo( 38 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 39 | //(used if a resource is not found in the page, 40 | // or application resource dictionaries) 41 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 42 | //(used if a resource is not found in the page, 43 | // app, or any theme specific resource dictionaries) 44 | )] 45 | 46 | 47 | // Version information for an assembly consists of the following four values: 48 | // 49 | // Major Version 50 | // Minor Version 51 | // Build Number 52 | // Revision 53 | // 54 | // You can specify all the values or you can default the Build and Revision Numbers 55 | // by using the '*' as shown below: 56 | // [assembly: AssemblyVersion("1.0.*")] 57 | 58 | //These will be replaced with the MDIX_CORE_VERSION property 59 | [assembly: AssemblyVersion("1.0.*")] 60 | [assembly: AssemblyFileVersion("1.0.0.0")] 61 | [assembly: AssemblyInformationalVersion("1.0.*")] 62 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.0 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace MaterialDesignThemes.Wpf.Properties { 12 | 13 | 14 | /// 15 | /// A strongly-typed resource class, for looking up localized strings, etc. 16 | /// 17 | // This class was auto-generated by the StronglyTypedResourceBuilder 18 | // class via a tool like ResGen or Visual Studio. 19 | // To add or remove a member, edit your .ResX file then rerun ResGen 20 | // with the /str option, or rebuild your VS project. 21 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 22 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 23 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 24 | internal class Resources { 25 | 26 | private static global::System.Resources.ResourceManager resourceMan; 27 | 28 | private static global::System.Globalization.CultureInfo resourceCulture; 29 | 30 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 31 | internal Resources() { 32 | } 33 | 34 | /// 35 | /// Returns the cached ResourceManager instance used by this class. 36 | /// 37 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 38 | internal static global::System.Resources.ResourceManager ResourceManager { 39 | get { 40 | if ((resourceMan == null)) { 41 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MaterialDesignThemes.Wpf.Properties.Resources", typeof(Resources).Assembly); 42 | resourceMan = temp; 43 | } 44 | return resourceMan; 45 | } 46 | } 47 | 48 | /// 49 | /// Overrides the current thread's CurrentUICulture property for all 50 | /// resource lookups using this strongly typed resource class. 51 | /// 52 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 53 | internal static global::System.Globalization.CultureInfo Culture { 54 | get { 55 | return resourceCulture; 56 | } 57 | set { 58 | resourceCulture = value; 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.0 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace MaterialDesignThemes.Wpf.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/RatingBarButton.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls.Primitives; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public class RatingBarButton : ButtonBase 7 | { 8 | static RatingBarButton() 9 | { 10 | DefaultStyleKeyProperty.OverrideMetadata(typeof(RatingBarButton), new FrameworkPropertyMetadata(typeof(RatingBarButton))); 11 | } 12 | 13 | private static readonly DependencyPropertyKey ValuePropertyKey = 14 | DependencyProperty.RegisterReadOnly( 15 | "Value", typeof (int), typeof (RatingBarButton), 16 | new PropertyMetadata(default(int))); 17 | 18 | public static readonly DependencyProperty ValueProperty = 19 | ValuePropertyKey.DependencyProperty; 20 | 21 | public int Value 22 | { 23 | get { return (int) GetValue(ValueProperty); } 24 | internal set { SetValue(ValuePropertyKey, value); } 25 | } 26 | 27 | private static readonly DependencyPropertyKey IsWithinValuePropertyKey = 28 | DependencyProperty.RegisterReadOnly( 29 | "IsWithinSelectedValue", typeof (bool), typeof (RatingBarButton), 30 | new PropertyMetadata(default(bool))); 31 | 32 | public static readonly DependencyProperty IsWithinSelectedValueProperty = 33 | IsWithinValuePropertyKey.DependencyProperty; 34 | 35 | public bool IsWithinSelectedValue 36 | { 37 | get { return (bool) GetValue(IsWithinSelectedValueProperty); } 38 | internal set { SetValue(IsWithinValuePropertyKey, value); } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/RippleAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Media; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public static class RippleAssist 7 | { 8 | #region ClipToBound 9 | 10 | public static readonly DependencyProperty ClipToBoundsProperty = DependencyProperty.RegisterAttached( 11 | "ClipToBounds", typeof(bool), typeof(RippleAssist), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.Inherits)); 12 | 13 | public static void SetClipToBounds(DependencyObject element, bool value) 14 | { 15 | element.SetValue(ClipToBoundsProperty, value); 16 | } 17 | 18 | public static bool GetClipToBounds(DependencyObject element) 19 | { 20 | return (bool)element.GetValue(ClipToBoundsProperty); 21 | } 22 | 23 | #endregion 24 | 25 | #region StayOnCenter 26 | 27 | /// 28 | /// Set to true to cause the ripple to originate from the centre of the 29 | /// content. Otherwise the effect will originate from the mouse down position. 30 | /// 31 | public static readonly DependencyProperty IsCenteredProperty = DependencyProperty.RegisterAttached( 32 | "IsCentered", typeof(bool), typeof(RippleAssist), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits)); 33 | 34 | /// 35 | /// Set to true to cause the ripple to originate from the centre of the 36 | /// content. Otherwise the effect will originate from the mouse down position. 37 | /// 38 | /// 39 | /// 40 | public static void SetIsCentered(DependencyObject element, bool value) 41 | { 42 | element.SetValue(IsCenteredProperty, value); 43 | } 44 | 45 | /// 46 | /// Set to true to cause the ripple to originate from the centre of the 47 | /// content. Otherwise the effect will originate from the mouse down position. 48 | /// 49 | /// 50 | public static bool GetIsCentered(DependencyObject element) 51 | { 52 | return (bool)element.GetValue(IsCenteredProperty); 53 | } 54 | 55 | #endregion 56 | 57 | #region disable 58 | 59 | /// 60 | /// Set to True to disable ripple effect 61 | /// 62 | public static readonly DependencyProperty IsDisabledProperty = DependencyProperty.RegisterAttached( 63 | "IsDisabled", typeof(bool), typeof(RippleAssist), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits)); 64 | 65 | /// 66 | /// Set to True to disable ripple effect 67 | /// 68 | /// 69 | /// 70 | public static void SetIsDisabled(DependencyObject element, bool value) 71 | { 72 | element.SetValue(IsDisabledProperty, value); 73 | } 74 | 75 | /// 76 | /// Set to True to disable ripple effect 77 | /// 78 | /// 79 | public static bool GetIsDisabled(DependencyObject element) 80 | { 81 | return (bool)element.GetValue(IsDisabledProperty); 82 | } 83 | 84 | #endregion 85 | 86 | #region RippleSizeMultiplier 87 | 88 | public static readonly DependencyProperty RippleSizeMultiplierProperty = DependencyProperty.RegisterAttached( 89 | "RippleSizeMultiplier", typeof(double), typeof(RippleAssist), new FrameworkPropertyMetadata(1.0, FrameworkPropertyMetadataOptions.Inherits)); 90 | 91 | public static void SetRippleSizeMultiplier(DependencyObject element, double value) 92 | { 93 | element.SetValue(RippleSizeMultiplierProperty, value); 94 | } 95 | 96 | public static double GetRippleSizeMultiplier(DependencyObject element) 97 | { 98 | return (double)element.GetValue(RippleSizeMultiplierProperty); 99 | } 100 | 101 | #endregion 102 | 103 | #region Feedback 104 | 105 | public static readonly DependencyProperty FeedbackProperty = DependencyProperty.RegisterAttached( 106 | "Feedback", typeof(Brush), typeof(RippleAssist), new FrameworkPropertyMetadata(default(Brush), FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsRender)); 107 | 108 | public static void SetFeedback(DependencyObject element, Brush value) 109 | { 110 | element.SetValue(FeedbackProperty, value); 111 | } 112 | 113 | public static Brush GetFeedback(DependencyObject element) 114 | { 115 | return (Brush)element.GetValue(FeedbackProperty); 116 | } 117 | 118 | #endregion 119 | 120 | 121 | } 122 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ScaleHost.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | /// 6 | /// Internal use only. 7 | /// 8 | public class ScaleHost : FrameworkElement 9 | { 10 | public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register( 11 | "Scale", typeof(double), typeof(ScaleHost), new PropertyMetadata(0.0)); 12 | 13 | public double Scale 14 | { 15 | get { return (double) GetValue(ScaleProperty); } 16 | set { SetValue(ScaleProperty, value); } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ScrollViewerAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | internal static class ScrollViewerAssist 7 | { 8 | public static readonly DependencyProperty HorizontalOffsetProperty = DependencyProperty.RegisterAttached( 9 | "SyncHorizontalOffset", typeof(double), typeof(ScrollViewerAssist), new PropertyMetadata(default(double), OnSyncHorizontalOffsetChanged)); 10 | 11 | private static void OnSyncHorizontalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 12 | { 13 | var scrollViewer = d as ScrollViewer; 14 | scrollViewer?.ScrollToHorizontalOffset((double)e.NewValue); 15 | } 16 | 17 | public static void SetSyncHorizontalOffset(DependencyObject element, double value) 18 | { 19 | element.SetValue(HorizontalOffsetProperty, value); 20 | } 21 | 22 | public static double GetSyncHorizontalOffset(DependencyObject element) 23 | { 24 | return (double) element.GetValue(HorizontalOffsetProperty); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/SnackbarMessageEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | public class SnackbarMessageEventArgs : RoutedEventArgs 6 | { 7 | public SnackbarMessageEventArgs(SnackbarMessage message) 8 | { 9 | Message = message; 10 | } 11 | 12 | public SnackbarMessageEventArgs(RoutedEvent routedEvent, SnackbarMessage message) : base(routedEvent) 13 | { 14 | Message = message; 15 | } 16 | 17 | public SnackbarMessageEventArgs(RoutedEvent routedEvent, object source, SnackbarMessage message) : base(routedEvent, source) 18 | { 19 | Message = message; 20 | } 21 | 22 | public SnackbarMessage Message { get; } 23 | } 24 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/SnackbarMessageQueueItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | internal class SnackbarMessageQueueItem 6 | { 7 | public SnackbarMessageQueueItem(object content, object actionContent = null, Action actionHandler = null, object actionArgument = null, 8 | bool isPromoted = false, bool ignoreDuplicate = false) 9 | { 10 | Content = content; 11 | ActionContent = actionContent; 12 | ActionHandler = actionHandler; 13 | ActionArgument = actionArgument; 14 | IsPromoted = isPromoted; 15 | IgnoreDuplicate = ignoreDuplicate; 16 | } 17 | 18 | /// 19 | /// The content to be displayed 20 | /// 21 | public object Content { get; } 22 | 23 | /// 24 | /// The content for the action button on the snackbar 25 | /// 26 | public object ActionContent { get; } 27 | 28 | /// 29 | /// Handler to be invoked when the action button is clicked 30 | /// 31 | public Action ActionHandler { get; } 32 | 33 | /// 34 | /// The argument to pass to the delegate. 35 | /// 36 | public object ActionArgument { get; } 37 | 38 | /// 39 | /// Promote the message, pushing it in front of any message that is not promoted. 40 | /// 41 | public bool IsPromoted { get; } 42 | 43 | /// 44 | /// Still display this message even if it is a duplicate. 45 | /// 46 | public bool IgnoreDuplicate { get; } 47 | } 48 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Spelling.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf 4 | { 5 | public static class Spelling 6 | { 7 | public static ResourceKey SuggestionMenuItemStyleKey { get; } = new ComponentResourceKey(typeof(Spelling), ResourceKeyId.SpellingSuggestionMenuItemStyle); 8 | public static ResourceKey IgnoreAllMenuItemStyleKey { get; } = new ComponentResourceKey(typeof(Spelling), ResourceKeyId.SpellingIgnoreAllMenuItemStyle); 9 | public static ResourceKey NoSuggestionsMenuItemStyleKey { get; } = new ComponentResourceKey(typeof(Spelling), ResourceKeyId.SpellingNoSuggestionsMenuItemStyle); 10 | public static ResourceKey SeparatorStyleKey { get; } = new ComponentResourceKey(typeof(Spelling), ResourceKeyId.SpellingSeparatorStyle); 11 | } 12 | 13 | internal enum ResourceKeyId 14 | { 15 | SpellingSuggestionMenuItemStyle, 16 | SpellingIgnoreAllMenuItemStyle, 17 | SpellingNoSuggestionsMenuItemStyle, 18 | SpellingSeparatorStyle, 19 | } 20 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | 5 | namespace MaterialDesignThemes.Wpf 6 | { 7 | internal static class StringExtensions 8 | { 9 | public static string ToTitleCase(this string text, CultureInfo culture, string separator = " ") 10 | { 11 | TextInfo textInfo = culture.TextInfo; 12 | 13 | string lowerText = textInfo.ToLower(text); 14 | string[] words = lowerText.Split(new[] { separator }, StringSplitOptions.None); 15 | 16 | return String.Join(separator, words.Select(v => textInfo.ToTitleCase(v))); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ThemeAssist.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public static class ThemeAssist 7 | { 8 | public static BaseTheme GetTheme(DependencyObject obj) 9 | { 10 | return (BaseTheme)obj.GetValue(ThemeProperty); 11 | } 12 | 13 | public static void SetTheme(DependencyObject obj, BaseTheme value) 14 | { 15 | obj.SetValue(ThemeProperty, value); 16 | } 17 | 18 | public static readonly DependencyProperty ThemeProperty = 19 | DependencyProperty.RegisterAttached("Theme", typeof(BaseTheme), typeof(ThemeAssist), new PropertyMetadata(default(BaseTheme), OnThemeChanged)); 20 | 21 | private static void OnThemeChanged(DependencyObject @do, DependencyPropertyChangedEventArgs e) 22 | { 23 | if (@do is FrameworkElement element) 24 | { 25 | if (e.OldValue is BaseTheme oldTheme && 26 | GetResourceDictionarySource(oldTheme) is string oldSource) 27 | { 28 | foreach(ResourceDictionary resourceDictionary in element.Resources.MergedDictionaries) 29 | { 30 | if (string.Equals(resourceDictionary.Source?.ToString(), oldSource, StringComparison.OrdinalIgnoreCase)) 31 | { 32 | element.Resources.MergedDictionaries.Remove(resourceDictionary); 33 | break; 34 | } 35 | } 36 | } 37 | 38 | if (e.NewValue is BaseTheme newTheme && 39 | GetResourceDictionarySource(newTheme) is string newThemeSource) 40 | { 41 | element.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri(newThemeSource) }); 42 | } 43 | } 44 | } 45 | 46 | private static string GetResourceDictionarySource(BaseTheme theme) 47 | { 48 | switch (theme) 49 | { 50 | case BaseTheme.Light: 51 | return "pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml"; 52 | case BaseTheme.Dark: 53 | return "pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml"; 54 | } 55 | return null; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ToggleButtonAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls.Primitives; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public static class ToggleButtonAssist 7 | { 8 | private static readonly DependencyPropertyKey HasOnContentPropertyKey = 9 | DependencyProperty.RegisterAttachedReadOnly( 10 | "HasOnContent", typeof(bool), typeof(ToggleButtonAssist), 11 | new PropertyMetadata(false)); 12 | 13 | public static readonly DependencyProperty HasOnContentProperty = HasOnContentPropertyKey.DependencyProperty; 14 | 15 | private static void SetHasOnContent(DependencyObject element, object value) 16 | { 17 | element.SetValue(HasOnContentPropertyKey, value); 18 | } 19 | 20 | /// 21 | /// Framework use only. 22 | /// 23 | /// 24 | /// 25 | public static bool GetHasOnContent(DependencyObject element) 26 | { 27 | return (bool)element.GetValue(HasOnContentProperty); 28 | } 29 | 30 | /// 31 | /// Allows on (IsChecked) content to be provided on supporting styles. 32 | /// 33 | public static readonly DependencyProperty OnContentProperty = DependencyProperty.RegisterAttached( 34 | "OnContent", typeof (object), typeof (ToggleButtonAssist), new PropertyMetadata(default(object), OnContentPropertyChangedCallback)); 35 | 36 | private static void OnContentPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) 37 | { 38 | SetHasOnContent(dependencyObject, dependencyPropertyChangedEventArgs.NewValue != null); 39 | } 40 | 41 | /// 42 | /// Allows on (IsChecked) content to be provided on supporting styles. 43 | /// 44 | /// 45 | /// 46 | public static void SetOnContent(DependencyObject element, object value) 47 | { 48 | element.SetValue(OnContentProperty, value); 49 | } 50 | 51 | /// 52 | /// Allows on (IsChecked) content to be provided on supporting styles. 53 | /// 54 | public static object GetOnContent(DependencyObject element) 55 | { 56 | return (object) element.GetValue(OnContentProperty); 57 | } 58 | 59 | /// 60 | /// Allows an on (IsChecked) template to be provided on supporting styles. 61 | /// 62 | public static readonly DependencyProperty OnContentTemplateProperty = DependencyProperty.RegisterAttached( 63 | "OnContentTemplate", typeof (DataTemplate), typeof (ToggleButtonAssist), new PropertyMetadata(default(DataTemplate))); 64 | 65 | /// 66 | /// Allows an on (IsChecked) template to be provided on supporting styles. 67 | /// 68 | public static void SetOnContentTemplate(DependencyObject element, DataTemplate value) 69 | { 70 | element.SetValue(OnContentTemplateProperty, value); 71 | } 72 | 73 | /// 74 | /// Allows an on (IsChecked) template to be provided on supporting styles. 75 | /// 76 | public static DataTemplate GetOnContentTemplate(DependencyObject element) 77 | { 78 | return (DataTemplate) element.GetValue(OnContentTemplateProperty); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ToolTipAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls.Primitives; 3 | 4 | namespace MaterialDesignThemes.Wpf 5 | { 6 | public static class ToolTipAssist 7 | { 8 | public static CustomPopupPlacementCallback CustomPopupPlacementCallback => CustomPopupPlacementCallbackImpl; 9 | 10 | public static CustomPopupPlacement[] CustomPopupPlacementCallbackImpl(Size popupSize, Size targetSize, Point offset) 11 | { 12 | return new [] 13 | { 14 | new CustomPopupPlacement(new Point(targetSize.Width/2 - popupSize.Width/2, targetSize.Height + 14), PopupPrimaryAxis.Horizontal) 15 | }; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/CircleWipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Animation; 5 | 6 | namespace MaterialDesignThemes.Wpf.Transitions 7 | { 8 | public class CircleWipe : ITransitionWipe 9 | { 10 | public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point origin, IZIndexController zIndexController) 11 | { 12 | if (fromSlide == null) throw new ArgumentNullException(nameof(fromSlide)); 13 | if (toSlide == null) throw new ArgumentNullException(nameof(toSlide)); 14 | if (zIndexController == null) throw new ArgumentNullException(nameof(zIndexController)); 15 | 16 | var horizontalProportion = Math.Max(1.0 - origin.X, 1.0 * origin.X); 17 | var verticalProportion = Math.Max(1.0 - origin.Y, 1.0 * origin.Y); 18 | var radius = Math.Sqrt(Math.Pow(toSlide.ActualWidth * horizontalProportion, 2) + Math.Pow(toSlide.ActualHeight * verticalProportion, 2)); 19 | 20 | var scaleTransform = new ScaleTransform(0, 0); 21 | var translateTransform = new TranslateTransform(toSlide.ActualWidth * origin.X, toSlide.ActualHeight * origin.Y); 22 | var transformGroup = new TransformGroup(); 23 | transformGroup.Children.Add(scaleTransform); 24 | transformGroup.Children.Add(translateTransform); 25 | var ellipseGeomotry = new EllipseGeometry() 26 | { 27 | RadiusX = radius, 28 | RadiusY = radius, 29 | Transform = transformGroup 30 | }; 31 | 32 | toSlide.SetCurrentValue(UIElement.ClipProperty, ellipseGeomotry); 33 | zIndexController.Stack(toSlide, fromSlide); 34 | 35 | var zeroKeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero); 36 | var midKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)); 37 | var endKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400)); 38 | 39 | var opacityAnimation = new DoubleAnimationUsingKeyFrames(); 40 | opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, zeroKeyTime)); 41 | opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, midKeyTime)); 42 | opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, endKeyTime)); 43 | opacityAnimation.Completed += (sender, args) => 44 | { 45 | fromSlide.BeginAnimation(UIElement.OpacityProperty, null); 46 | fromSlide.Opacity = 0; 47 | }; 48 | fromSlide.BeginAnimation(UIElement.OpacityProperty, opacityAnimation); 49 | 50 | var scaleAnimation = new DoubleAnimationUsingKeyFrames(); 51 | scaleAnimation.Completed += (sender, args) => 52 | { 53 | toSlide.SetCurrentValue(UIElement.ClipProperty, null); 54 | fromSlide.BeginAnimation(UIElement.OpacityProperty, null); 55 | fromSlide.Opacity = 0; 56 | }; 57 | scaleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, zeroKeyTime)); 58 | scaleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, endKeyTime)); 59 | scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation); 60 | scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/FadeWipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media.Animation; 4 | 5 | namespace MaterialDesignThemes.Wpf.Transitions 6 | { 7 | public class FadeWipe : ITransitionWipe 8 | { 9 | private readonly SineEase _sineEase = new SineEase(); 10 | 11 | /// 12 | /// Duration of the animation 13 | /// 14 | public TimeSpan Duration { get; set; } = TimeSpan.FromSeconds(0.5); 15 | 16 | public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point origin, IZIndexController zIndexController) 17 | { 18 | if (fromSlide == null) throw new ArgumentNullException(nameof(fromSlide)); 19 | if (toSlide == null) throw new ArgumentNullException(nameof(toSlide)); 20 | if (zIndexController == null) throw new ArgumentNullException(nameof(zIndexController)); 21 | 22 | // Set up time points 23 | var zeroKeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero); 24 | var endKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Duration.TotalSeconds/2)); 25 | 26 | // From 27 | var fromAnimation = new DoubleAnimationUsingKeyFrames(); 28 | fromAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(1, zeroKeyTime)); 29 | fromAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, endKeyTime, _sineEase)); 30 | 31 | // To 32 | var toAnimation = new DoubleAnimationUsingKeyFrames(); 33 | toAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(0, zeroKeyTime)); 34 | toAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, endKeyTime, _sineEase)); 35 | 36 | // Preset 37 | fromSlide.Opacity = 1; 38 | toSlide.Opacity = 0; 39 | 40 | // Set up events 41 | toAnimation.Completed += (sender, args) => 42 | { 43 | toSlide.BeginAnimation(UIElement.OpacityProperty, null); 44 | fromSlide.Opacity = 0; 45 | toSlide.Opacity = 1; 46 | }; 47 | fromAnimation.Completed += (sender, args) => 48 | { 49 | fromSlide.BeginAnimation(UIElement.OpacityProperty, null); 50 | fromSlide.Opacity = 0; 51 | toSlide.BeginAnimation(UIElement.OpacityProperty, toAnimation); 52 | }; 53 | 54 | // Animate 55 | fromSlide.BeginAnimation(UIElement.OpacityProperty, fromAnimation); 56 | zIndexController.Stack(toSlide, fromSlide); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/ITransitionEffect.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Media.Animation; 3 | 4 | namespace MaterialDesignThemes.Wpf.Transitions 5 | { 6 | public interface ITransitionEffect 7 | { 8 | Timeline Build(TSubject effectSubject) where TSubject : FrameworkElement, ITransitionEffectSubject; 9 | } 10 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/ITransitionEffectSubject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MaterialDesignThemes.Wpf.Transitions 4 | { 5 | public interface ITransitionEffectSubject 6 | { 7 | string MatrixTransformName { get; } 8 | string RotateTransformName { get; } 9 | string ScaleTransformName { get; } 10 | string SkewTransformName { get; } 11 | string TranslateTransformName { get; } 12 | TimeSpan Offset { get; } 13 | } 14 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/ITransitionWipe.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf.Transitions 4 | { 5 | public interface ITransitionWipe 6 | { 7 | void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point origin, IZIndexController zIndexController); 8 | } 9 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/IZIndexController.cs: -------------------------------------------------------------------------------- 1 | namespace MaterialDesignThemes.Wpf.Transitions 2 | { 3 | public interface IZIndexController 4 | { 5 | void Stack(params TransitionerSlide[] highestToLowest); 6 | } 7 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/IndexedItemOffsetMultiplierExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Markup; 5 | using System.Windows.Media; 6 | 7 | namespace MaterialDesignThemes.Wpf.Transitions 8 | { 9 | /// 10 | /// Multiplies a time span unit by the index of an item in a list. 11 | /// 12 | /// 13 | /// Example usage is for a to have a 14 | /// time delayed according to position in a list, so cascading animations can occur. 15 | /// 16 | [MarkupExtensionReturnType(typeof(TimeSpan))] 17 | public class IndexedItemOffsetMultiplierExtension : MarkupExtension 18 | { 19 | public IndexedItemOffsetMultiplierExtension(TimeSpan unit) 20 | { 21 | Unit = unit; 22 | } 23 | 24 | [ConstructorArgument("unit")] 25 | public TimeSpan Unit { get; set; } 26 | 27 | public override object ProvideValue(IServiceProvider serviceProvider) 28 | { 29 | var provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; 30 | if (provideValueTarget == null) return TimeSpan.Zero; 31 | 32 | if (provideValueTarget.TargetObject != null && 33 | provideValueTarget.TargetObject.GetType().FullName == "System.Windows.SharedDp") 34 | //we are inside a template, return this, so we can re-evaluate later... 35 | return this; 36 | 37 | var element = provideValueTarget?.TargetObject as DependencyObject; 38 | if (element == null) return TimeSpan.Zero; 39 | 40 | var itemsControl = ItemsControl.ItemsControlFromItemContainer(element); 41 | if (itemsControl == null) 42 | { 43 | var ancestor = element; 44 | while (ancestor != null && itemsControl == null) 45 | { 46 | ancestor = VisualTreeHelper.GetParent(ancestor); 47 | itemsControl = ItemsControl.ItemsControlFromItemContainer(ancestor); 48 | } 49 | } 50 | if (itemsControl == null) return TimeSpan.Zero; 51 | 52 | var isOwnContainer = itemsControl.IsItemItsOwnContainer(element); 53 | var container = isOwnContainer 54 | ? element 55 | : itemsControl.ItemContainerGenerator.ContainerFromItem(element); 56 | if (container == null) 57 | { 58 | var dataContext = (element as FrameworkElement)?.DataContext; 59 | if (dataContext != null) 60 | container = itemsControl.ItemContainerGenerator.ContainerFromItem(dataContext); 61 | } 62 | 63 | if (container == null) return TimeSpan.Zero; 64 | 65 | var multiplier = itemsControl.ItemContainerGenerator.IndexFromContainer(container); 66 | if (multiplier == -1) //container generation may not have completed 67 | { 68 | multiplier = itemsControl.Items.IndexOf(element); 69 | } 70 | 71 | if (multiplier == -1) //still not found, repeat now using datacontext 72 | { 73 | var frameworkElement = element as FrameworkElement; 74 | if (frameworkElement != null) 75 | { 76 | multiplier = itemsControl.Items.IndexOf(frameworkElement.DataContext); 77 | } 78 | } 79 | 80 | return multiplier > -1 ? new TimeSpan(Unit.Ticks * multiplier) : TimeSpan.Zero; 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/SlideDirection.cs: -------------------------------------------------------------------------------- 1 | namespace MaterialDesignThemes.Wpf.Transitions 2 | { 3 | public enum SlideDirection { Left, Right, Up, Down } 4 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/SlideOutWipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Animation; 5 | 6 | namespace MaterialDesignThemes.Wpf.Transitions 7 | { 8 | public class SlideOutWipe : ITransitionWipe 9 | { 10 | private readonly SineEase _sineEase = new SineEase(); 11 | 12 | public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point origin, IZIndexController zIndexController) 13 | { 14 | if (fromSlide == null) throw new ArgumentNullException(nameof(fromSlide)); 15 | if (toSlide == null) throw new ArgumentNullException(nameof(toSlide)); 16 | if (zIndexController == null) throw new ArgumentNullException(nameof(zIndexController)); 17 | 18 | var zeroKeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero); 19 | var midishKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)); 20 | var endKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400)); 21 | 22 | //back out old slide setup 23 | var scaleTransform = new ScaleTransform(1, 1); 24 | fromSlide.RenderTransform = scaleTransform; 25 | var scaleAnimation = new DoubleAnimationUsingKeyFrames(); 26 | scaleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, zeroKeyTime)); 27 | scaleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(.8, endKeyTime)); 28 | scaleAnimation.Completed += (sender, args) => 29 | { 30 | fromSlide.RenderTransform = null; 31 | }; 32 | var opacityAnimation = new DoubleAnimationUsingKeyFrames(); 33 | opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, zeroKeyTime)); 34 | opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, endKeyTime)); 35 | opacityAnimation.Completed += (sender, args) => 36 | { 37 | fromSlide.BeginAnimation(UIElement.OpacityProperty, null); 38 | fromSlide.Opacity = 0; 39 | }; 40 | 41 | //slide in new slide setup 42 | var translateTransform = new TranslateTransform(0, toSlide.ActualHeight); 43 | toSlide.RenderTransform = translateTransform; 44 | var slideAnimation = new DoubleAnimationUsingKeyFrames(); 45 | slideAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(toSlide.ActualHeight, zeroKeyTime)); 46 | slideAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(toSlide.ActualHeight, midishKeyTime) { EasingFunction = _sineEase}); 47 | slideAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, endKeyTime) { EasingFunction = _sineEase }); 48 | 49 | //kick off! 50 | translateTransform.BeginAnimation(TranslateTransform.YProperty, slideAnimation); 51 | scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation); 52 | scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation); 53 | fromSlide.BeginAnimation(UIElement.OpacityProperty, opacityAnimation); 54 | 55 | zIndexController.Stack(toSlide, fromSlide); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/TransitionAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf.Transitions 4 | { 5 | /// 6 | /// Allows transitions to be disabled where supported. 7 | /// 8 | public static class TransitionAssist 9 | { 10 | /// 11 | /// Allows transitions to be disabled where supported. Note this is an inheritable property. 12 | /// 13 | public static readonly DependencyProperty DisableTransitionsProperty = DependencyProperty.RegisterAttached( 14 | "DisableTransitions", typeof (bool), typeof (TransitionAssist), new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.Inherits)); 15 | 16 | /// 17 | /// Allows transitions to be disabled where supported. Note this is an inheritable property. 18 | /// 19 | public static void SetDisableTransitions(DependencyObject element, bool value) 20 | { 21 | element.SetValue(DisableTransitionsProperty, value); 22 | } 23 | 24 | /// 25 | /// Allows transitions to be disabled where supported. Note this is an inheritable property. 26 | /// 27 | public static bool GetDisableTransitions(DependencyObject element) 28 | { 29 | return (bool) element.GetValue(DisableTransitionsProperty); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/TransitionEffectBase.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Media.Animation; 3 | 4 | namespace MaterialDesignThemes.Wpf.Transitions 5 | { 6 | public abstract class TransitionEffectBase : FrameworkElement, ITransitionEffect 7 | { 8 | public abstract Timeline Build(TSubject effectSubject) where TSubject : FrameworkElement, ITransitionEffectSubject; 9 | } 10 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/TransitionEffectExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Markup; 3 | 4 | namespace MaterialDesignThemes.Wpf.Transitions 5 | { 6 | [MarkupExtensionReturnType(typeof(TransitionEffectBase))] 7 | public class TransitionEffectExtension : MarkupExtension 8 | { 9 | public TransitionEffectExtension() 10 | { 11 | Kind = TransitionEffectKind.None; 12 | } 13 | 14 | public TransitionEffectExtension(TransitionEffectKind kind) 15 | { 16 | Kind = kind; 17 | } 18 | 19 | public TransitionEffectExtension(TransitionEffectKind kind, TimeSpan duration) 20 | { 21 | Kind = kind; 22 | Duration = duration; 23 | } 24 | 25 | [ConstructorArgument("kind")] 26 | public TransitionEffectKind Kind { get; set; } 27 | 28 | [ConstructorArgument("duration")] 29 | public TimeSpan? Duration { get; set; } 30 | 31 | public override object ProvideValue(IServiceProvider serviceProvider) 32 | { 33 | return Duration.HasValue ? new TransitionEffect(Kind, Duration.Value) : new TransitionEffect(Kind); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/TransitionEffectKind.cs: -------------------------------------------------------------------------------- 1 | namespace MaterialDesignThemes.Wpf.Transitions 2 | { 3 | public enum TransitionEffectKind 4 | { 5 | None, 6 | ExpandIn, 7 | FadeIn, 8 | SlideInFromLeft, 9 | SlideInFromTop, 10 | SlideInFromRight, 11 | SlideInFromBottom 12 | } 13 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/TransitionEffectTypeConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Globalization; 4 | using System.Windows.Markup; 5 | 6 | namespace MaterialDesignThemes.Wpf.Transitions 7 | { 8 | public class TransitionEffectTypeConverter : TypeConverter 9 | { 10 | public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) 11 | { 12 | return sourceType == typeof(string) || typeof(TransitionEffectKind).IsAssignableFrom(sourceType); 13 | } 14 | 15 | public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) 16 | { 17 | TransitionEffectBase transitionEffect; 18 | 19 | if (value is string stringValue && 20 | Enum.TryParse(stringValue, out TransitionEffectKind effectKind)) 21 | { 22 | transitionEffect = new TransitionEffect(effectKind); 23 | } 24 | else 25 | { 26 | transitionEffect = value as TransitionEffectBase; 27 | } 28 | 29 | if (transitionEffect == null) 30 | throw new XamlParseException($"Could not parse to type {typeof(TransitionEffectKind).FullName} or {typeof(TransitionEffectBase).FullName}."); 31 | 32 | return transitionEffect; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/TransitionerSlide.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace MaterialDesignThemes.Wpf.Transitions 4 | { 5 | /// 6 | /// Content control to host the content of an individual page within a . 7 | /// 8 | public class TransitionerSlide : TransitioningContentBase 9 | { 10 | static TransitionerSlide() 11 | { 12 | DefaultStyleKeyProperty.OverrideMetadata(typeof(TransitionerSlide), new FrameworkPropertyMetadata(typeof(TransitionerSlide))); 13 | } 14 | 15 | public static readonly DependencyProperty TransitionOriginProperty = DependencyProperty.Register( 16 | "TransitionOrigin", typeof(Point), typeof(Transitioner), new PropertyMetadata(new Point(0.5, 0.5))); 17 | 18 | public Point TransitionOrigin 19 | { 20 | get => (Point)GetValue(TransitionOriginProperty); 21 | set => SetValue(TransitionOriginProperty, value); 22 | } 23 | 24 | public static RoutedEvent InTransitionFinished = 25 | EventManager.RegisterRoutedEvent("InTransitionFinished", RoutingStrategy.Bubble, typeof(RoutedEventHandler), 26 | typeof(TransitionerSlide)); 27 | 28 | protected void OnInTransitionFinished(RoutedEventArgs e) 29 | { 30 | RaiseEvent(e); 31 | } 32 | 33 | public static readonly DependencyProperty StateProperty = DependencyProperty.Register("State", typeof(TransitionerSlideState), typeof(TransitionerSlide), new PropertyMetadata(default(TransitionerSlideState), new PropertyChangedCallback(StatePropertyChangedCallback))); 34 | 35 | private static void StatePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) 36 | { 37 | ((TransitionerSlide)d).AnimateToState(); 38 | } 39 | 40 | public TransitionerSlideState State 41 | { 42 | get => (TransitionerSlideState)GetValue(StateProperty); 43 | set => SetValue(StateProperty, value); 44 | } 45 | 46 | public static readonly DependencyProperty ForwardWipeProperty = DependencyProperty.Register( 47 | "ForwardWipe", typeof(ITransitionWipe), typeof(TransitionerSlide), new PropertyMetadata(new CircleWipe())); 48 | 49 | public ITransitionWipe ForwardWipe 50 | { 51 | get => (ITransitionWipe)GetValue(ForwardWipeProperty); 52 | set => SetValue(ForwardWipeProperty, value); 53 | } 54 | 55 | public static readonly DependencyProperty BackwardWipeProperty = DependencyProperty.Register( 56 | "BackwardWipe", typeof(ITransitionWipe), typeof(TransitionerSlide), new PropertyMetadata(new SlideOutWipe())); 57 | 58 | public ITransitionWipe BackwardWipe 59 | { 60 | get => (ITransitionWipe)GetValue(BackwardWipeProperty); 61 | set => SetValue(BackwardWipeProperty, value); 62 | } 63 | 64 | private void AnimateToState() 65 | { 66 | if (State != TransitionerSlideState.Current) return; 67 | 68 | RunOpeningEffects(); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/TransitionerSlideState.cs: -------------------------------------------------------------------------------- 1 | namespace MaterialDesignThemes.Wpf.Transitions 2 | { 3 | public enum TransitionerSlideState 4 | { 5 | None, 6 | Current, 7 | Previous, 8 | } 9 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Transitions/TransitioningContent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | 4 | namespace MaterialDesignThemes.Wpf.Transitions 5 | { 6 | [Flags] 7 | public enum TransitioningContentRunHint 8 | { 9 | Loaded = 1, 10 | IsVisibleChanged = 2, 11 | All = Loaded | IsVisibleChanged 12 | } 13 | 14 | 15 | /// 16 | /// Content control to enable easier transitions. 17 | /// 18 | public class TransitioningContent : TransitioningContentBase 19 | { 20 | static TransitioningContent() 21 | { 22 | DefaultStyleKeyProperty.OverrideMetadata(typeof(TransitioningContent), new FrameworkPropertyMetadata(typeof(TransitioningContent))); 23 | } 24 | 25 | public TransitioningContent() 26 | { 27 | Loaded += (sender, args) => Run(TransitioningContentRunHint.Loaded); 28 | IsVisibleChanged += (sender, args) => Run(TransitioningContentRunHint.IsVisibleChanged); 29 | 30 | } 31 | 32 | public static readonly DependencyProperty RunHintProperty = DependencyProperty.Register( 33 | nameof(RunHint), typeof(TransitioningContentRunHint), typeof(TransitioningContent), new PropertyMetadata(TransitioningContentRunHint.All)); 34 | 35 | public TransitioningContentRunHint RunHint 36 | { 37 | get => (TransitioningContentRunHint)GetValue(RunHintProperty); 38 | set => SetValue(RunHintProperty, value); 39 | } 40 | 41 | private void Run(TransitioningContentRunHint requiredHint) 42 | { 43 | if ((RunHint & requiredHint) == requiredHint) 44 | RunOpeningEffects(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/TreeHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | 5 | namespace MaterialDesignThemes.Wpf 6 | { 7 | internal static class TreeHelper 8 | { 9 | public static double GetVisibleWidth(FrameworkElement element, UIElement parent) 10 | { 11 | if (element == null) throw new ArgumentNullException(nameof(element)); 12 | if (parent == null) throw new ArgumentNullException(nameof(parent)); 13 | 14 | var location = element.TransformToAncestor(parent).Transform(new Point(0, 0)); 15 | 16 | int width = (int) Math.Floor(element.ActualWidth); 17 | var hitTest = parent.InputHitTest(new Point(location.X + width, location.Y)); 18 | 19 | if (IsAncestorTill(hitTest as FrameworkElement, element, parent)) 20 | { 21 | return width; 22 | } 23 | 24 | //BinarySearch here 25 | int end = (int) Math.Floor(element.ActualWidth); 26 | int start = 0; 27 | 28 | while (start < end) 29 | { 30 | width = (end + start)/2; 31 | hitTest = parent.InputHitTest(new Point(location.X + width, location.Y)); 32 | 33 | if (IsAncestorTill(hitTest as FrameworkElement, element, parent)) 34 | { 35 | //Speed tweak 36 | hitTest = parent.InputHitTest(new Point(location.X + width + 1, location.Y)); 37 | 38 | if (IsAncestorTill(hitTest as FrameworkElement, element, parent)) 39 | { 40 | start = width; 41 | } 42 | else 43 | { 44 | return width; 45 | } 46 | } 47 | else 48 | { 49 | end = width; 50 | } 51 | } 52 | 53 | 54 | //for (int width = (int) Math.Floor(element.ActualWidth); width >= 0; width--) 55 | //{ 56 | // var hitTest = parent.InputHitTest(new Point(location.X + width, location.Y)); 57 | // 58 | // if (hitTest == null) continue; 59 | // 60 | // if (IsAncestorTill(hitTest as FrameworkElement, element, parent)) 61 | // { 62 | // return width; 63 | // } 64 | //} 65 | 66 | return element.ActualWidth; 67 | } 68 | 69 | private static bool IsAncestorTill(FrameworkElement element, object ancestor, object container) 70 | { 71 | if (element == null) return false; 72 | 73 | FrameworkElement parent = element; 74 | 75 | do 76 | { 77 | if (ReferenceEquals(parent, ancestor)) return true; 78 | if (ReferenceEquals(parent, container)) return false; 79 | } while ((parent = (parent.Parent ?? VisualTreeHelper.GetParent(parent)) as FrameworkElement) != null); 80 | 81 | return false; 82 | } 83 | 84 | public static Visual FindMainTreeVisual(Visual visual) 85 | { 86 | DependencyObject root = null; 87 | DependencyObject dependencyObject = visual; 88 | 89 | while (dependencyObject != null) 90 | { 91 | root = dependencyObject; 92 | dependencyObject = VisualTreeHelper.GetParent(dependencyObject); 93 | } 94 | 95 | return root as Visual; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/TreeViewAssist.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using System.Windows; 5 | using System.Windows.Controls; 6 | using System.Windows.Markup; 7 | 8 | namespace MaterialDesignThemes.Wpf 9 | { 10 | public static class TreeViewAssist 11 | { 12 | /// 13 | /// Allows additional rendering for each tree node, outside of the rippled part of the node which responsds to user selection. 14 | /// 15 | /// 16 | /// The content to be rendered is the same of the ; i.e the Header property, or 17 | /// some other content such as a view model, typically when using a . 18 | /// 19 | public static readonly DependencyProperty AdditionalTemplateProperty = DependencyProperty.RegisterAttached( 20 | "AdditionalTemplate", 21 | typeof(DataTemplate), 22 | typeof(TreeViewAssist), 23 | new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits)); 24 | 25 | /// 26 | /// Sets the additional template. 27 | /// 28 | /// The element. 29 | /// The value. 30 | public static void SetAdditionalTemplate(DependencyObject element, DataTemplate value) 31 | { 32 | element.SetValue(AdditionalTemplateProperty, value); 33 | } 34 | 35 | /// 36 | /// Gets the additional template. 37 | /// 38 | /// The element. 39 | /// 40 | /// The . 41 | /// 42 | public static DataTemplate GetAdditionalTemplate(DependencyObject element) 43 | { 44 | return (DataTemplate)element.GetValue(AdditionalTemplateProperty); 45 | } 46 | 47 | /// 48 | /// Allows additional rendering for each tree node, outside of the rippled part of the node which responsds to user selection. 49 | /// 50 | /// 51 | /// The content to be rendered is the same of the ; i.e the Header property, or 52 | /// some other content such as a view model, typically when using a . 53 | /// 54 | public static readonly DependencyProperty AdditionalTemplateSelectorProperty = DependencyProperty.RegisterAttached( 55 | "AdditionalTemplateSelector", 56 | typeof(DataTemplateSelector), 57 | typeof(TreeViewAssist), 58 | new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits)); 59 | 60 | /// 61 | /// Sets the additional template selector. 62 | /// 63 | /// The element. 64 | /// The value. 65 | public static void SetAdditionalTemplateSelector(DependencyObject element, DataTemplateSelector value) 66 | { 67 | element.SetValue(AdditionalTemplateSelectorProperty, value); 68 | } 69 | 70 | /// 71 | /// Gets the additional template selector. 72 | /// 73 | /// The element. 74 | /// 75 | /// The . 76 | /// 77 | public static DataTemplateSelector GetAdditionalTemplateSelector(DependencyObject element) 78 | { 79 | return (DataTemplateSelector)element.GetValue(AdditionalTemplateSelectorProperty); 80 | } 81 | 82 | private static readonly Lazy NoAdditionalTemplateProvider = new Lazy(CreateEmptyGridDataTemplate); 83 | 84 | /// 85 | /// To be used at level, or to be returned by 86 | /// implementors when the additional template associated with a tree should not be used. 87 | /// 88 | public static readonly DataTemplate SuppressAdditionalTemplate = NoAdditionalTemplateProvider.Value; 89 | 90 | public static DataTemplate CreateEmptyGridDataTemplate() 91 | { 92 | var xaml = ""; 93 | var parserContext = new ParserContext(); 94 | parserContext.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation"); 95 | parserContext.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml"); 96 | 97 | using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(xaml))) 98 | { 99 | return (DataTemplate)XamlReader.Load(memoryStream, parserContext); 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/Underline.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | using MaterialDesignThemes.Wpf.Transitions; 4 | 5 | namespace MaterialDesignThemes.Wpf 6 | { 7 | /// 8 | /// 9 | /// 10 | [TemplateVisualState(GroupName="ActivationStates", Name = ActiveStateName)] 11 | [TemplateVisualState(GroupName = "ActivationStates", Name = InactiveStateName)] 12 | public class Underline : Control 13 | { 14 | public const string ActiveStateName = "Active"; 15 | public const string InactiveStateName = "Inactive"; 16 | 17 | static Underline() 18 | { 19 | DefaultStyleKeyProperty.OverrideMetadata(typeof(Underline), new FrameworkPropertyMetadata(typeof(Underline))); 20 | } 21 | 22 | public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register( 23 | nameof(IsActive), typeof(bool), typeof(Underline), 24 | new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender, IsActivePropertyChangedCallback)); 25 | 26 | private static void IsActivePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) 27 | { 28 | ((Underline)dependencyObject).GotoVisualState(!TransitionAssist.GetDisableTransitions(dependencyObject)); 29 | } 30 | 31 | public bool IsActive 32 | { 33 | get { return (bool)GetValue(IsActiveProperty); } 34 | set { SetValue(IsActiveProperty, value); } 35 | } 36 | 37 | public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register( 38 | nameof(CornerRadius), typeof(CornerRadius), typeof(Underline), 39 | new FrameworkPropertyMetadata(new CornerRadius(0), FrameworkPropertyMetadataOptions.AffectsRender, null)); 40 | 41 | public CornerRadius CornerRadius 42 | { 43 | get { return (CornerRadius)GetValue(CornerRadiusProperty); } 44 | set { SetValue(CornerRadiusProperty, value); } 45 | } 46 | 47 | public override void OnApplyTemplate() 48 | { 49 | base.OnApplyTemplate(); 50 | 51 | GotoVisualState(false); 52 | } 53 | 54 | private void GotoVisualState(bool useTransitions) 55 | { 56 | VisualStateManager.GoToState(this, SelectStateName(), useTransitions); 57 | } 58 | 59 | private string SelectStateName() 60 | { 61 | return IsActive ? ActiveStateName : InactiveStateName; 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /packages/MaterialDesignThemes.2.5.1/src/net45/ValidationAssist.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls.Primitives; 3 | using System.Windows.Media; 4 | 5 | namespace MaterialDesignThemes.Wpf 6 | { 7 | public static class ValidationAssist 8 | { 9 | #region ShowOnFocusProperty 10 | 11 | /// 12 | /// The hint property 13 | /// 14 | public static readonly DependencyProperty OnlyShowOnFocusProperty = DependencyProperty.RegisterAttached( 15 | "OnlyShowOnFocus", 16 | typeof(bool), 17 | typeof(ValidationAssist), 18 | new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits)); 19 | 20 | public static bool GetOnlyShowOnFocus(DependencyObject element) 21 | { 22 | return (bool)element.GetValue(OnlyShowOnFocusProperty); 23 | } 24 | 25 | public static void SetOnlyShowOnFocus(DependencyObject element, bool value) 26 | { 27 | element.SetValue(OnlyShowOnFocusProperty, value); 28 | } 29 | 30 | #endregion 31 | 32 | #region UsePopupProperty 33 | 34 | /// 35 | /// The hint property 36 | /// 37 | public static readonly DependencyProperty UsePopupProperty = DependencyProperty.RegisterAttached( 38 | "UsePopup", 39 | typeof(bool), 40 | typeof(ValidationAssist), 41 | new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits)); 42 | 43 | public static bool GetUsePopup(DependencyObject element) 44 | { 45 | return (bool)element.GetValue(UsePopupProperty); 46 | } 47 | 48 | public static void SetUsePopup(DependencyObject element, bool value) 49 | { 50 | element.SetValue(UsePopupProperty, value); 51 | } 52 | 53 | #endregion 54 | 55 | /// 56 | /// The hint property 57 | /// 58 | public static readonly DependencyProperty PopupPlacementProperty = DependencyProperty.RegisterAttached( 59 | "PopupPlacement", 60 | typeof(PlacementMode), 61 | typeof(ValidationAssist), 62 | new FrameworkPropertyMetadata(PlacementMode.Bottom, FrameworkPropertyMetadataOptions.Inherits)); 63 | 64 | public static PlacementMode GetPopupPlacement(DependencyObject element) 65 | { 66 | return (PlacementMode)element.GetValue(UsePopupProperty); 67 | } 68 | 69 | public static void SetPopupPlacement(DependencyObject element, PlacementMode value) 70 | { 71 | element.SetValue(UsePopupProperty, value); 72 | } 73 | 74 | /// 75 | /// Framework use only. 76 | /// 77 | public static readonly DependencyProperty SuppressProperty = DependencyProperty.RegisterAttached( 78 | "Suppress", typeof (bool), typeof (ValidationAssist), new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.Inherits)); 79 | 80 | /// 81 | /// Framework use only. 82 | /// 83 | /// 84 | /// 85 | public static void SetSuppress(DependencyObject element, bool value) 86 | { 87 | element.SetValue(SuppressProperty, value); 88 | } 89 | 90 | /// 91 | /// Framework use only. 92 | /// 93 | public static bool GetSuppress(DependencyObject element) 94 | { 95 | return (bool) element.GetValue(SuppressProperty); 96 | } 97 | 98 | public static readonly DependencyProperty BackgroundProperty = DependencyProperty.RegisterAttached( 99 | "Background", typeof(Brush), typeof(ValidationAssist), new PropertyMetadata(default(Brush))); 100 | 101 | public static void SetBackground(DependencyObject element, Brush value) 102 | { 103 | element.SetValue(BackgroundProperty, value); 104 | } 105 | 106 | public static Brush GetBackground(DependencyObject element) 107 | { 108 | return (Brush) element.GetValue(BackgroundProperty); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/packages/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxwl3sxl/AnyExeToService/3e0617e7affdfbb1108acb9fab2bf8b59f1e2bbd/packages/log4net.dll --------------------------------------------------------------------------------