├── .gitignore ├── License.md ├── Readme.md ├── SyncArrow_64x.png ├── appveyor.yml └── source ├── CleanAll.bat ├── Demo ├── MLibTest │ └── Components │ │ ├── ServiceLocator │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── ServiceContainer.cs │ │ └── ServiceLocator.csproj │ │ └── Settings │ │ ├── Settings │ │ ├── Interfaces │ │ │ ├── IOptions.cs │ │ │ ├── IOptionsPanel.cs │ │ │ ├── IProfile.cs │ │ │ ├── ISettingsManager.cs │ │ │ └── IViewPosSizeModel.cs │ │ ├── Internal │ │ │ └── SettingsManagerImpl.cs │ │ ├── ProgramSettings │ │ │ ├── LanguageCollection.cs │ │ │ └── OptionsPanel.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── SerializableDictionary.cs │ │ ├── Settings.csproj │ │ ├── SettingsManager.cs │ │ ├── UserProfile │ │ │ ├── IViewSize.cs │ │ │ ├── LocalizabilityAttribute.cs │ │ │ ├── Profile.cs │ │ │ ├── ViewPosSizeModel.cs │ │ │ └── ViewSize.cs │ │ └── packages.config │ │ └── SettingsModel │ │ ├── ExtensionMethods │ │ └── SecureStringExtensionMethod.cs │ │ ├── Interfaces │ │ ├── IEngine.cs │ │ ├── IOptionGroup.cs │ │ └── IOptionsSchema.cs │ │ ├── Models │ │ ├── Engine.cs │ │ ├── Factory.cs │ │ ├── FileReference.cs │ │ ├── OptionGroup.cs │ │ ├── OptionsSchema.cs │ │ └── XML │ │ │ ├── Converters │ │ │ ├── AlternativeDataTypeHandler.cs │ │ │ ├── IAlternativeDataTypeHandler.cs │ │ │ └── SecureStringHandler.cs │ │ │ └── XMLLayer.cs │ │ ├── Overview.cd │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── SettingsModel.csproj │ │ └── packages.config └── UpDownDemoLib │ ├── Converters │ ├── BoolToVisibilityConverter.cs │ └── EnumMatchToBooleanConverter.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── UpDownDemoLib.csproj │ ├── ViewModels │ ├── Base │ │ └── ViewModelBase.cs │ ├── BaseUpDownViewModel.cs │ ├── ByteUpDownViewModel.cs │ ├── DecimalUpDownViewModel.cs │ ├── DemoViewModel.cs │ ├── DoubleUpDownViewModel.cs │ ├── FloatUpDownViewModel.cs │ ├── IntegerUpDownViewModel.cs │ ├── LongUpDownViewModel.cs │ ├── SByteUpDownViewModel.cs │ ├── ShortUpDownViewModel.cs │ ├── UIntegerUpDownViewModel.cs │ ├── ULongUpDownViewModel.cs │ └── UShortUpDownViewModel.cs │ └── Views │ ├── ByteUpDownDemo.xaml │ ├── ByteUpDownDemo.xaml.cs │ ├── DecimalUpDownDemo.xaml │ ├── DecimalUpDownDemo.xaml.cs │ ├── DoubleUpDownDemo.xaml │ ├── DoubleUpDownDemo.xaml.cs │ ├── FloatUpDownDemo.xaml │ ├── FloatUpDownDemo.xaml.cs │ ├── LongUpDownDemo.xaml │ ├── LongUpDownDemo.xaml.cs │ ├── NumericUpDownDemo.xaml │ ├── NumericUpDownDemo.xaml.cs │ ├── PercentageUpDownDemo.xaml │ ├── PercentageUpDownDemo.xaml.cs │ ├── SByteUpDownDemo.xaml │ ├── SByteUpDownDemo.xaml.cs │ ├── ShortUpDownDemo.xaml │ ├── ShortUpDownDemo.xaml.cs │ ├── UIntegerUpDownDemo.xaml │ ├── UIntegerUpDownDemo.xaml.cs │ ├── ULongUpDownDemo.xaml │ ├── ULongUpDownDemo.xaml.cs │ ├── UShortUpDownDemo.xaml │ └── UShortUpDownDemo.xaml.cs ├── NUnitTestProject ├── ByteTests.cs ├── DecimalTests.cs ├── DoubleTests.cs ├── FloatTests.cs ├── LongTests.cs ├── NUnitTestProject.csproj ├── NumericTests.cs ├── SbyteTests.cs ├── ShortTests.cs ├── UIntegerTests.cs ├── ULongTests.cs └── UShortTests.cs ├── NumericUpDown.sln ├── NumericUpDownLib ├── AssemblyInfo.cs ├── Base │ ├── AbstractBaseUpDown.cs │ ├── ClassDiagram1.cd │ ├── InputBaseUpDown.xaml │ ├── InputBaseUpDown.xaml.cs │ ├── NumericRepeatButtonControl.xaml │ └── NumericRepeatButtonControl.xaml.cs ├── ByteUpDown.cs ├── Converters │ ├── BoolToVisibilityPropConverter.cs │ ├── ByteToPlaceHolderStringConverter.cs │ └── FactorToDoubleConverter.cs ├── DecimalUpDown.cs ├── DoubleUpDown.cs ├── Enums │ └── CanIncDecMouseDrag.cs ├── FloatUpDown.cs ├── LongUpDown.cs ├── Models │ ├── MouseDirections.cs │ └── MouseIncrementor.cs ├── NumericUpDown.cs ├── NumericUpDownLib.csproj ├── NumericUpDownLib.csproj.user ├── SByteUpDown.cs ├── ShortUpDown.cs ├── Themes │ ├── DarkBrushs.xaml │ ├── Generic.xaml │ ├── LightBrushs.xaml │ └── ResourceKeys.cs ├── UIntegerUpDown.cs ├── ULongUpDown.cs ├── UShortUpDown.cs └── images │ └── SyncArrow_64x.png ├── TestGenerics ├── App.config ├── App.xaml ├── App.xaml.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── TestGenerics.csproj └── ViewModels │ ├── Base │ └── ViewModelBase.cs │ └── DemoViewModel.cs └── TestThemes ├── App.config ├── App.xaml ├── App.xaml.cs ├── AppLocalResources.xaml ├── Behaviors └── SelectionChangedBehavior.cs ├── BindToMLib ├── MWindowLib │ └── DarkLightBrushs.xaml └── NumericUpDownLib │ └── DarkLightBrushs.xaml ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Models ├── AppCore.cs └── SettingDefaults.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── ServiceInjector.cs ├── TestThemes.csproj ├── ViewModels ├── AppLifeCycleViewModel.cs ├── AppViewModel.cs ├── Base │ ├── ModelBase.cs │ ├── RelayCommand.cs │ └── ViewModelBase.cs ├── ThemeDefinitionViewModel.cs └── ThemeViewModel.cs └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | 00_Release/ 3 | 01_Nuget/ 4 | debug/ 5 | release/ 6 | build/ 7 | bin/ 8 | obj/ 9 | cache/ 10 | log/ 11 | tmp/ 12 | 13 | *~ 14 | *.lock 15 | *.DS_Store 16 | *.swp 17 | *.out 18 | *.sou 19 | *.suo 20 | *.sqlite 21 | /source/packages 22 | -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2014-2017 Dirk Bahle 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 | -------------------------------------------------------------------------------- /SyncArrow_64x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dirkster99/NumericUpDownLib/0dd9bd8e569736f0192107cfaadd340a7e0aa90e/SyncArrow_64x.png -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 2.4.{build} 2 | 3 | configuration: Release 4 | 5 | platform: Any CPU 6 | 7 | image: Visual Studio 2019 Preview 8 | 9 | install: 10 | - cmd: choco install dotnetcore-sdk --pre 11 | 12 | before_build: 13 | - cmd: nuget restore source/NumericUpDown.sln 14 | 15 | build: 16 | 17 | verbosity: minimal 18 | 19 | artifacts: 20 | 21 | - path: source\TestGenerics\bin\Release 22 | name: TestGenerics 23 | 24 | - path: source\TestThemes\bin\Release 25 | name: TestThemes 26 | 27 | - path: source\NumericUpDownLib\bin\Release 28 | name: NumericUpDownLib 29 | -------------------------------------------------------------------------------- /source/CleanAll.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | pushd "%~dp0" 3 | ECHO. 4 | ECHO. 5 | ECHO. 6 | ECHO This script deletes all temporary build files in their 7 | ECHO corresponding BIN and OBJ Folder contained in the following projects 8 | ECHO. 9 | ECHO TestThemes 10 | ECHO TestGenerics 11 | ECHO NumericUpDownLib 12 | ECHO Demo\UpDownDemoLib 13 | ECHO Demo\MLibTest\Components\ServiceLocator 14 | ECHO Demo\MLibTest\Components\Settings\Settings 15 | ECHO Demo\MLibTest\Components\Settings\SettingsModel 16 | ECHO. 17 | REM Ask the user if hes really sure to continue beyond this point XXXXXXXX 18 | set /p choice=Are you sure to continue (Y/N)? 19 | if not '%choice%'=='Y' Goto EndOfBatch 20 | REM Script does not continue unless user types 'Y' in upper case letter 21 | ECHO. 22 | ECHO XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 23 | ECHO. 24 | ECHO XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 25 | ECHO. 26 | ECHO Deleting BIN and OBJ Folders in NumericUpDownLib 27 | ECHO. 28 | RMDIR /S /Q .\NumericUpDownLib\bin 29 | RMDIR /S /Q .\NumericUpDownLib\obj 30 | ECHO. 31 | ECHO Deleting BIN and OBJ Folders in TestThemes 32 | ECHO. 33 | RMDIR /S /Q .\TestThemes\bin 34 | RMDIR /S /Q .\TestThemes\obj 35 | ECHO. 36 | ECHO Deleting BIN and OBJ Folders in TestGenerics 37 | ECHO. 38 | RMDIR /S /Q .\TestGenerics\bin 39 | RMDIR /S /Q .\TestGenerics\obj 40 | ECHO. 41 | 42 | ECHO. 43 | ECHO Deleting BIN and OBJ Folders in UpDownDemoLib 44 | ECHO. 45 | RMDIR /S /Q .\.vs 46 | RMDIR /S /Q .\Demo\UpDownDemoLib\bin 47 | RMDIR /S /Q .\Demo\UpDownDemoLib\obj 48 | 49 | ECHO. 50 | ECHO Deleting BIN and OBJ Folders in Demo\MLibTest\Components\ServiceLocator 51 | ECHO. 52 | RMDIR /S /Q .\.vs 53 | RMDIR /S /Q .\Demo\MLibTest\Components\ServiceLocator\bin 54 | RMDIR /S /Q .\Demo\MLibTest\Components\ServiceLocator\obj 55 | 56 | ECHO. 57 | ECHO Deleting BIN and OBJ Folders in Demo\MLibTest\Components\Settings\Settings 58 | ECHO. 59 | RMDIR /S /Q .\.vs 60 | RMDIR /S /Q .\Demo\MLibTest\Components\Settings\Settings\bin 61 | RMDIR /S /Q .\Demo\MLibTest\Components\Settings\Settings\obj 62 | 63 | ECHO. 64 | ECHO Deleting BIN and OBJ Folders in Demo\MLibTest\Components\Settings\SettingsModel 65 | ECHO. 66 | RMDIR /S /Q .\.vs 67 | RMDIR /S /Q .\Demo\MLibTest\Components\Settings\SettingsModel\bin 68 | RMDIR /S /Q .\Demo\MLibTest\Components\Settings\SettingsModel\obj 69 | 70 | PAUSE 71 | 72 | :EndOfBatch 73 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/ServiceLocator/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ServiceLocator")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HP")] 12 | [assembly: AssemblyProduct("ServiceLocator")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2516097b-2435-44a4-a9b8-9899bca81a6e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/ServiceLocator/ServiceContainer.cs: -------------------------------------------------------------------------------- 1 | namespace ServiceLocator 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | /// 7 | /// Source: http://www.codeproject.com/Articles/70223/Using-a-Service-Locator-to-Work-with-MessageBoxes 8 | /// 9 | public class ServiceContainer 10 | { 11 | #region fields 12 | public static readonly ServiceContainer Instance = new ServiceContainer(); 13 | 14 | readonly Dictionary _serviceMap; 15 | readonly object _serviceMapLock; 16 | #endregion fields 17 | 18 | #region constructors 19 | /// 20 | /// Class Constructor 21 | /// 22 | private ServiceContainer() 23 | { 24 | _serviceMap = new Dictionary(); 25 | _serviceMapLock = new object(); 26 | } 27 | #endregion constructors 28 | 29 | #region methods 30 | public void AddService(TServiceContract implementation) 31 | where TServiceContract : class 32 | { 33 | lock (_serviceMapLock) 34 | { 35 | _serviceMap[typeof(TServiceContract)] = implementation; 36 | } 37 | } 38 | 39 | public TServiceContract GetService() 40 | where TServiceContract : class 41 | { 42 | object service; 43 | lock (_serviceMapLock) 44 | { 45 | _serviceMap.TryGetValue(typeof(TServiceContract), out service); 46 | } 47 | 48 | return service as TServiceContract; 49 | } 50 | #endregion methods 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/ServiceLocator/ServiceLocator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {252126D1-E1D9-49C3-910B-FCF2266265EF} 8 | Library 9 | Properties 10 | ServiceLocator 11 | ServiceLocator 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | true 34 | bin\x64\Debug\ 35 | DEBUG;TRACE 36 | full 37 | x64 38 | prompt 39 | MinimumRecommendedRules.ruleset 40 | 41 | 42 | bin\x64\Release\ 43 | TRACE 44 | true 45 | pdbonly 46 | x64 47 | prompt 48 | MinimumRecommendedRules.ruleset 49 | 50 | 51 | true 52 | bin\x86\Debug\ 53 | DEBUG;TRACE 54 | full 55 | x86 56 | prompt 57 | MinimumRecommendedRules.ruleset 58 | 59 | 60 | bin\x86\Release\ 61 | TRACE 62 | true 63 | pdbonly 64 | x86 65 | prompt 66 | MinimumRecommendedRules.ruleset 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 87 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/Interfaces/IOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Settings.Interfaces 2 | { 3 | using Settings.ProgramSettings; 4 | using System.Collections.Generic; 5 | 6 | public interface IOptions 7 | { 8 | #region properties 9 | bool IsDirty { get; set; } 10 | string LanguageSelected { get; set; } 11 | bool ReloadOpenFilesOnAppStart { get; set; } 12 | string SourceFilePath { get; set; } 13 | 14 | string DefaultSourceLanguage { get; set; } 15 | string DefaultTargetLanguage { get; set; } 16 | 17 | string DefaultDefaultSourceLanguage { get; } 18 | string DefaultDefaultTargetLanguage { get; } 19 | 20 | int DefaultIconSize { get; } 21 | int IconSizeMin { get; } 22 | int IconSizeMax { get; } 23 | 24 | int DefaultFontSize { get; } 25 | int FontSizeMin { get; } 26 | int FontSizeMax { get; } 27 | #endregion properties 28 | 29 | #region methods 30 | /// 31 | /// Reset the dirty flag (e.g. after saving program options when they where edit). 32 | /// 33 | /// 34 | void SetDirtyFlag(bool flag); 35 | 36 | void SetIconSize(int size); 37 | void SetFontSize(int size); 38 | #endregion methods 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/Interfaces/IOptionsPanel.cs: -------------------------------------------------------------------------------- 1 | namespace Settings.Interfaces 2 | { 3 | using SettingsModel.Interfaces; 4 | 5 | public interface IOptionsPanel 6 | { 7 | IEngine Options { get; } 8 | } 9 | } -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/Interfaces/IProfile.cs: -------------------------------------------------------------------------------- 1 | namespace Settings.Interfaces 2 | { 3 | using Settings.UserProfile; 4 | using SettingsModel.Models; 5 | using System; 6 | using System.Collections.Generic; 7 | 8 | public interface IProfile 9 | { 10 | #region properties 11 | string GetLastActivePath(); 12 | string LastActiveSolution { get; set; } 13 | 14 | 15 | string LastActiveTargetFile { get; set; } 16 | 17 | List LastActiveSourceFiles { get; set; } 18 | 19 | /// 20 | /// Gets the key name of the MainWindow item in the collection. 21 | /// Ths name can be used as key in the WindowPosSz property 22 | /// to read and write MainWindow position and size information. 23 | /// 24 | string MainWindowName { get; } 25 | 26 | /// 27 | /// Gets a collection of window position and size items. 28 | /// 29 | SerializableDictionary WindowPosSz { get; } 30 | #endregion properties 31 | 32 | #region methods 33 | /// 34 | /// Checks the MainWindow for visibility when re-starting application 35 | /// (with different screen configuration). 36 | /// 37 | /// 38 | /// 39 | void CheckSettingsOnLoad(double SystemParameters_VirtualScreenLeft, double SystemParameters_VirtualScreenTop); 40 | 41 | /// 42 | /// Updates or inserts the requested window pos size item in the collection. 43 | /// 44 | /// 45 | /// 46 | /// 47 | void UpdateInsertWindowPosSize(string windowName, ViewPosSizeModel model); 48 | #endregion methods 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/Interfaces/ISettingsManager.cs: -------------------------------------------------------------------------------- 1 | namespace Settings.Interfaces 2 | { 3 | using Settings.ProgramSettings; 4 | using MLib.Interfaces; 5 | using System.Collections.Generic; 6 | using System.Xml.Serialization; 7 | 8 | public interface ISettingsManager : IOptionsPanel 9 | { 10 | void CheckSettingsOnLoad(double SystemParameters_VirtualScreenLeft, double SystemParameters_VirtualScreenTop); 11 | 12 | ////void LoadOptions(string settingsFileName); 13 | void LoadSessionData(string sessionDataFileName); 14 | 15 | ////bool SaveOptions(string settingsFileName, Settings.Interfaces.IOptions optionsModel); 16 | bool SaveSessionData(string sessionDataFileName, Settings.Interfaces.IProfile model); 17 | 18 | /// 19 | /// Get a list of all supported languages in Edi. 20 | /// 21 | /// 22 | IEnumerable GetSupportedLanguages(); 23 | 24 | #region properties 25 | Settings.Interfaces.IProfile SessionData { get; } 26 | 27 | int IconSizeMin { get; } 28 | int IconSizeMax { get; } 29 | 30 | int FontSizeMin { get; } 31 | int FontSizeMax { get; } 32 | 33 | /// 34 | /// Gets the default icon size for the application. 35 | /// 36 | int DefaultIconSize { get; } 37 | 38 | /// 39 | /// Gets the default font size for the application. 40 | /// 41 | int DefaultFontSize { get; } 42 | 43 | /// 44 | /// Gets the default fixed font size for the application. 45 | /// 46 | int DefaultFixedFontSize { get; } 47 | 48 | /// 49 | /// Gets the internal name and Uri source for all available themes. 50 | /// 51 | [XmlIgnore] 52 | IThemeInfos Themes { get; } 53 | #endregion properties 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/Interfaces/IViewPosSizeModel.cs: -------------------------------------------------------------------------------- 1 | namespace Settings.Interfaces 2 | { 3 | using System; 4 | 5 | public interface IViewPosSizeModel 6 | { 7 | bool DefaultConstruct { get; } 8 | double Height { get; set; } 9 | bool IsMaximized { get; set; } 10 | double Width { get; set; } 11 | double X { get; set; } 12 | double Y { get; set; } 13 | 14 | void SetValidPos(double SystemParameters_VirtualScreenLeft, double SystemParameters_VirtualScreenTop); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/ProgramSettings/LanguageCollection.cs: -------------------------------------------------------------------------------- 1 | namespace Settings.ProgramSettings 2 | { 3 | using System; 4 | 5 | /// 6 | /// Base class for enumeration over languages (and their locale) that 7 | /// are supported with specific (non-English) button and tool tip strings. 8 | /// 9 | /// The class definition is based on BCP 47 which in turn is used to 10 | /// set the UI and thread culture (which in turn selects the correct 11 | /// string resource in MsgBox assembly). 12 | /// 13 | public class LanguageCollection 14 | { 15 | public string Language { get; set; } 16 | public string Locale { get; set; } 17 | public string Name { get; set; } 18 | 19 | /// 20 | /// Get BCP47 language tag for this language 21 | /// See also http://en.wikipedia.org/wiki/IETF_language_tag 22 | /// 23 | public string BCP47 24 | { 25 | get 26 | { 27 | if (string.IsNullOrEmpty(Locale) == false) 28 | return String.Format("{0}-{1}", Language, Locale); 29 | else 30 | return String.Format("{0}", Language); 31 | } 32 | } 33 | 34 | /// 35 | /// Get BCP47 language tag for this language 36 | /// See also http://en.wikipedia.org/wiki/IETF_language_tag 37 | /// 38 | public string DisplayName 39 | { 40 | get 41 | { 42 | return String.Format("{0} {1}", Name, BCP47); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/ProgramSettings/OptionsPanel.cs: -------------------------------------------------------------------------------- 1 | namespace Settings.ProgramSettings 2 | { 3 | using Settings.Interfaces; 4 | using SettingsModel.Interfaces; 5 | using SettingsModel.Models; 6 | 7 | internal class OptionsPanel : IOptionsPanel 8 | { 9 | private IEngine mQuery = null; 10 | 11 | public OptionsPanel() 12 | { 13 | mQuery = Factory.CreateEngine(); 14 | } 15 | 16 | /// 17 | /// Gets the options that used to manage program options. 18 | /// 19 | public IEngine Options 20 | { 21 | get 22 | { 23 | return mQuery; 24 | } 25 | 26 | private set 27 | { 28 | mQuery = value; 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Settings")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HP")] 12 | [assembly: AssemblyProduct("Settings")] 13 | [assembly: AssemblyCopyright("The MIT License (MIT) Copyright © 2013 - 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7f13f2b5-a017-4045-8ead-f5496101a616")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/SerializableDictionary.cs: -------------------------------------------------------------------------------- 1 | namespace Settings 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Globalization; 6 | using System.Runtime.Serialization; 7 | using System.Xml; 8 | using System.Xml.Serialization; 9 | 10 | /// 11 | /// This class represents a serializable dictionary implementation 12 | /// of the standard generic dictionary class in .Net. 13 | /// 14 | /// Source: http://www.jankowskimichal.pl/en/2010/10/serializabledictionary/ 15 | /// 16 | [Serializable] 17 | public class SerializableDictionary : Dictionary, IXmlSerializable, ISerializable 18 | { 19 | #region Private Members 20 | private XmlSerializer _keySerializer; 21 | private XmlSerializer _valueSerializer; 22 | #endregion 23 | 24 | #region Constructors 25 | public SerializableDictionary() 26 | { 27 | } 28 | 29 | public SerializableDictionary(IDictionary dictionary) 30 | : base(dictionary) 31 | { 32 | } 33 | 34 | public SerializableDictionary(IEqualityComparer comparer) 35 | : base(comparer) 36 | { 37 | } 38 | 39 | public SerializableDictionary(int capacity) 40 | : base(capacity) 41 | { 42 | } 43 | 44 | public SerializableDictionary(IDictionary dictionary, IEqualityComparer comparer) 45 | : base(dictionary, comparer) 46 | { 47 | } 48 | 49 | public SerializableDictionary(int capacity, IEqualityComparer comparer) 50 | : base(capacity, comparer) 51 | { 52 | } 53 | 54 | #endregion 55 | 56 | #region Private Properties 57 | protected XmlSerializer ValueSerializer 58 | { 59 | get { return _valueSerializer ?? (_valueSerializer = new XmlSerializer(typeof(TVal))); } 60 | } 61 | 62 | private XmlSerializer KeySerializer 63 | { 64 | get { return _keySerializer ?? (_keySerializer = new XmlSerializer(typeof(TKey))); } 65 | } 66 | #endregion 67 | 68 | #region ISerializable Members 69 | protected SerializableDictionary(SerializationInfo info, StreamingContext context) 70 | { 71 | int itemCount = info.GetInt32("itemsCount"); 72 | for (int i = 0; i < itemCount; i++) 73 | { 74 | KeyValuePair kvp = (KeyValuePair)info.GetValue(String.Format(CultureInfo.InvariantCulture, "Item{0}", i), typeof(KeyValuePair)); 75 | Add(kvp.Key, kvp.Value); 76 | } 77 | } 78 | 79 | void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) 80 | { 81 | info.AddValue("itemsCount", Count); 82 | int itemIdx = 0; 83 | foreach (KeyValuePair kvp in this) 84 | { 85 | info.AddValue(String.Format(CultureInfo.InvariantCulture, "Item{0}", itemIdx), kvp, typeof(KeyValuePair)); 86 | itemIdx++; 87 | } 88 | } 89 | #endregion 90 | 91 | #region IXmlSerializable Members 92 | void IXmlSerializable.WriteXml(XmlWriter writer) 93 | { 94 | foreach (KeyValuePair kvp in this) 95 | { 96 | writer.WriteStartElement("item"); 97 | writer.WriteStartElement("key"); 98 | KeySerializer.Serialize(writer, kvp.Key); 99 | writer.WriteEndElement(); 100 | writer.WriteStartElement("value"); 101 | ValueSerializer.Serialize(writer, kvp.Value); 102 | writer.WriteEndElement(); 103 | writer.WriteEndElement(); 104 | } 105 | } 106 | 107 | void IXmlSerializable.ReadXml(XmlReader reader) 108 | { 109 | if (reader.IsEmptyElement) 110 | { 111 | return; 112 | } 113 | // Move past container 114 | if (reader.NodeType == XmlNodeType.Element && !reader.Read()) 115 | { 116 | throw new XmlException("Error in Deserialization of SerializableDictionary"); 117 | } 118 | while (reader.NodeType != XmlNodeType.EndElement) 119 | { 120 | reader.ReadStartElement("item"); 121 | reader.ReadStartElement("key"); 122 | TKey key = (TKey)KeySerializer.Deserialize(reader); 123 | reader.ReadEndElement(); 124 | reader.ReadStartElement("value"); 125 | TVal value = (TVal)ValueSerializer.Deserialize(reader); 126 | reader.ReadEndElement(); 127 | reader.ReadEndElement(); 128 | Add(key, value); 129 | reader.MoveToContent(); 130 | } 131 | // Move past container 132 | if (reader.NodeType == XmlNodeType.EndElement) 133 | { 134 | reader.ReadEndElement(); 135 | } 136 | else 137 | { 138 | throw new XmlException("Error in Deserialization of SerializableDictionary"); 139 | } 140 | } 141 | 142 | System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema() 143 | { 144 | return null; 145 | } 146 | #endregion 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/SettingsManager.cs: -------------------------------------------------------------------------------- 1 | namespace Settings 2 | { 3 | using MLib.Interfaces; 4 | using Settings.Interfaces; 5 | using Settings.Internal; 6 | 7 | /// 8 | /// Helper class to initialize an 9 | /// service interface. 10 | /// 11 | public sealed class SettingsManager 12 | { 13 | /// 14 | /// Hidden default constructor. 15 | /// 16 | private SettingsManager() 17 | { 18 | } 19 | 20 | /// 21 | /// Gets an instance of an object that implements the 22 | /// interface. 23 | /// 24 | /// 25 | public static ISettingsManager GetInstance(IThemeInfos themeInfos) 26 | { 27 | return new SettingsManagerImpl(themeInfos); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/UserProfile/IViewSize.cs: -------------------------------------------------------------------------------- 1 | namespace Settings.UserProfile 2 | { 3 | using System.Windows; 4 | 5 | /// 6 | /// Provide an interface to implement saving and loading/repositioning of Window or view. 7 | /// 8 | public interface IViewSize 9 | { 10 | // 11 | // Zusammenfassung: 12 | // Ruft die Position des linken Fensterrands im Verhältnis zum Desktop ab oder legt 13 | // diese fest. 14 | // 15 | // Rückgabewerte: 16 | // Die Position des linken Fensterrands in logischen Einheiten (1/96 Zoll). 17 | double Left { get; set; } 18 | 19 | // 20 | // Zusammenfassung: 21 | // Ruft die Position des oberen Fensterrands im Verhältnis zum Desktop ab oder legt 22 | // diese fest. 23 | // 24 | // Rückgabewerte: 25 | // Die Position des oberen Fensterrands in logischen Einheiten (1/96 "). 26 | double Top { get; set; } 27 | 28 | // 29 | // Zusammenfassung: 30 | // Ruft die Breite des Elements ab bzw. legt diese fest. 31 | // 32 | // Rückgabewerte: 33 | // Die Breite des Elements in geräteunabhängige Einheiten (1/96th inch per unit).Der 34 | // Standardwert ist System.Double.NaN.Dieser Wert muss größer oder gleich 0,0 sein.In 35 | // den Hinweisen finden Sie Informationen über obere Grenzen. 36 | double Width { get; set; } 37 | 38 | // 39 | // Zusammenfassung: 40 | // Ruft die vorgeschlagene Höhe des Elements ab oder legt diese fest. 41 | // 42 | // Rückgabewerte: 43 | // Die Höhe des Elements in geräteunabhängige Einheiten (1/96th inch per unit).Der 44 | // Standardwert ist System.Double.NaN.Dieser Wert muss größer oder gleich 0,0 sein.In 45 | // den Hinweisen finden Sie Informationen über obere Grenzen. 46 | double Height { get; set; } 47 | 48 | // 49 | // Zusammenfassung: 50 | // Ruft einen Wert ab, der angibt, ob ein Fenster wiederhergestellt, minimiert oder 51 | // maximiert ist, oder legt diesen fest. 52 | // 53 | // Rückgabewerte: 54 | // Ein System.Windows.WindowState, der bestimmt, ob ein Fenster wiederhergestellt, 55 | // minimiert oder maximiert ist.Der Standardwert ist System.Windows.WindowState.Normal 56 | // (wiederhergestellt). 57 | WindowState WindowState { get; set; } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/UserProfile/LocalizabilityAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Settings.UserProfile 4 | { 5 | internal class LocalizabilityAttribute : Attribute 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/UserProfile/ViewSize.cs: -------------------------------------------------------------------------------- 1 | namespace Settings.UserProfile 2 | { 3 | // 50, 50, 800, 550 4 | public class ViewSize 5 | { 6 | public ViewSize(double x, double y, double width, double height) 7 | { 8 | X = x; 9 | Y = y; 10 | Width = width; 11 | Height = height; 12 | } 13 | 14 | public double X { get; private set; } 15 | public double Y { get; private set; } 16 | public double Width { get; private set; } 17 | public double Height { get; private set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/Settings/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/SettingsModel/ExtensionMethods/SecureStringExtensionMethod.cs: -------------------------------------------------------------------------------- 1 | namespace SettingsModel.ExtensionMethods 2 | { 3 | using System; 4 | using System.Runtime.InteropServices; 5 | using System.Security; 6 | 7 | /// 8 | /// Source: http://blogs.msdn.com/b/fpintos/archive/2009/06/12/how-to-properly-convert-securestring-to-string.aspx 9 | /// 10 | internal static class SecureStringExtensionMethod 11 | { 12 | public static string ConvertToUnsecureString(this SecureString securePassword) 13 | { 14 | if (securePassword == null) 15 | throw new ArgumentNullException("securePassword"); 16 | 17 | IntPtr unmanagedString = IntPtr.Zero; 18 | try 19 | { 20 | unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword); 21 | return Marshal.PtrToStringUni(unmanagedString); 22 | } 23 | finally 24 | { 25 | Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString); 26 | } 27 | } 28 | 29 | public static SecureString ConvertToSecureString(this string password) 30 | { 31 | if (password == null) 32 | throw new ArgumentNullException("password"); 33 | 34 | var securePassword = new SecureString(); 35 | foreach (char c in password) 36 | securePassword.AppendChar(c); 37 | 38 | securePassword.MakeReadOnly(); 39 | return securePassword; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/SettingsModel/Interfaces/IOptionGroup.cs: -------------------------------------------------------------------------------- 1 | namespace SettingsModel.Interfaces 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | /// 7 | /// An option group is a logical group of options 8 | /// (setting values or preferences) of an application. 9 | /// 10 | public interface IOptionGroup 11 | { 12 | /// 13 | /// Gets the name of this options group. This name is used to 14 | /// cluster related options around a technically relevant name. 15 | /// 16 | string Name { get; } 17 | 18 | /// 19 | /// Retrieves the schema of each option in this optiongroup. 20 | /// 21 | /// 22 | IEnumerable GetOptionDefinitions(); 23 | 24 | /// 25 | /// Retrieves the schema of an option in this optiongroup. 26 | /// 27 | /// 28 | IOptionsSchema GetOptionDefinition(string optionName); 29 | 30 | /// 31 | /// Gets the value of an option in a given or null 32 | /// if either option or does not exist. 33 | /// 34 | /// Method returns false if option or are not known. 35 | /// 36 | /// 37 | /// Indicates whether option and exist or not. 38 | /// 39 | bool GetValue(string optionName, out object optValue); 40 | 41 | /// 42 | /// Gets the value of an option in a given or 43 | /// throws an exception if either option or 44 | /// does not exist. 45 | /// 46 | /// Method the requested option value if option and are known. 47 | /// 48 | /// 49 | /// 50 | object GetValue(string optionName); 51 | 52 | /// 53 | /// Gets the requested option and returns it as typed <T> value. 54 | /// The method throws an exception if: 55 | /// - requested option value is not stored as typed <T> or 56 | /// - the and option name does not exist. 57 | /// 58 | /// 59 | /// current value of this option. 60 | T GetValue(string optionName); 61 | 62 | /// 63 | /// Sets the value of a given option in this option table. 64 | /// 65 | /// 66 | /// 67 | /// 68 | bool SetValue(string optionName, object newValue); 69 | 70 | /// 71 | /// Add a list item in a list schema 72 | /// 73 | /// 74 | /// 75 | /// 76 | /// 77 | /// Returns true if item was succesfully added or false 78 | /// if schema is not a list schema. 79 | /// 80 | bool List_AddValue(string optionName, string keyName, object value); 81 | 82 | /// 83 | /// Clear all items contained in a list. 84 | /// 85 | /// 86 | /// 87 | bool List_Clear(string optionName); 88 | 89 | /// 90 | /// Create a new option that can hold a list of items. 91 | /// 92 | /// 93 | /// 94 | /// 95 | /// 96 | /// 97 | /// 98 | IOptionsSchema List_CreateOption(string optionName, Type type, bool isOptional, List list); 99 | 100 | /// 101 | /// Gets a list of current values if this schema descripes a List. 102 | /// Return a single value schema as a list of 1 item. 103 | /// 104 | /// 105 | /// 106 | IEnumerable List_GetListOfValues(string optionName); 107 | 108 | /// 109 | /// Gets a list of current keys and values if this schema 110 | /// descripes a List. 111 | /// 112 | /// Return a single value schema as a list of 1 item. 113 | /// 114 | /// 115 | /// 116 | IEnumerable> List_GetListOfKeyValues(string optionName); 117 | 118 | /// 119 | /// Resets the IsDirty flag to false to indicate that the current 120 | /// data was not changed/edited by a user request, yet. This is 121 | /// useful after defining a new options model and starting to work 122 | /// with it, as well, as after reading options from persistance... 123 | /// 124 | /// 125 | void SetUndirty(bool isDirty); 126 | } 127 | } -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/SettingsModel/Interfaces/IOptionsSchema.cs: -------------------------------------------------------------------------------- 1 | namespace SettingsModel.Interfaces 2 | { 3 | using SettingsModel.Models; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | /// 8 | /// Defines available schema information for 1 option. 9 | /// 10 | public interface IOptionsSchema 11 | { 12 | /// 13 | /// Gets the type of schema (list or single value) 14 | /// 15 | OptionSchemaType SchemaType { get; } 16 | 17 | /// 18 | /// Gets the name of an option. 19 | /// 20 | string OptionName { get; } 21 | 22 | /// 23 | /// Gets the type of the option being defined here. 24 | /// 25 | Type TypeOfValue { get; } 26 | 27 | /// 28 | /// Gets whether this options is optional or required. 29 | /// This is important when perisiting data and when reading 30 | /// data from persistance. 31 | /// 32 | bool IsOptional { get; } 33 | 34 | /// 35 | /// Gets the value of this option. 36 | /// 37 | object Value { get; } 38 | 39 | /// 40 | /// Gets/sets the default value of this option. 41 | /// 42 | object DefaultValue { get; } 43 | 44 | #region methods 45 | /// 46 | /// Removes the value with the specified key 47 | /// from the internal dictionary. 48 | /// 49 | /// The key of the element to remove. 50 | /// 51 | /// true if the element is successfully found and removed; otherwise, false. 52 | /// This method returns false if key is not found in 53 | /// the System.Collections.Generic.Dictionary<TKey,TValue>. 54 | /// 55 | /// Exceptions: 56 | /// System.ArgumentNullException: 57 | /// key is null. 58 | /// 59 | bool List_Remove(string key); 60 | 61 | /// 62 | /// Gets the value associated with the specified key. 63 | /// 64 | /// 65 | /// The key of the value to get. 66 | /// 67 | /// 68 | /// When this method returns, contains the value associated with the specified 69 | /// key, if the key is found; otherwise, the default value for the type of the 70 | /// value parameter. This parameter is passed uninitialized. 71 | /// 72 | /// 73 | /// true if the System.Collections.Generic.Dictionary<TKey,TValue> contains an 74 | /// element with the specified key; otherwise, false. 75 | /// 76 | /// Exceptions: 77 | /// System.ArgumentNullException: 78 | /// key is null. 79 | /// 80 | bool List_TryGetValue(string key, out object value); 81 | 82 | /// 83 | /// Sets the value of a given option in this option object. 84 | /// 85 | /// true if data actually changed (for dirty state tracking). 86 | /// Otherwise, false if requested value was already present. 87 | /// 88 | bool SetValue(object newValue); 89 | 90 | /// 91 | /// Add a list item in a list schema 92 | /// 93 | /// 94 | /// 95 | /// 96 | /// Returns true if item was succesfully added or false 97 | /// if schema is not a list schema. 98 | /// 99 | bool List_AddValue(string name, object value); 100 | 101 | /// 102 | /// Clear all items contained in a list. 103 | /// 104 | /// 105 | bool List_Clear(); 106 | 107 | /// 108 | /// Gets a list of current values if this schema descripes a List. 109 | /// Return a single value schema as a list of 1 item. 110 | /// 111 | /// 112 | IEnumerable List_GetListOfValues(); 113 | 114 | /// 115 | /// Gets a list of current keys and values if this schema 116 | /// descripes a List. 117 | /// 118 | /// Return a single value schema as a list of 1 item. 119 | /// 120 | /// 121 | IEnumerable> List_GetListOfKeyValues(); 122 | #endregion methods 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/SettingsModel/Models/Factory.cs: -------------------------------------------------------------------------------- 1 | namespace SettingsModel.Models 2 | { 3 | using SettingsModel.Interfaces; 4 | 5 | /// 6 | /// Factory class to create an 7 | /// object from a class that is otherwise unknown to the outside world. 8 | /// 9 | public static class Factory 10 | { 11 | /// 12 | /// Create a new engine object that provides all root functions required 13 | /// to model, track, persist, and load data at run-time. 14 | /// 15 | /// 16 | public static IEngine CreateEngine() 17 | { 18 | return new OptionsEngine(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/SettingsModel/Models/FileReference.cs: -------------------------------------------------------------------------------- 1 | namespace SettingsModel.Models 2 | { 3 | using System.Xml.Serialization; 4 | 5 | /// 6 | /// Implement a simple file reverence model to allow XML persistence 7 | /// of a List via this class. 8 | /// 9 | public class FileReference 10 | { 11 | /// 12 | /// Gets/sets the path to a file. 13 | /// 14 | [XmlAttribute(AttributeName = "path")] 15 | public string path { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/SettingsModel/Models/XML/Converters/AlternativeDataTypeHandler.cs: -------------------------------------------------------------------------------- 1 | namespace SettingsModel.Models.XML.Converters 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Security; 6 | 7 | /// 8 | /// Holds a collection of alternative datatype 9 | /// handlers to handle datatypes that are not supported through equivalent conversion 10 | /// in alternative datatypes. 11 | /// 12 | internal class AlternativeDataTypeHandler 13 | { 14 | #region fields 15 | private readonly Dictionary converters = null; 16 | #endregion fields 17 | 18 | public AlternativeDataTypeHandler() 19 | { 20 | converters = new Dictionary(); 21 | 22 | converters.Add(typeof(SecureString), new SecureStringHandler()); 23 | } 24 | 25 | /// 26 | /// Finds an alternative datatype handler to handle datatypes that are not 27 | /// supported through equivalent conversion in alternative datatypes. 28 | /// 29 | /// 30 | /// 31 | public IAlternativeDataTypeHandler FindHandler(Type typeOfDataType2Handle) 32 | { 33 | IAlternativeDataTypeHandler ret = null; 34 | 35 | try 36 | { 37 | converters.TryGetValue(typeOfDataType2Handle, out ret); 38 | } 39 | catch 40 | { 41 | } 42 | 43 | return ret; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/SettingsModel/Models/XML/Converters/IAlternativeDataTypeHandler.cs: -------------------------------------------------------------------------------- 1 | namespace SettingsModel.Models.XML.Converters 2 | { 3 | using System; 4 | 5 | internal interface IAlternativeDataTypeHandler 6 | { 7 | Type SourceDataType { get; } 8 | Type TargetDataType { get; } 9 | 10 | object Convert(object objectInput); 11 | object ConvertBack(object objectEncryptedData); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/SettingsModel/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SettingsModel")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SettingsModel")] 13 | [assembly: AssemblyCopyright("The MIT License (MIT) Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9b0ba841-5a2f-4ed3-a908-253dbca70e77")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /source/Demo/MLibTest/Components/Settings/SettingsModel/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Converters/BoolToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Converters 2 | { 3 | using System; 4 | using System.Globalization; 5 | using System.Windows; 6 | using System.Windows.Data; 7 | 8 | /// 9 | /// Source: http://stackoverflow.com/questions/534575/how-do-i-invert-booleantovisibilityconverter 10 | /// 11 | /// Implements a Boolean to Visibility converter 12 | /// Use ConverterParameter=true to negate the visibility - boolean interpretation. 13 | /// 14 | [ValueConversion(typeof(Boolean), typeof(Visibility))] 15 | public sealed class BoolToVisibilityConverter : IValueConverter 16 | { 17 | /// 18 | /// Converts a value 19 | /// into a value. 20 | /// 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 27 | { 28 | var back = ((value is Visibility) && (((Visibility)value) == Visibility.Visible)); 29 | 30 | if (parameter != null) 31 | { 32 | if ((bool)parameter) 33 | { 34 | back = !back; 35 | } 36 | } 37 | return back; 38 | } 39 | 40 | /// 41 | /// Converts a value 42 | /// into a value. 43 | /// 44 | /// 45 | /// 46 | /// 47 | /// 48 | /// 49 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 50 | { 51 | var flag = false; 52 | if (value is bool) 53 | { 54 | flag = (bool)value; 55 | } 56 | else if (value is bool?) 57 | { 58 | var nullable = (bool?)value; 59 | flag = nullable.GetValueOrDefault(); 60 | } 61 | if (parameter != null) 62 | { 63 | if (bool.Parse((string)parameter)) 64 | { 65 | flag = !flag; 66 | } 67 | } 68 | if (flag) 69 | { 70 | return Visibility.Visible; 71 | } 72 | else 73 | { 74 | return Visibility.Collapsed; 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Converters/EnumMatchToBooleanConverter.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Converters 2 | { 3 | using System; 4 | using System.Globalization; 5 | using System.Windows.Data; 6 | 7 | /// 8 | /// https://www.wpftutorial.net/RadioButton.html 9 | /// 10 | public class EnumMatchToBooleanConverter : IValueConverter 11 | { 12 | public object Convert(object value, Type targetType, 13 | object parameter, CultureInfo culture) 14 | { 15 | if (value == null || parameter == null) 16 | return false; 17 | 18 | string checkValue = value.ToString(); 19 | string targetValue = parameter.ToString(); 20 | return checkValue.Equals(targetValue, 21 | StringComparison.InvariantCultureIgnoreCase); 22 | } 23 | 24 | public object ConvertBack(object value, Type targetType, 25 | object parameter, CultureInfo culture) 26 | { 27 | if (value == null || parameter == null) 28 | return null; 29 | 30 | bool useValue = (bool)value; 31 | string targetValue = parameter.ToString(); 32 | if (useValue) 33 | return Enum.Parse(targetType, targetValue); 34 | 35 | return null; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("UpDownDemoLib")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("UpDownDemoLib")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ed3a742d-4055-4da2-bbce-74e817b211bf")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/Base/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.ViewModels.Base 2 | { 3 | using System; 4 | using System.ComponentModel; 5 | using System.Linq.Expressions; 6 | 7 | /// 8 | /// Implements a base class for all viewmodel classes 9 | /// that implements interface for binding. 10 | /// 11 | public class ViewModelBase : INotifyPropertyChanged 12 | { 13 | /// 14 | /// Standard implementation of . 15 | /// 16 | public event PropertyChangedEventHandler PropertyChanged; 17 | 18 | /// 19 | /// Tell bound controls (via WPF binding) to refresh their display. 20 | /// 21 | /// Sample call: this.NotifyPropertyChanged(() => this.IsSelected); 22 | /// where 'this' is derived from 23 | /// and IsSelected is a property. 24 | /// 25 | /// 26 | /// 27 | public void NotifyPropertyChanged(Expression> property) 28 | { 29 | var lambda = (LambdaExpression)property; 30 | MemberExpression memberExpression; 31 | 32 | if (lambda.Body is UnaryExpression) 33 | { 34 | var unaryExpression = (UnaryExpression)lambda.Body; 35 | memberExpression = (MemberExpression)unaryExpression.Operand; 36 | } 37 | else 38 | memberExpression = (MemberExpression)lambda.Body; 39 | 40 | this.NotifyPropertyChanged(memberExpression.Member.Name); 41 | } 42 | 43 | /// 44 | /// Tell bound controls (via WPF binding) to refresh their display. 45 | /// Standard implementation through . 46 | /// 47 | /// 48 | protected virtual void NotifyPropertyChanged(string propertyName) 49 | { 50 | if (this.PropertyChanged != null) 51 | this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/ByteUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements a based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class ByteUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public ByteUpDownViewModel(byte value, 20 | byte minimumValue, 21 | byte maximumValue, 22 | byte stepSize, 23 | byte largeStepSize 24 | ) 25 | : base() 26 | { 27 | base.Value = value; 28 | base.MinimumValue = minimumValue; 29 | base.MaximumValue = maximumValue; 30 | base.StepSize = stepSize; 31 | base.LargeStepSize = largeStepSize; 32 | } 33 | 34 | /// 35 | /// Method determine whether two objects of type {T} are equal. 36 | /// 37 | /// Returns false if both objects are in-equal, otherwise true. 38 | /// 39 | /// 40 | /// 41 | /// 42 | public override bool Compare(byte intValue, byte intValue1) 43 | { 44 | return byte.Equals(intValue, intValue1); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/DecimalUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements an based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class DecimalUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public DecimalUpDownViewModel(decimal value, 20 | decimal minimumValue, 21 | decimal maximumValue, 22 | decimal stepSize, 23 | decimal largeStepSize 24 | ) 25 | : base() 26 | { 27 | base.Value = value; 28 | base.MinimumValue = minimumValue; 29 | base.MaximumValue = maximumValue; 30 | base.StepSize = stepSize; 31 | base.LargeStepSize = largeStepSize; 32 | 33 | // "decimal" does not support format string "D" as set in base class 34 | FormatString = "F4"; 35 | } 36 | 37 | /// 38 | /// Method determine whether two objects of type {T} are equal. 39 | /// 40 | /// Returns false if both objects are in-equal, otherwise true. 41 | /// 42 | /// 43 | /// 44 | /// 45 | public override bool Compare(decimal intValue, decimal intValue1) 46 | { 47 | return decimal.Equals(intValue, intValue1); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/DoubleUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements an based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class DoubleUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public DoubleUpDownViewModel(double value, 20 | double minimumValue, 21 | double maximumValue, 22 | double stepSize, 23 | double largestepSize 24 | ) 25 | : base() 26 | { 27 | base.Value = value; 28 | base.MinimumValue = minimumValue; 29 | base.MaximumValue = maximumValue; 30 | base.StepSize = stepSize; 31 | base.LargeStepSize = largestepSize; 32 | 33 | FormatString = "F4"; 34 | } 35 | 36 | /// Method determine whether two objects of type {T} are equal. 37 | /// 38 | /// Returns false if both objects are in-equal, otherwise true. 39 | public override bool Compare(double intValue, double intValue1) 40 | { 41 | return double.Equals(intValue, intValue1); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/FloatUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements an based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class FloatUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public FloatUpDownViewModel(float value, 20 | float minimumValue, 21 | float maximumValue, 22 | float stepSize, 23 | float largeStepSize 24 | ) 25 | : base() 26 | { 27 | base.Value = value; 28 | base.MinimumValue = minimumValue; 29 | base.MaximumValue = maximumValue; 30 | base.StepSize = stepSize; 31 | base.LargeStepSize = largeStepSize; 32 | 33 | FormatString = "F4"; 34 | } 35 | 36 | /// Method determine whether two objects of type {T} are equal. 37 | /// 38 | /// Returns false if both objects are in-equal, otherwise true. 39 | public override bool Compare(float intValue, float intValue1) 40 | { 41 | return float.Equals(intValue, intValue1); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/IntegerUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements an based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class IntegerUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public IntegerUpDownViewModel(int value, 20 | int minimumValue, 21 | int maximumValue, 22 | int stepSize, 23 | int largeStepSize 24 | ) 25 | : base() 26 | { 27 | base.Value = value; 28 | base.MinimumValue = minimumValue; 29 | base.MaximumValue = maximumValue; 30 | base.StepSize = stepSize; 31 | base.LargeStepSize = largeStepSize; 32 | } 33 | 34 | /// 35 | /// Method determine whether two objects of type {T} are equal. 36 | /// 37 | /// Returns false if both objects are in-equal, otherwise true. 38 | /// 39 | /// 40 | /// 41 | /// 42 | public override bool Compare(int intValue, int intValue1) 43 | { 44 | return int.Equals(intValue, intValue1); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/LongUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements an based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class LongUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public LongUpDownViewModel(long value, 20 | long minimumValue, 21 | long maximumValue, 22 | long stepSize, 23 | long largeStepSize 24 | ) 25 | : base() 26 | { 27 | base.Value = value; 28 | base.MinimumValue = minimumValue; 29 | base.MaximumValue = maximumValue; 30 | base.StepSize = stepSize; 31 | base.LargeStepSize = largeStepSize; 32 | } 33 | 34 | /// 35 | /// Method determine whether two objects of type {T} are equal. 36 | /// 37 | /// Returns false if both objects are in-equal, otherwise true. 38 | /// 39 | /// 40 | /// 41 | /// 42 | public override bool Compare(long intValue, long intValue1) 43 | { 44 | return long.Equals(intValue, intValue1); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/SByteUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements an based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class SByteUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public SByteUpDownViewModel(sbyte value, 20 | sbyte minimumValue, 21 | sbyte maximumValue, 22 | sbyte stepSize, 23 | sbyte largeStepSize 24 | ) 25 | : base() 26 | { 27 | base.Value = value; 28 | base.MinimumValue = minimumValue; 29 | base.MaximumValue = maximumValue; 30 | base.StepSize = stepSize; 31 | base.LargeStepSize = largeStepSize; 32 | } 33 | 34 | /// 35 | /// Method determine whether two objects of type {T} are equal. 36 | /// 37 | /// Returns false if both objects are in-equal, otherwise true. 38 | /// 39 | /// 40 | /// 41 | /// 42 | public override bool Compare(sbyte intValue, sbyte intValue1) 43 | { 44 | return sbyte.Equals(intValue, intValue1); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/ShortUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements a based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class ShortUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public ShortUpDownViewModel(short value, 20 | short minimumValue, 21 | short maximumValue, 22 | short stepSize, 23 | short largeStepSize 24 | ) 25 | : base() 26 | { 27 | base.Value = value; 28 | base.MinimumValue = minimumValue; 29 | base.MaximumValue = maximumValue; 30 | base.StepSize = stepSize; 31 | base.LargeStepSize = largeStepSize; 32 | } 33 | 34 | /// 35 | /// Method determine whether two objects of type {T} are equal. 36 | /// 37 | /// Returns false if both objects are in-equal, otherwise true. 38 | /// 39 | /// 40 | /// 41 | /// 42 | public override bool Compare(short intValue, short intValue1) 43 | { 44 | return short.Equals(intValue, intValue1); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/UIntegerUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements a based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class UIntegerUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public UIntegerUpDownViewModel(uint value, 20 | uint minimumValue, 21 | uint maximumValue, 22 | uint stepSize, 23 | uint largeStepSize 24 | ) 25 | : base() 26 | { 27 | base._FormatString = "D8"; 28 | 29 | base.Value = value; 30 | base.MinimumValue = minimumValue; 31 | base.MaximumValue = maximumValue; 32 | base.StepSize = stepSize; 33 | base.LargeStepSize = largeStepSize; 34 | } 35 | 36 | /// 37 | /// Method determine whether two objects of type {T} are equal. 38 | /// 39 | /// Returns false if both objects are in-equal, otherwise true. 40 | /// 41 | /// 42 | /// 43 | /// 44 | public override bool Compare(uint intValue, uint intValue1) 45 | { 46 | return uint.Equals(intValue, intValue1); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/ULongUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements a based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class ULongUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public ULongUpDownViewModel(ulong value, 20 | ulong minimumValue, 21 | ulong maximumValue, 22 | ulong stepSize, 23 | ulong largeStepSize 24 | ) 25 | : base() 26 | { 27 | base.Value = value; 28 | base.MinimumValue = minimumValue; 29 | base.MaximumValue = maximumValue; 30 | base.StepSize = stepSize; 31 | base.LargeStepSize = largeStepSize; 32 | } 33 | 34 | /// 35 | /// Method determine whether two objects of type {T} are equal. 36 | /// 37 | /// Returns false if both objects are in-equal, otherwise true. 38 | /// 39 | /// 40 | /// 41 | /// 42 | public override bool Compare(ulong intValue, ulong intValue1) 43 | { 44 | return ulong.Equals(intValue, intValue1); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/ViewModels/UShortUpDownViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Demos.ViewModels 2 | { 3 | using UpDownDemoLib.ViewModels; 4 | 5 | /// 6 | /// Implements a based demo viewmodel that can be used 7 | /// to drive an integer base numeric up down control. 8 | /// 9 | public class UShortUpDownViewModel : BaseUpDownViewModel 10 | { 11 | /// 12 | /// Class constructor 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public UShortUpDownViewModel(ushort value, 20 | ushort minimumValue, 21 | ushort maximumValue, 22 | ushort stepSize, 23 | ushort largeStepSize 24 | ) 25 | : base() 26 | { 27 | base.Value = value; 28 | base.MinimumValue = minimumValue; 29 | base.MaximumValue = maximumValue; 30 | base.StepSize = stepSize; 31 | base.LargeStepSize = largeStepSize; 32 | } 33 | 34 | /// 35 | /// Method determine whether two objects of type {T} are equal. 36 | /// 37 | /// Returns false if both objects are in-equal, otherwise true. 38 | /// 39 | /// 40 | /// 41 | /// 42 | public override bool Compare(ushort intValue, ushort intValue1) 43 | { 44 | return ushort.Equals(intValue, intValue1); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/ByteUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class ByteUpDownDemo : UserControl 9 | { 10 | public ByteUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/DecimalUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class DecimalUpDownDemo : UserControl 9 | { 10 | public DecimalUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/DoubleUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class DoubleUpDownDemo : UserControl 9 | { 10 | public DoubleUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/FloatUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class FloatUpDownDemo : UserControl 9 | { 10 | public FloatUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/LongUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class LongUpDownDemo : UserControl 9 | { 10 | public LongUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/NumericUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class NumericUpDownDemo : UserControl 9 | { 10 | public NumericUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/PercentageUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class PercentageUpDownDemo : UserControl 9 | { 10 | public PercentageUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/SByteUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class SByteUpDownDemo : UserControl 9 | { 10 | public SByteUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/ShortUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class ShortUpDownDemo : UserControl 9 | { 10 | public ShortUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/UIntegerUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class UIntegerUpDownDemo : UserControl 9 | { 10 | public UIntegerUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/ULongUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class ULongUpDownDemo : UserControl 9 | { 10 | public ULongUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/Demo/UpDownDemoLib/Views/UShortUpDownDemo.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace UpDownDemoLib.Views 2 | { 3 | using System.Windows.Controls; 4 | 5 | /// 6 | /// Interaction logic for DoubleUpDownDemo.xaml 7 | /// 8 | public partial class UShortUpDownDemo : UserControl 9 | { 10 | public UShortUpDownDemo() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/NUnitTestProject/ByteTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class ByteTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(0, 25, 155); 26 | TestAllPermutations(50, 50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(25, 150, 255); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(byte min, byte val, byte max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new ByteUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while(range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(ByteUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /source/NUnitTestProject/DecimalTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class DecimalTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(-25, 50, 75); 26 | TestAllPermutations(-50, -50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(-50, -50, -50); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(decimal min, decimal val, decimal max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new DecimalUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while (range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(DecimalUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /source/NUnitTestProject/DoubleTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class DoubleTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(-25, 50, 75); 26 | TestAllPermutations(-50, -50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(-50, -50, -50); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(double min, double val, double max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new DoubleUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while (range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(DoubleUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /source/NUnitTestProject/FloatTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class FloatTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(-25, 50, 75); 26 | TestAllPermutations(-50, -50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(-50, -50, -50); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(float min, float val, float max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new FloatUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while (range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(FloatUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /source/NUnitTestProject/LongTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class LongTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(-25, 50, 75); 26 | TestAllPermutations(-50, -50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(-50, -50, -50); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(long min, long val, long max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new LongUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while (range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(LongUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /source/NUnitTestProject/NUnitTestProject.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /source/NUnitTestProject/NumericTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class NumericTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(-25, 50, 75); 26 | TestAllPermutations(-50, -50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(-50, -50, -50); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(int min, int val, int max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new NumericUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while (range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(NumericUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /source/NUnitTestProject/SbyteTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class SByteTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(-25, 50, 75); 26 | TestAllPermutations(-50, -50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(-50, -50, -50); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(sbyte min, sbyte val, sbyte max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new SByteUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while (range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(SByteUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /source/NUnitTestProject/ShortTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class ShortTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(-25, 50, 75); 26 | TestAllPermutations(-50, -50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(-50, -50, -50); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(short min, short val, short max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new ShortUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while (range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(ShortUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /source/NUnitTestProject/UIntegerTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class UIntegerTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(0, 15, 75); 26 | TestAllPermutations(50, 50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(150, 250, 255); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(uint min, uint val, uint max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new UIntegerUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while (range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(UIntegerUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /source/NUnitTestProject/ULongTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class ULongTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(0, 50, 75); 26 | TestAllPermutations(50, 50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(150, 150, 256); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(ulong min, ulong val, ulong max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new ULongUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while (range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(ULongUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /source/NUnitTestProject/UShortTests.cs: -------------------------------------------------------------------------------- 1 | using NumericUpDownLib; 2 | using NumericUpDownLib.Base; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Threading; 6 | 7 | namespace NUnitTestProject 8 | { 9 | [Apartment(ApartmentState.STA)] 10 | public class UShortTests 11 | { 12 | [SetUp] 13 | public void Setup() 14 | { 15 | } 16 | 17 | /// 18 | /// Tests whether values are set correctly as required while maintaining 19 | /// valid values at all times. 20 | /// 21 | [Test] 22 | public void TestValues() 23 | { 24 | TestAllPermutations(25, 50, 75); 25 | TestAllPermutations(0, 50, 75); 26 | TestAllPermutations(50, 50, 75); 27 | TestAllPermutations(50, 50, 50); 28 | TestAllPermutations(150, 250, 255); 29 | } 30 | 31 | /// 32 | /// Tests all permutions for all sequences of three elements. 33 | /// 34 | /// 35 | /// 36 | /// 37 | public void TestAllPermutations(ushort min, ushort val, ushort max) 38 | { 39 | string[,] ctrl = new string[6, 3] 40 | { 41 | { "min", "val", "max" }, 42 | { "val", "min", "max" }, 43 | { "val", "max", "min" }, 44 | { "val", "min", "max" }, 45 | { "min", "max", "val" }, 46 | { "max", "min", "val" }, 47 | }; 48 | 49 | for (int i = 0; i < 6; i++) 50 | { 51 | var range = new UShortUpDown(); 52 | string testPermutation = ""; 53 | 54 | for (int j = 0; j < 3; j++) 55 | { 56 | var itemToSet = ctrl[i, j]; 57 | 58 | if (string.IsNullOrEmpty(testPermutation)) 59 | testPermutation = itemToSet; 60 | else 61 | testPermutation += ", " + itemToSet; 62 | 63 | switch (itemToSet) 64 | { 65 | case "min": 66 | range.MinValue = min; 67 | Assert.IsTrue(IsValidRange(range)); 68 | break; 69 | 70 | case "val": 71 | range.Value = val; 72 | Assert.IsTrue(IsValidRange(range)); 73 | break; 74 | 75 | case "max": 76 | range.MaxValue = max; 77 | Assert.IsTrue(IsValidRange(range)); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | } 84 | 85 | Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max); 86 | Assert.IsTrue(IsValidRange(range)); 87 | 88 | Assert.IsTrue(range.MinValue == min); 89 | Assert.IsTrue(range.Value == val); 90 | Assert.IsTrue(range.MaxValue == max); 91 | 92 | // Test if increment command works as expected 93 | while (range.MaxValue > range.Value) 94 | { 95 | Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range)); 96 | InputBaseUpDown.IncreaseCommand.Execute(null, range); 97 | } 98 | Assert.IsTrue(range.MaxValue == range.Value); 99 | 100 | // Test if decrement command works as expected 101 | while (range.MinValue < range.Value) 102 | { 103 | Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range)); 104 | InputBaseUpDown.DecreaseCommand.Execute(null, range); 105 | } 106 | Assert.IsTrue(range.MinValue == range.Value); 107 | } 108 | } 109 | 110 | /// 111 | /// Determines whether the given set of values defines a valid range or not. 112 | /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue. 113 | /// 114 | /// 115 | /// 116 | bool IsValidRange(UShortUpDown range) 117 | { 118 | if (range.MinValue <= range.Value && range.Value <= range.MaxValue) 119 | return true; 120 | 121 | return false; 122 | 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] 11 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Base/NumericRepeatButtonControl.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 66 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Base/NumericRepeatButtonControl.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace NumericUpDownLib.Base 2 | { 3 | using System.Windows; 4 | using System.Windows.Controls.Primitives; 5 | using System.Windows.Input; 6 | using System.Windows.Media; 7 | 8 | /// 9 | /// Class implements a repeat button custom control that supports 10 | /// custom data for display as an error and 11 | /// and binding to relay a click command 12 | /// to a hosting control or bound viewmodel. 13 | /// 14 | public class NumericRepeatButtonControl : RepeatButton 15 | { 16 | static NumericRepeatButtonControl() 17 | { 18 | DefaultStyleKeyProperty.OverrideMetadata(typeof(NumericRepeatButtonControl), new FrameworkPropertyMetadata(typeof(NumericRepeatButtonControl))); 19 | } 20 | 21 | #region RepeatButtonContent dependency property 22 | /// 23 | /// Gets/sets an object that is bound to the 24 | /// ContentControl of the RepeatButton. 25 | /// 26 | public Geometry RepeatButtonContent 27 | { 28 | get { return (Geometry)GetValue(RepeatButtonContentProperty); } 29 | set { SetValue(RepeatButtonContentProperty, value); } 30 | } 31 | 32 | /// 33 | /// Using a DependencyProperty as the backing store for RepeatButtonContent. 34 | /// This enables styling and usage of flexible binding. 35 | /// 36 | public static readonly DependencyProperty RepeatButtonContentProperty = 37 | DependencyProperty.Register("RepeatButtonContent", 38 | typeof(Geometry), 39 | typeof(NumericRepeatButtonControl), 40 | new PropertyMetadata(null)); 41 | #endregion RepeatButtonContent dependency property 42 | 43 | #region ICommand dependency property 44 | /// 45 | /// Gets/sets the command that is bound and 46 | /// invocked when the repeat button is clicked. 47 | /// 48 | public ICommand ClickCommand 49 | { 50 | get { return (ICommand)GetValue(ClickCommandProperty); } 51 | set { SetValue(ClickCommandProperty, value); } 52 | } 53 | 54 | /// 55 | /// Implments the backing store for a DependencyProperty of the ClickCommand. 56 | /// 57 | public static readonly DependencyProperty ClickCommandProperty = 58 | DependencyProperty.Register("ClickCommand", 59 | typeof(ICommand), 60 | typeof(NumericRepeatButtonControl), 61 | new PropertyMetadata(null)); 62 | #endregion ICommand dependency property 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Converters/BoolToVisibilityPropConverter.cs: -------------------------------------------------------------------------------- 1 | namespace NumericUpDownLib.Converters 2 | { 3 | using System; 4 | using System.Globalization; 5 | using System.Windows; 6 | using System.Windows.Data; 7 | 8 | /// 9 | /// Converts a boolean value into a configurable 10 | /// value of type . 11 | /// 12 | /// Source: http://stackoverflow.com/questions/3128023/wpf-booleantovisibilityconverter-that-converts-to-hidden-instead-of-collapsed-wh 13 | /// 14 | [ValueConversion(typeof(bool), typeof(Visibility))] 15 | public sealed class BoolToVisibilityPropConverter : IValueConverter 16 | { 17 | #region constructor 18 | /// 19 | /// Class constructor 20 | /// 21 | public BoolToVisibilityPropConverter() 22 | { 23 | // set defaults 24 | TrueValue = Visibility.Visible; 25 | FalseValue = Visibility.Collapsed; 26 | } 27 | #endregion constructor 28 | 29 | #region properties 30 | /// 31 | /// Gets/sets the value that is associated 32 | /// (converted into) with the boolean true value. 33 | /// 34 | public Visibility TrueValue { get; set; } 35 | 36 | /// 37 | /// Gets/sets the value that is associated 38 | /// (converted into) with the boolean false value. 39 | /// 40 | public Visibility FalseValue { get; set; } 41 | #endregion properties 42 | 43 | #region methods 44 | /// 45 | /// Convertzs a bool value into as configured in the 46 | /// and properties. 47 | /// 48 | /// 49 | /// 50 | /// 51 | /// 52 | /// 53 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 54 | { 55 | if (!(value is bool)) 56 | return null; 57 | return (bool)value ? TrueValue : FalseValue; 58 | } 59 | 60 | /// 61 | /// Convertzs a value into bool as configured in the 62 | /// and properties. 63 | /// 64 | /// 65 | /// 66 | /// 67 | /// 68 | /// 69 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 70 | { 71 | if (Equals(value, TrueValue)) 72 | return true; 73 | 74 | if (Equals(value, FalseValue)) 75 | return false; 76 | 77 | return null; 78 | } 79 | #endregion methods 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Converters/ByteToPlaceHolderStringConverter.cs: -------------------------------------------------------------------------------- 1 | namespace NumericUpDownLib.Converters 2 | { 3 | using System; 4 | using System.Globalization; 5 | using System.Windows.Data; 6 | 7 | /// 8 | /// Converts a byte number into a string that contains the number 'X' characters input. 9 | /// The output of this converter can be used to measure UI Air space to ensure enough 10 | /// space for input controls... 11 | /// 12 | [ValueConversion(typeof(byte), typeof(string))] 13 | public sealed class ByteToPlaceHolderStringConverter : IValueConverter 14 | { 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// 21 | /// 22 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 23 | { 24 | if ((value is byte) == false) 25 | return Binding.DoNothing; 26 | 27 | byte byteVal = (byte)value; 28 | 29 | string retString = string.Empty; 30 | for (int i = 0; i < byteVal; i++) 31 | retString = retString + "X"; 32 | 33 | return retString; 34 | } 35 | 36 | /// 37 | /// 38 | /// 39 | /// 40 | /// 41 | /// 42 | /// 43 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 44 | { 45 | return Binding.DoNothing; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Converters/FactorToDoubleConverter.cs: -------------------------------------------------------------------------------- 1 | namespace NumericUpDownLib.Converters 2 | { 3 | using System; 4 | using System.Globalization; 5 | using System.Windows; 6 | using System.Windows.Data; 7 | 8 | /// 9 | /// Scales a double value by its scale factor (eg. 100.00) up (convert) 10 | /// or down (convertback), or vice versa if factor is set to 0.01... 11 | /// 12 | [ValueConversion(typeof(double), typeof(double))] 13 | public sealed class FactorToDoubleConverter : IValueConverter 14 | { 15 | /// 16 | /// Class constructor 17 | /// 18 | public FactorToDoubleConverter() 19 | { 20 | Factor = 100.0; 21 | } 22 | 23 | /// 24 | /// Gets/sets the factor for multiplication and division 25 | /// between source (viewmodel) and target (view). 26 | /// 27 | public double Factor { get; set; } 28 | 29 | /// 30 | /// Converts a value 31 | /// into a value. 32 | /// 33 | /// 34 | /// 35 | /// 36 | /// 37 | /// 38 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 39 | { 40 | if (value is float) // Do multplikation with float and output float 41 | { 42 | var val = (float)value; 43 | 44 | return (float)(val * Factor); 45 | } 46 | 47 | if (value is double) // Do multplikation with double and output double 48 | { 49 | var val = (double)value; 50 | 51 | return val * Factor; 52 | } 53 | 54 | return Binding.DoNothing; 55 | } 56 | 57 | /// 58 | /// Converts a value 59 | /// into a value. 60 | /// 61 | /// 62 | /// 63 | /// 64 | /// 65 | /// 66 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 67 | { 68 | if (value is float) // Do division with float and output float 69 | { 70 | var val = (double)((float)value); 71 | 72 | return (float)(val / Factor); 73 | } 74 | 75 | if (value is double) // Do division with double and output double 76 | { 77 | var val = (double)value; 78 | 79 | return val / Factor; 80 | } 81 | 82 | return Binding.DoNothing; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Enums/CanIncDecMouseDrag.cs: -------------------------------------------------------------------------------- 1 | namespace NumericUpDownLib.Enums 2 | { 3 | /// 4 | /// Defines the mouse drag modes that are supported to increment/decrement 5 | /// small/large values allowing horizontal/vertical mouse drag moves at the same 6 | /// time or each direction only by itself. 7 | /// 8 | public enum CanIncDecMouseDrag 9 | { 10 | /// 11 | /// A value can be incremented/decremented in small steps using vertical mouse drag moves only. 12 | /// 13 | VerticalOnly, 14 | 15 | /// 16 | /// A value can be incremented/decremented in large steps using horizontal mouse drag moves only. 17 | /// 18 | HorizontalOnly, 19 | 20 | /// 21 | /// A value can be incremented/decremented in small steps or large steps 22 | /// using vertical or horizontal mouse drag moves at the same time. 23 | /// 24 | VerticalHorizontal 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Models/MouseDirections.cs: -------------------------------------------------------------------------------- 1 | namespace NumericUpDownLib.Models 2 | { 3 | /// 4 | /// Specifies the direction in which the mouse is recognized 5 | /// to be moved when comparing coordinates for 2 points. 6 | /// 7 | internal enum MouseDirections 8 | { 9 | /// 10 | /// A mouse movement was not detected. 11 | /// 12 | None, 13 | 14 | /// 15 | /// Mouse was moved horizontally rather than vertically. 16 | /// 17 | LeftRight, 18 | 19 | /// 20 | /// Mouse was moved vertically rather than horizontally. 21 | /// 22 | UpDown 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Models/MouseIncrementor.cs: -------------------------------------------------------------------------------- 1 | namespace NumericUpDownLib.Models 2 | { 3 | using System; 4 | using System.Windows; 5 | 6 | /// 7 | /// Models a simple object that keeps track of the direction in which 8 | /// a mouse was moved, its initial coordinates on the screen and its 9 | /// current location... 10 | /// 11 | internal class MouseIncrementor 12 | { 13 | #region fields 14 | private MouseDirections _enumMouseDirection = MouseDirections.None; 15 | private Point _objPoint; 16 | 17 | private readonly Point _initialPoint; 18 | #endregion fields 19 | 20 | #region Ctors 21 | /// 22 | /// Class constructor 23 | /// 24 | /// 25 | /// 26 | public MouseIncrementor(Point objPoint, MouseDirections enumMouseDirection) 27 | { 28 | _objPoint = objPoint; 29 | _initialPoint = _objPoint; 30 | _enumMouseDirection = enumMouseDirection; 31 | } 32 | #endregion Ctors 33 | 34 | #region properties 35 | /// 36 | /// Gets/sets the direction in which a mouse was seen to be moved 37 | /// when comparing 2 points. 38 | /// 39 | public MouseDirections MouseDirection 40 | { 41 | get 42 | { 43 | return _enumMouseDirection; 44 | } 45 | 46 | protected set 47 | { 48 | _enumMouseDirection = value; 49 | } 50 | } 51 | 52 | /// 53 | /// Gets the initial mouse location (eg.: mouse down) in which we've seen the mouse 54 | /// in the beginning of this processing. 55 | /// 56 | public Point InitialPoint 57 | { 58 | get 59 | { 60 | return _initialPoint; 61 | } 62 | } 63 | 64 | /// 65 | /// Gets/sets the current mouse location (eg.: during mouse move) 66 | /// in which we've seen the mouse last. 67 | /// 68 | public Point Point 69 | { 70 | get 71 | { 72 | return _objPoint; 73 | } 74 | 75 | set 76 | { 77 | _objPoint = value; 78 | } 79 | } 80 | 81 | /// 82 | /// Sets the current mouse direction based on the last position stored 83 | /// in the property compared to the coordinates in 84 | /// the parameter. 85 | /// 86 | /// 87 | /// The mouse direction that was identified when comparing 2 coordinates. 88 | internal MouseDirections SetMouseDirection(Point pos) 89 | { 90 | double deltaX = this.Point.X - pos.X; 91 | double deltaY = this.Point.Y - pos.Y; 92 | 93 | if (Math.Abs(deltaX) > Math.Abs(deltaY)) 94 | MouseDirection = MouseDirections.LeftRight; 95 | else 96 | { 97 | if (Math.Abs(deltaX) < Math.Abs(deltaY)) 98 | MouseDirection = MouseDirections.UpDown; 99 | } 100 | 101 | return MouseDirection; 102 | } 103 | #endregion properties 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/NumericUpDownLib.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net4;netcoreapp3.0 5 | true 6 | 7 | true 8 | 3.4.0.0 9 | 3.4.0.0 10 | 3.4.0.0 11 | Open Source 12 | NumericUpDownLib 13 | 2013-2023 14 | Provides a numeric up down WPF control that can be used to edit (integer, byte, decimal, double, float, short and many more) values with a textbox and/or up/down arrow (repeat) buttons. Editing can be based on input via mouse wheel, mouse drag, cursor keys, or text editing. 15 | https://github.com/Dirkster99/NumericUpDownLib 16 | https://github.com/Dirkster99/NumericUpDownLib 17 | Dirkster.NumericUpDownLib 18 | https://github.com/Dirkster99/NumericUpDownLib 19 | MIT 20 | numericupdown numeric up down integer float double percentage increment decrement custom wpf control mvvm c# .net metro black light themed control library 21 | Adding features and fixes please refer to release notes. 22 | en 23 | SyncArrow_64x.png 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 35 | Code 36 | NumericRepeatButtonControl.xaml 37 | 38 | 39 | 40 | 41 | 42 | Designer 43 | 44 | 45 | Designer 46 | 47 | 48 | Designer 49 | 50 | 51 | Designer 52 | MSBuild:Compile 53 | 54 | 55 | Designer 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/NumericUpDownLib.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Designer 7 | 8 | 9 | Designer 10 | 11 | 12 | Designer 13 | 14 | 15 | Designer 16 | 17 | 18 | Designer 19 | 20 | 21 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Themes/DarkBrushs.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 11 | #FF1888b8 12 | 13 | 18 | 19 | 20 | 21 | 26 | 27 | 31 | 32 | 36 | 37 | 42 | 43 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Themes/Generic.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Themes/LightBrushs.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 11 | #FF1888b8 12 | 13 | 18 | 19 | 20 | 21 | 26 | 27 | 32 | 33 | 38 | 39 | 44 | 45 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/Themes/ResourceKeys.cs: -------------------------------------------------------------------------------- 1 | namespace NumericUpDownLib.Themes 2 | { 3 | using System.Windows; 4 | 5 | /// 6 | /// Resource key management class to keep track of all resources 7 | /// that can be re-styled in applications that make use of the implemented controls. 8 | /// 9 | public static class ResourceKeys 10 | { 11 | #region Accent Keys 12 | /// 13 | /// Accent Color Key - This Color key is used to accent elements in the UI 14 | /// (e.g.: Color of Activated Normal Window Frame, ResizeGrip, Focus or MouseOver input elements) 15 | /// 16 | public static readonly ComponentResourceKey ControlAccentColorKey = new ComponentResourceKey(typeof(ResourceKeys), "ControlAccentColorKey"); 17 | 18 | /// 19 | /// Accent Brush Key - This Brush key is used to accent elements in the UI 20 | /// (e.g.: Color of Activated Normal Window Frame, ResizeGrip, Focus or MouseOver input elements) 21 | /// 22 | public static readonly ComponentResourceKey ControlAccentBrushKey = new ComponentResourceKey(typeof(ResourceKeys), "ControlAccentBrushKey"); 23 | #endregion Accent Keys 24 | 25 | #region Brush Keys 26 | /// 27 | /// Resource key of the controls normal glyph brush key. 28 | /// 29 | public static readonly ComponentResourceKey GlyphNormalForegroundKey = new ComponentResourceKey(typeof(ResourceKeys), "GlyphNormalForegroundKey"); 30 | 31 | /// 32 | /// Resource key of the controls normal glyph brush key. 33 | /// 34 | public static readonly ComponentResourceKey GlyphMouseOverForegroundKey = new ComponentResourceKey(typeof(ResourceKeys), "GlyphMouseOverForegroundKey"); 35 | 36 | /// 37 | /// Resource key of the controls disabled glyph brush key. 38 | /// 39 | public static readonly ComponentResourceKey GlyphDisabledForegroundKey = new ComponentResourceKey(typeof(ResourceKeys), "GlyphDisabledForegroundKey"); 40 | 41 | /// 42 | /// Resource key of the controls disabled glyph brush key. 43 | /// 44 | public static readonly ComponentResourceKey GlyphPressedBackroundKey = new ComponentResourceKey(typeof(ResourceKeys), "GlyphPressedBackroundKey"); 45 | #endregion Brush Keys 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/NumericUpDownLib/images/SyncArrow_64x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dirkster99/NumericUpDownLib/0dd9bd8e569736f0192107cfaadd340a7e0aa90e/source/NumericUpDownLib/images/SyncArrow_64x.png -------------------------------------------------------------------------------- /source/TestGenerics/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /source/TestGenerics/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /source/TestGenerics/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace TestGenerics 4 | { 5 | /// 6 | /// Interaction logic for App.xaml 7 | /// 8 | public partial class App : Application 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /source/TestGenerics/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /source/TestGenerics/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace TestGenerics 2 | { 3 | using System.Windows; 4 | using TestGenerics.ViewModel; 5 | 6 | /// 7 | /// Interaction logic for MainWindow.xaml 8 | /// 9 | public partial class MainWindow : Window 10 | { 11 | public MainWindow() 12 | { 13 | InitializeComponent(); 14 | 15 | DataContext = new AppViewModel(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /source/TestGenerics/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 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("TestGenerics")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("Open Source")] 14 | [assembly: AssemblyProduct("TestGenerics")] 15 | [assembly: AssemblyCopyright("Copyright © 2013")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /source/TestGenerics/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 TestGenerics.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.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 | /// Returns the cached ResourceManager instance used by this class. 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("TestGenerics.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 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 | -------------------------------------------------------------------------------- /source/TestGenerics/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 TestGenerics.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.8.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 | -------------------------------------------------------------------------------- /source/TestGenerics/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /source/TestGenerics/TestGenerics.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {BDBB3D84-0268-43E2-BBC6-F5CA2068262E} 8 | WinExe 9 | Properties 10 | TestGenerics 11 | TestGenerics 12 | v4.0 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | Client 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | AnyCPU 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 4.0 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | MSBuild:Compile 55 | Designer 56 | 57 | 58 | 59 | 60 | MSBuild:Compile 61 | Designer 62 | 63 | 64 | App.xaml 65 | Code 66 | 67 | 68 | MainWindow.xaml 69 | Code 70 | 71 | 72 | 73 | 74 | Code 75 | 76 | 77 | True 78 | True 79 | Resources.resx 80 | 81 | 82 | True 83 | Settings.settings 84 | True 85 | 86 | 87 | ResXFileCodeGenerator 88 | Resources.Designer.cs 89 | 90 | 91 | SettingsSingleFileGenerator 92 | Settings.Designer.cs 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | {ed3a742d-4055-4da2-bbce-74e817b211bf} 102 | UpDownDemoLib 103 | 104 | 105 | {e542beed-60f4-48b0-8ac6-24dbfc03b0c4} 106 | NumericUpDownLib 107 | 108 | 109 | 110 | 117 | -------------------------------------------------------------------------------- /source/TestGenerics/ViewModels/Base/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | namespace TestGenerics.ViewModel.Base 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.ComponentModel; 8 | using System.Linq.Expressions; 9 | 10 | public class ViewModelBase : INotifyPropertyChanged 11 | { 12 | 13 | protected virtual void RaisePropertyChanged(string propertyName) 14 | { 15 | if (PropertyChanged != null) 16 | PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 17 | } 18 | 19 | 20 | public event PropertyChangedEventHandler PropertyChanged; 21 | 22 | /// 23 | /// Tell bound controls (via WPF binding) to refresh their display. 24 | /// 25 | /// Sample call: this.NotifyPropertyChanged(() => this.IsSelected); 26 | /// where 'this' is derived from 27 | /// and IsSelected is a property. 28 | /// 29 | /// 30 | /// 31 | public void NotifyPropertyChanged(Expression> property) 32 | { 33 | var lambda = (LambdaExpression)property; 34 | MemberExpression memberExpression; 35 | 36 | if (lambda.Body is UnaryExpression) 37 | { 38 | var unaryExpression = (UnaryExpression)lambda.Body; 39 | memberExpression = (MemberExpression)unaryExpression.Operand; 40 | } 41 | else 42 | memberExpression = (MemberExpression)lambda.Body; 43 | 44 | this.RaisePropertyChanged(memberExpression.Member.Name); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/TestGenerics/ViewModels/DemoViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace TestGenerics.ViewModel 2 | { 3 | using UpDownDemoLib.Demos.ViewModels; 4 | 5 | /// 6 | /// Application Viewmodel class to be bound to MainWindow... 7 | /// 8 | public class AppViewModel : Base.ViewModelBase 9 | { 10 | public AppViewModel() 11 | { 12 | Demo = new DemoViewModel(); 13 | } 14 | 15 | public DemoViewModel Demo { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /source/TestThemes/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /source/TestThemes/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | -------------------------------------------------------------------------------- /source/TestThemes/AppLocalResources.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /source/TestThemes/Behaviors/SelectionChangedBehavior.cs: -------------------------------------------------------------------------------- 1 | namespace TestThemes.Behaviors 2 | { 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Controls.Primitives; 6 | using System.Windows.Input; 7 | 8 | /// 9 | /// Attached behaviour to implement a selection changed command on a Selector (combobox). 10 | /// The Selector (combobox) generates a SelectionChanged event which in turn generates a 11 | /// Command (in this behavior), which in turn is, when bound, invoked on the viewmodel. 12 | /// 13 | public static class SelectionChangedCommand 14 | { 15 | // Field of attached ICommand property 16 | private static readonly DependencyProperty ChangedCommandProperty = DependencyProperty.RegisterAttached( 17 | "ChangedCommand", 18 | typeof(ICommand), 19 | typeof(SelectionChangedCommand), 20 | new PropertyMetadata(null, OnSelectionChangedCommandChange)); 21 | 22 | /// 23 | /// Setter method of the attached DropCommand property 24 | /// 25 | /// 26 | /// 27 | public static void SetChangedCommand(DependencyObject source, ICommand value) 28 | { 29 | source.SetValue(ChangedCommandProperty, value); 30 | } 31 | 32 | /// 33 | /// Getter method of the attached DropCommand property 34 | /// 35 | /// 36 | /// 37 | public static ICommand GetChangedCommand(DependencyObject source) 38 | { 39 | return (ICommand)source.GetValue(ChangedCommandProperty); 40 | } 41 | 42 | /// 43 | /// This method is hooked in the definition of the . 44 | /// It is called whenever the attached property changes - in our case the event of binding 45 | /// and unbinding the property to a sink is what we are looking for. 46 | /// 47 | /// 48 | /// 49 | private static void OnSelectionChangedCommandChange(DependencyObject d, DependencyPropertyChangedEventArgs e) 50 | { 51 | Selector uiElement = d as Selector; // Remove the handler if it exist to avoid memory leaks 52 | 53 | if (uiElement != null) 54 | { 55 | uiElement.SelectionChanged -= Selection_Changed; 56 | uiElement.KeyUp -= uiElement_KeyUp; 57 | 58 | var command = e.NewValue as ICommand; 59 | if (command != null) 60 | { 61 | // the property is attached so we attach the Drop event handler 62 | uiElement.SelectionChanged += Selection_Changed; 63 | uiElement.KeyUp += uiElement_KeyUp; 64 | } 65 | } 66 | } 67 | 68 | private static void uiElement_KeyUp(object sender, KeyEventArgs e) 69 | { 70 | if (e == null) 71 | return; 72 | 73 | // Forward key event only if user has hit the return, BackSlash, or Slash key 74 | if (e.Key != Key.Return) 75 | return; 76 | 77 | ComboBox uiElement = sender as ComboBox; 78 | 79 | // Sanity check just in case this was somehow send by something else 80 | if (uiElement == null) 81 | return; 82 | 83 | ICommand changedCommand = SelectionChangedCommand.GetChangedCommand(uiElement); 84 | 85 | // There may not be a command bound to this after all 86 | if (changedCommand == null) 87 | return; 88 | 89 | // Check whether this attached behaviour is bound to a RoutedCommand 90 | if (changedCommand is RoutedCommand) 91 | { 92 | // Execute the routed command 93 | (changedCommand as RoutedCommand).Execute(uiElement.Text, uiElement); 94 | } 95 | else 96 | { 97 | // Execute the Command as bound delegate 98 | changedCommand.Execute(uiElement.Text); 99 | } 100 | } 101 | 102 | /// 103 | /// This method is called when the selection changed event occurs. The sender should be the control 104 | /// on which this behaviour is attached - so we convert the sender into a 105 | /// and receive the Command through the getter listed above. 106 | /// 107 | /// This implementation supports binding of delegate commands and routed commands. 108 | /// 109 | /// 110 | /// 111 | private static void Selection_Changed(object sender, System.Windows.Controls.SelectionChangedEventArgs e) 112 | { 113 | Selector uiElement = sender as Selector; 114 | 115 | // Sanity check just in case this was somehow send by something else 116 | if (uiElement == null) 117 | return; 118 | 119 | ICommand changedCommand = SelectionChangedCommand.GetChangedCommand(uiElement); 120 | 121 | // There may not be a command bound to this after all 122 | if (changedCommand == null) 123 | return; 124 | 125 | // Check whether this attached behaviour is bound to a RoutedCommand 126 | if (changedCommand is RoutedCommand) 127 | { 128 | // Execute the routed command 129 | (changedCommand as RoutedCommand).Execute(e.AddedItems, uiElement); 130 | } 131 | else 132 | { 133 | // Execute the Command as bound delegate 134 | changedCommand.Execute(e.AddedItems); 135 | } 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /source/TestThemes/BindToMLib/MWindowLib/DarkLightBrushs.xaml: -------------------------------------------------------------------------------- 1 |  7 | 11 | Blue 12 | 13 | 18 | 19 | 20 | #FFF4F4F5 21 | 22 | #FF2D2D30 23 | 24 | 29 | 30 | 35 | 36 | 37 | #FF3F3F41 38 | 39 | 44 | 45 | -------------------------------------------------------------------------------- /source/TestThemes/BindToMLib/NumericUpDownLib/DarkLightBrushs.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 12 | #FF1888b8 13 | 14 | 19 | 20 | 21 | 22 | 26 | 27 | 32 | -------------------------------------------------------------------------------- /source/TestThemes/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 38 | 39 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /source/TestThemes/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace TestThemes 2 | { 3 | using Settings.UserProfile; 4 | using ViewModels; 5 | 6 | /// 7 | /// Interaction logic for MainWindow.xaml 8 | /// 9 | public partial class MainWindow : MWindowLib.MetroWindow 10 | , IViewSize // Implements saving and loading/repositioning of Window 11 | { 12 | public MainWindow() 13 | { 14 | InitializeComponent(); 15 | Loaded += MainWindow_Loaded; 16 | } 17 | 18 | private void MainWindow_Loaded(object sender, System.Windows.RoutedEventArgs e) 19 | { 20 | Loaded -= MainWindow_Loaded; 21 | 22 | var viewModel = this.DataContext as AppViewModel; 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /source/TestThemes/Models/AppCore.cs: -------------------------------------------------------------------------------- 1 | namespace TestThemes.Models 2 | { 3 | using System; 4 | using System.Globalization; 5 | using System.Reflection; 6 | 7 | /// 8 | /// Class supplies a set of common static helper methodes that help 9 | /// localizing application specific items such as setting folders etc. 10 | /// 11 | public class AppCore 12 | { 13 | #region properties 14 | /// 15 | /// Get the name of the executing assembly (usually name of *.exe file) 16 | /// 17 | internal static string AssemblyTitle 18 | { 19 | get 20 | { 21 | return Assembly.GetEntryAssembly().GetName().Name; 22 | } 23 | } 24 | 25 | // 26 | // Summary: 27 | // Gets the path or UNC location of the loaded file that contains the manifest. 28 | // 29 | // Returns: 30 | // The location of the loaded file that contains the manifest. If the loaded 31 | // file was shadow-copied, the location is that of the file after being shadow-copied. 32 | // If the assembly is loaded from a byte array, such as when using the System.Reflection.Assembly.Load(System.Byte[]) 33 | // method overload, the value returned is an empty string (""). 34 | internal static string AssemblyEntryLocation 35 | { 36 | get 37 | { 38 | return System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); 39 | } 40 | } 41 | 42 | /// 43 | /// Get a path to the directory where the user store his documents 44 | /// 45 | public static string MyDocumentsUserDir 46 | { 47 | get 48 | { 49 | return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 50 | } 51 | } 52 | 53 | public static string Company 54 | { 55 | get 56 | { 57 | return "TestThemes"; 58 | } 59 | } 60 | public static string Application_Title 61 | { 62 | get 63 | { 64 | return "TestThemes"; 65 | } 66 | } 67 | 68 | /// 69 | /// Get a path to the directory where the application 70 | /// can persist/load user data on session exit and re-start. 71 | /// 72 | public static string DirAppData 73 | { 74 | get 75 | { 76 | return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + 77 | System.IO.Path.DirectorySeparatorChar + 78 | AppCore.Company; 79 | } 80 | } 81 | 82 | //// /// 83 | //// /// Get path and file name to application specific settings file 84 | //// /// 85 | //// public static string DirFileAppSettingsData 86 | //// { 87 | //// get 88 | //// { 89 | //// return System.IO.Path.Combine(AppCore.DirAppData, 90 | //// string.Format(CultureInfo.InvariantCulture, "{0}.App.settings", AppCore.AssemblyTitle)); 91 | //// } 92 | //// } 93 | 94 | /// 95 | /// Get path and file name to application specific session file 96 | /// 97 | public static string DirFileAppSessionData 98 | { 99 | get 100 | { 101 | return System.IO.Path.Combine(AppCore.DirAppData, 102 | string.Format(CultureInfo.InvariantCulture, "{0}.App.session", AppCore.AssemblyTitle)); 103 | } 104 | } 105 | #endregion properties 106 | 107 | #region methods 108 | /// 109 | /// Create a dedicated directory to store program settings and session data 110 | /// 111 | /// 112 | public static bool CreateAppDataFolder() 113 | { 114 | try 115 | { 116 | if (System.IO.Directory.Exists(AppCore.DirAppData) == false) 117 | System.IO.Directory.CreateDirectory(AppCore.DirAppData); 118 | } 119 | catch 120 | { 121 | return false; 122 | } 123 | 124 | return true; 125 | } 126 | #endregion methods 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /source/TestThemes/Models/SettingDefaults.cs: -------------------------------------------------------------------------------- 1 | namespace TestThemes.Models 2 | { 3 | using Settings.Interfaces; 4 | using SettingsModel.Interfaces; 5 | using System.Windows.Media; 6 | 7 | /// 8 | /// Class contains all methods necessary to initialize the applications settings model. 9 | /// 10 | internal static class SettingDefaults 11 | { 12 | /// 13 | /// Create the minimal settings model that should be used for every application. 14 | /// This model does not include advanced features like theming etc... 15 | /// 16 | /// 17 | public static void CreateGeneralSettings(IEngine options) 18 | { 19 | const string groupName = "Options"; 20 | 21 | options.AddOption(groupName, "ReloadOpenFilesFromLastSession", typeof(bool), false, true); 22 | options.AddOption(groupName, "SourceFilePath", typeof(string), false, @"C:\temp\source\"); 23 | options.AddOption(groupName, "LanguageSelected", typeof(string), false, "en-US"); 24 | 25 | // var schema = optsEngine.AddListOption(groupName, "BookmarkedFolders", typeof(string), false, new List()); 26 | // schema.List_AddValue(@"C:\TEMP", @"C:\TEMP"); 27 | // schema.List_AddValue(@"C:\Windows", @"C:\Windows"); 28 | } 29 | 30 | /// 31 | /// Create the minimal settings model that should be used for every application. 32 | /// 33 | /// 34 | public static void CreateAppearanceSettings(IEngine options, ISettingsManager settings) 35 | { 36 | const string groupName = "Appearance"; 37 | 38 | options.AddOption(groupName, "ThemeDisplayName", typeof(string), false, "Dark"); 39 | options.AddOption(groupName, "ApplyWindowsDefaultAccent", typeof(bool), false, true); 40 | options.AddOption(groupName, "AccentColor", typeof(Color), false, Color.FromRgb(0x33, 0x99, 0xff)); 41 | 42 | // options.AddOption(groupName, "DefaultIconSize", typeof(int), false, settings.DefaultIconSize); 43 | // options.AddOption(groupName, "DefaultFontSize", typeof(int), false, settings.DefaultFontSize); 44 | // options.AddOption(groupName, "FixedFontSize", typeof(int), false, settings.DefaultFixedFontSize); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/TestThemes/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 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("TestThemes")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("TestThemes")] 15 | [assembly: AssemblyCopyright("Copyright © 2018")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /source/TestThemes/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 TestThemes.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.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 | /// Returns the cached ResourceManager instance used by this class. 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("TestThemes.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 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 | -------------------------------------------------------------------------------- /source/TestThemes/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 TestThemes.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.8.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 | -------------------------------------------------------------------------------- /source/TestThemes/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /source/TestThemes/ServiceInjector.cs: -------------------------------------------------------------------------------- 1 | namespace TestThemes 2 | { 3 | using MLib; 4 | using MLib.Interfaces; 5 | using ServiceLocator; 6 | using Settings; 7 | using Settings.Interfaces; 8 | 9 | /// 10 | /// Creates and initializes all services. 11 | /// 12 | public static class ServiceInjector 13 | { 14 | /// 15 | /// Loads service objects into the ServiceContainer on startup of application. 16 | /// 17 | /// Returns the current instance 18 | /// to let caller work with service container items right after creation. 19 | public static ServiceContainer InjectServices() 20 | { 21 | var appearance = AppearanceManager.GetInstance(); 22 | ServiceContainer.Instance.AddService(SettingsManager.GetInstance(appearance.CreateThemeInfos())); 23 | ServiceContainer.Instance.AddService(appearance); 24 | 25 | return ServiceContainer.Instance; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /source/TestThemes/ViewModels/Base/ModelBase.cs: -------------------------------------------------------------------------------- 1 | namespace TestThemes.ViewModels.Base 2 | { 3 | public class ModelBase 4 | { 5 | /// 6 | /// Gets an instance of the service container and retrieves the requested service coponent. 7 | /// 8 | /// 9 | /// 10 | public TServiceContract GetService() where TServiceContract : class 11 | { 12 | return ServiceLocator.ServiceContainer.Instance.GetService(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/TestThemes/ViewModels/Base/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | namespace TestThemes.ViewModels.Base 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | using System.Windows.Input; 6 | 7 | /// 8 | /// A command whose sole purpose is to 9 | /// relay its functionality to other 10 | /// objects by invoking delegates. The 11 | /// default return value for the CanExecute 12 | /// method is 'true'. 13 | /// 14 | /// Source: http://www.codeproject.com/Articles/31837/Creating-an-Internationalized-Wizard-in-WPF 15 | /// 16 | internal class RelayCommand : ICommand 17 | { 18 | #region Fields 19 | private readonly Action mExecute = null; 20 | private readonly Predicate mCanExecute = null; 21 | #endregion // Fields 22 | 23 | #region Constructors 24 | /// 25 | /// Class constructor 26 | /// 27 | /// 28 | public RelayCommand(Action execute) 29 | : this(execute, null) 30 | { 31 | } 32 | 33 | /// 34 | /// Creates a new command. 35 | /// 36 | /// The execution logic. 37 | /// The execution status logic. 38 | public RelayCommand(Action execute, Predicate canExecute) 39 | { 40 | if (execute == null) 41 | throw new ArgumentNullException("execute"); 42 | 43 | this.mExecute = execute; 44 | this.mCanExecute = canExecute; 45 | } 46 | 47 | #endregion // Constructors 48 | 49 | #region events 50 | /// 51 | /// Eventhandler to re-evaluate whether this command can execute or not 52 | /// 53 | public event EventHandler CanExecuteChanged 54 | { 55 | add 56 | { 57 | if (this.mCanExecute != null) 58 | CommandManager.RequerySuggested += value; 59 | } 60 | 61 | remove 62 | { 63 | if (this.mCanExecute != null) 64 | CommandManager.RequerySuggested -= value; 65 | } 66 | } 67 | #endregion 68 | 69 | #region methods 70 | /// 71 | /// Determine whether this pre-requisites to execute this command are given or not. 72 | /// 73 | /// 74 | /// 75 | [DebuggerStepThrough] 76 | public bool CanExecute(object parameter) 77 | { 78 | return this.mCanExecute == null ? true : this.mCanExecute((T)parameter); 79 | } 80 | 81 | /// 82 | /// Execute the command method managed in this class. 83 | /// 84 | /// 85 | public void Execute(object parameter) 86 | { 87 | this.mExecute((T)parameter); 88 | } 89 | #endregion methods 90 | } 91 | 92 | /// 93 | /// A command whose sole purpose is to 94 | /// relay its functionality to other 95 | /// objects by invoking delegates. The 96 | /// default return value for the CanExecute 97 | /// method is 'true'. 98 | /// 99 | internal class RelayCommand : ICommand 100 | { 101 | #region Fields 102 | private readonly Action mExecute; 103 | private readonly Func mCanExecute; 104 | #endregion Fields 105 | 106 | #region Constructors 107 | 108 | /// 109 | /// Creates a new command that can always execute. 110 | /// 111 | /// The execution logic. 112 | public RelayCommand(Action execute) 113 | : this(execute, null) 114 | { 115 | } 116 | 117 | /// 118 | /// Copy constructor 119 | /// 120 | /// 121 | public RelayCommand(RelayCommand inputRC) 122 | : this(inputRC.mExecute, inputRC.mCanExecute) 123 | { 124 | } 125 | 126 | /// 127 | /// Creates a new command. 128 | /// 129 | /// The execution logic. 130 | /// The execution status logic. 131 | public RelayCommand(Action execute, Func canExecute) 132 | { 133 | if (execute == null) 134 | throw new ArgumentNullException("execute"); 135 | 136 | this.mExecute = execute; 137 | this.mCanExecute = canExecute; 138 | } 139 | 140 | #endregion Constructors 141 | 142 | #region Events 143 | /// 144 | /// Eventhandler to re-evaluate whether this command can execute or not 145 | /// 146 | public event EventHandler CanExecuteChanged 147 | { 148 | add 149 | { 150 | if (this.mCanExecute != null) 151 | CommandManager.RequerySuggested += value; 152 | } 153 | 154 | remove 155 | { 156 | if (this.mCanExecute != null) 157 | CommandManager.RequerySuggested -= value; 158 | } 159 | } 160 | #endregion Events 161 | 162 | #region Methods 163 | /// 164 | /// Execute the attached CanExecute methode delegate (or always return true) 165 | /// to determine whether the command managed in this object can execute or not. 166 | /// 167 | /// 168 | /// 169 | [DebuggerStepThrough] 170 | public bool CanExecute(object parameter) 171 | { 172 | return this.mCanExecute == null ? true : this.mCanExecute(); 173 | } 174 | 175 | /// 176 | /// Return the attached delegate method. 177 | /// 178 | /// 179 | public void Execute(object parameter) 180 | { 181 | this.mExecute(); 182 | } 183 | #endregion Methods 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /source/TestThemes/ViewModels/Base/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | namespace TestThemes.ViewModels.Base 2 | { 3 | using System; 4 | using System.ComponentModel; 5 | using System.Linq.Expressions; 6 | 7 | /// 8 | /// Implements a base class for all viewmodel classes 9 | /// that implements interface for binding. 10 | /// 11 | public class ViewModelBase : ModelBase, INotifyPropertyChanged 12 | { 13 | /// 14 | /// Standard implementation of . 15 | /// 16 | public event PropertyChangedEventHandler PropertyChanged; 17 | 18 | /// 19 | /// Tell bound controls (via WPF binding) to refresh their display. 20 | /// 21 | /// Sample call: this.NotifyPropertyChanged(() => this.IsSelected); 22 | /// where 'this' is derived from 23 | /// and IsSelected is a property. 24 | /// 25 | /// 26 | /// 27 | public void NotifyPropertyChanged(Expression> property) 28 | { 29 | var lambda = (LambdaExpression)property; 30 | MemberExpression memberExpression; 31 | 32 | if (lambda.Body is UnaryExpression) 33 | { 34 | var unaryExpression = (UnaryExpression)lambda.Body; 35 | memberExpression = (MemberExpression)unaryExpression.Operand; 36 | } 37 | else 38 | memberExpression = (MemberExpression)lambda.Body; 39 | 40 | this.NotifyPropertyChanged(memberExpression.Member.Name); 41 | } 42 | 43 | /// 44 | /// Tell bound controls (via WPF binding) to refresh their display. 45 | /// Standard implementation through . 46 | /// 47 | /// 48 | protected virtual void NotifyPropertyChanged(string propertyName) 49 | { 50 | if (this.PropertyChanged != null) 51 | this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /source/TestThemes/ViewModels/ThemeDefinitionViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace TestThemes.ViewModels 2 | { 3 | using MLib.Interfaces; 4 | 5 | public class ThemeDefinitionViewModel : Base.ViewModelBase 6 | { 7 | #region private fields 8 | readonly private IThemeInfo _model; 9 | 10 | private bool _IsSelected; 11 | #endregion private fields 12 | 13 | #region constructors 14 | /// 15 | /// Class constructor 16 | /// 17 | /// 18 | public ThemeDefinitionViewModel(IThemeInfo model) 19 | : this() 20 | { 21 | _model = model; 22 | } 23 | 24 | /// 25 | /// Hidden class constructor 26 | /// 27 | protected ThemeDefinitionViewModel() 28 | { 29 | _model = null; 30 | _IsSelected = false; 31 | } 32 | #endregion constructors 33 | 34 | #region properties 35 | /// 36 | /// Gets the static theme model based data items. 37 | /// 38 | public IThemeInfo Model 39 | { 40 | get 41 | { 42 | return _model; 43 | } 44 | } 45 | 46 | /// 47 | /// Determines whether this theme is currently selected or not. 48 | /// 49 | public bool IsSelected 50 | { 51 | get { return _IsSelected; } 52 | 53 | set 54 | { 55 | if (_IsSelected != value) 56 | { 57 | _IsSelected = value; 58 | } 59 | } 60 | } 61 | #endregion properties 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /source/TestThemes/ViewModels/ThemeViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace TestThemes.ViewModels 2 | { 3 | using MLib; 4 | using MLib.Interfaces; 5 | using MLib.Themes; 6 | using Settings.Interfaces; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Windows; 10 | using System.Windows.Media; 11 | 12 | /// 13 | /// ViewModel class that manages theme properties for binding and display in WPF UI. 14 | /// 15 | public class ThemeViewModel : Base.ViewModelBase 16 | { 17 | #region private fields 18 | private readonly ThemeDefinitionViewModel _DefaultTheme = null; 19 | private Dictionary _ListOfThemes = null; 20 | private ThemeDefinitionViewModel _SelectedTheme = null; 21 | private bool _IsEnabled = true; 22 | #endregion private fields 23 | 24 | #region constructors 25 | /// 26 | /// Standard Constructor 27 | /// 28 | public ThemeViewModel() 29 | { 30 | var settings = GetService(); // add the default themes 31 | 32 | _ListOfThemes = new Dictionary(); 33 | 34 | foreach (var item in settings.Themes.GetThemeInfos()) 35 | { 36 | _ListOfThemes.Add(item.DisplayName, new ThemeDefinitionViewModel(item)); 37 | } 38 | 39 | // Lets make sure there is a default 40 | _ListOfThemes.TryGetValue(GetService().GetDefaultTheme().DisplayName, out _DefaultTheme); 41 | 42 | // and something sensible is selected 43 | _SelectedTheme = _DefaultTheme; 44 | _SelectedTheme.IsSelected = true; 45 | } 46 | #endregion constructors 47 | 48 | #region properties 49 | /// 50 | /// Returns a default theme that should be applied when nothing else is available. 51 | /// 52 | public ThemeDefinitionViewModel DefaultTheme 53 | { 54 | get 55 | { 56 | return _DefaultTheme; 57 | } 58 | } 59 | 60 | /// 61 | /// Returns a list of theme definitons. 62 | /// 63 | public List ListOfThemes 64 | { 65 | get 66 | { 67 | return _ListOfThemes.Select(it => it.Value).ToList(); 68 | } 69 | } 70 | 71 | /// 72 | /// Gets the currently selected theme (or desfault on applaiction start-up) 73 | /// 74 | public ThemeDefinitionViewModel SelectedTheme 75 | { 76 | get 77 | { 78 | return _SelectedTheme; 79 | } 80 | 81 | private set 82 | { 83 | if (_SelectedTheme != value) 84 | { 85 | if (_SelectedTheme != null) 86 | _SelectedTheme.IsSelected = false; 87 | 88 | _SelectedTheme = value; 89 | 90 | if (_SelectedTheme != null) 91 | _SelectedTheme.IsSelected = true; 92 | 93 | NotifyPropertyChanged(() => SelectedTheme); 94 | } 95 | } 96 | } 97 | 98 | /// 99 | /// Gets whether a different theme can be selected right now or not. 100 | /// This property should be bound to the UI that selects a different 101 | /// theme to avoid the case in which a user could select a theme and 102 | /// select a different theme while the first theme change request is 103 | /// still processed. 104 | /// 105 | public bool IsEnabled 106 | { 107 | get { return _IsEnabled; } 108 | 109 | private set 110 | { 111 | if (_IsEnabled != value) 112 | { 113 | _IsEnabled = value; 114 | NotifyPropertyChanged(() => IsEnabled); 115 | } 116 | } 117 | } 118 | #endregion properties 119 | 120 | #region methods 121 | /// 122 | /// Applies a new theme based on the changed selection in the input element. 123 | /// 124 | /// 125 | public void ApplyTheme(FrameworkElement fe, string themeName) 126 | { 127 | if (themeName != null) 128 | { 129 | IsEnabled = false; 130 | try 131 | { 132 | var settings = GetService(); // add the default themes 133 | 134 | Color AccentColor = ThemeViewModel.GetCurrentAccentColor(settings); 135 | GetService().SetTheme(settings.Themes, themeName, AccentColor); 136 | 137 | ThemeDefinitionViewModel o; 138 | _ListOfThemes.TryGetValue(themeName, out o); 139 | SelectedTheme = o; 140 | } 141 | catch 142 | { 143 | } 144 | finally 145 | { 146 | IsEnabled = true; 147 | } 148 | } 149 | } 150 | 151 | public static Color GetCurrentAccentColor(ISettingsManager settings) 152 | { 153 | Color AccentColor = default(Color); 154 | 155 | if (settings.Options.GetOptionValue("Appearance", "ApplyWindowsDefaultAccent")) 156 | { 157 | try 158 | { 159 | AccentColor = SystemParameters.WindowGlassColor; 160 | } 161 | catch 162 | { 163 | } 164 | 165 | // This may be black on Windows 7 and the experience is black & white then :-( 166 | if (AccentColor == default(Color) || AccentColor == Colors.Black || AccentColor.A == 0) 167 | AccentColor = Color.FromRgb(0x1b, 0xa1, 0xe2); 168 | } 169 | else 170 | AccentColor = settings.Options.GetOptionValue("Appearance", "AccentColor"); 171 | 172 | return AccentColor; 173 | } 174 | #endregion methods 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /source/TestThemes/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | --------------------------------------------------------------------------------