├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md └── TimsWpfControls ├── TimsWpfControls.sln ├── TimsWpfControls ├── AssemblyInfo.cs ├── Controls │ ├── ArcSegment.cs │ ├── CircularProgressBar.cs │ ├── DataGridIntellisenseTextboxColumn.cs │ ├── FileSelectionTextbox.cs │ ├── IntellisenseTextBox.cs │ └── MultiSelectionComboBox │ │ ├── AddedItemEventArgs.cs │ │ ├── AddingItemEventArgs.cs │ │ ├── BuiltInStringToObjectParser.cs │ │ ├── ICompareObjectToString.cs │ │ ├── IParseStringToObject.cs │ │ ├── MultiSelectionComboBox.cs │ │ └── SelectedItemsOrderType.cs ├── Converter │ ├── ColorToSolidColorBrushConverter.cs │ ├── DataGridIsNewRowToVisibilityConverter.cs │ ├── EnumLocalizedDescriptionConverter.cs │ ├── EnumToBoolConverter.cs │ ├── EnumToItemSourceConverter.cs │ ├── InvertBoolConverter.cs │ ├── NotNullToVisibilityConverter.cs │ ├── NullImageConverter.cs │ ├── PercentageToGridLengthConverter.cs │ └── SolidColorBrushToColorConverter.cs ├── ExtensionMethods │ ├── NumericExtensions.cs │ └── StringExtensions.cs ├── Helper │ ├── BindingHelper.cs │ ├── DataContextProxy.cs │ ├── DialogHelper.cs │ ├── FileHelper.cs │ ├── MultiSelectorHelper.cs │ ├── SolidAccentsLibaryThemeProvider.cs │ ├── ThemingHelper.cs │ └── TreeHelper.cs ├── Lang │ ├── AccentColorNames.Designer.cs │ ├── AccentColorNames.de-DE.resx │ ├── AccentColorNames.resx │ ├── FileSelectionTextBox.Designer.cs │ ├── FileSelectionTextBox.de-DE.resx │ ├── FileSelectionTextBox.resx │ ├── MultiSelectionComboBox.Designer.cs │ ├── MultiSelectionComboBox.de.resx │ ├── MultiSelectionComboBox.resx │ ├── ValidationMessages.Designer.cs │ ├── ValidationMessages.de-DE.resx │ └── ValidationMessages.resx ├── Model │ ├── BaseClass.cs │ ├── LocalizedDescriptionAttribute.cs │ └── RelayCommand.cs ├── PushBinding │ ├── FreezableBinding.cs │ ├── PushBinding.cs │ ├── PushBindingCollection.cs │ └── PushBindingManager.cs ├── Themes │ ├── ArcSegment.xaml │ ├── CircularProgressBar.xaml │ ├── FileSelectionTextBox.xaml │ ├── Generic.xaml │ ├── IntellisenseTextBox.xaml │ ├── MultiSelectionComboBox.xaml │ ├── ScrollViewerWin10.xaml │ └── TimsStyles.xaml ├── TimsWpfControls.csproj └── Validation │ ├── CollectionNotEmptyAttribute.cs │ └── GreaterThanAttribute.cs └── TimsWpfControls_Demo ├── App.xaml ├── App.xaml.cs ├── AssemblyInfo.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Model ├── DemoProperty.cs ├── DemoPropertyTemplateSelector.cs ├── Gender.cs ├── MainViewModel.cs ├── Person.cs └── SelectableProperty.cs ├── TimsWpfControls_Demo.csproj └── Views ├── BoolToEnumConverterExample.xaml ├── BoolToEnumConverterExample.xaml.cs ├── ExampleViewBase.xaml ├── ExampleViewBase.xaml.cs ├── FileSelectionTextBoxExample.xaml ├── FileSelectionTextBoxExample.xaml.cs ├── IntellisenseTextBoxExample.xaml ├── IntellisenseTextBoxExample.xaml.cs ├── MultiselectionComboBox.xaml ├── MultiselectionComboBox.xaml.cs ├── RadialProgressExample.xaml ├── RadialProgressExample.xaml.cs ├── ThemeManger.xaml └── ThemeManger.xaml.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # JustCode is a .NET coding add-in 131 | .JustCode 132 | 133 | # TeamCity is a build add-in 134 | _TeamCity* 135 | 136 | # DotCover is a Code Coverage Tool 137 | *.dotCover 138 | 139 | # AxoCover is a Code Coverage Tool 140 | .axoCover/* 141 | !.axoCover/settings.json 142 | 143 | # Visual Studio code coverage results 144 | *.coverage 145 | *.coveragexml 146 | 147 | # NCrunch 148 | _NCrunch_* 149 | .*crunch*.local.xml 150 | nCrunchTemp_* 151 | 152 | # MightyMoose 153 | *.mm.* 154 | AutoTest.Net/ 155 | 156 | # Web workbench (sass) 157 | .sass-cache/ 158 | 159 | # Installshield output folder 160 | [Ee]xpress/ 161 | 162 | # DocProject is a documentation generator add-in 163 | DocProject/buildhelp/ 164 | DocProject/Help/*.HxT 165 | DocProject/Help/*.HxC 166 | DocProject/Help/*.hhc 167 | DocProject/Help/*.hhk 168 | DocProject/Help/*.hhp 169 | DocProject/Help/Html2 170 | DocProject/Help/html 171 | 172 | # Click-Once directory 173 | publish/ 174 | 175 | # Publish Web Output 176 | *.[Pp]ublish.xml 177 | *.azurePubxml 178 | # Note: Comment the next line if you want to checkin your web deploy settings, 179 | # but database connection strings (with potential passwords) will be unencrypted 180 | *.pubxml 181 | *.publishproj 182 | 183 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 184 | # checkin your Azure Web App publish settings, but sensitive information contained 185 | # in these scripts will be unencrypted 186 | PublishScripts/ 187 | 188 | # NuGet Packages 189 | *.nupkg 190 | # NuGet Symbol Packages 191 | *.snupkg 192 | # The packages folder can be ignored because of Package Restore 193 | **/[Pp]ackages/* 194 | # except build/, which is used as an MSBuild target. 195 | !**/[Pp]ackages/build/ 196 | # Uncomment if necessary however generally it will be regenerated when needed 197 | #!**/[Pp]ackages/repositories.config 198 | # NuGet v3's project.json files produces more ignorable files 199 | *.nuget.props 200 | *.nuget.targets 201 | 202 | # Microsoft Azure Build Output 203 | csx/ 204 | *.build.csdef 205 | 206 | # Microsoft Azure Emulator 207 | ecf/ 208 | rcf/ 209 | 210 | # Windows Store app package directories and files 211 | AppPackages/ 212 | BundleArtifacts/ 213 | Package.StoreAssociation.xml 214 | _pkginfo.txt 215 | *.appx 216 | *.appxbundle 217 | *.appxupload 218 | 219 | # Visual Studio cache files 220 | # files ending in .cache can be ignored 221 | *.[Cc]ache 222 | # but keep track of directories ending in .cache 223 | !?*.[Cc]ache/ 224 | 225 | # Others 226 | ClientBin/ 227 | ~$* 228 | *~ 229 | *.dbmdl 230 | *.dbproj.schemaview 231 | *.jfm 232 | *.pfx 233 | *.publishsettings 234 | orleans.codegen.cs 235 | 236 | # Including strong name files can present a security risk 237 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 238 | #*.snk 239 | 240 | # Since there are multiple workflows, uncomment next line to ignore bower_components 241 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 242 | #bower_components/ 243 | 244 | # RIA/Silverlight projects 245 | Generated_Code/ 246 | 247 | # Backup & report files from converting an old project file 248 | # to a newer Visual Studio version. Backup files are not needed, 249 | # because we have git ;-) 250 | _UpgradeReport_Files/ 251 | Backup*/ 252 | UpgradeLog*.XML 253 | UpgradeLog*.htm 254 | ServiceFabricBackup/ 255 | *.rptproj.bak 256 | 257 | # SQL Server files 258 | *.mdf 259 | *.ldf 260 | *.ndf 261 | 262 | # Business Intelligence projects 263 | *.rdl.data 264 | *.bim.layout 265 | *.bim_*.settings 266 | *.rptproj.rsuser 267 | *- [Bb]ackup.rdl 268 | *- [Bb]ackup ([0-9]).rdl 269 | *- [Bb]ackup ([0-9][0-9]).rdl 270 | 271 | # Microsoft Fakes 272 | FakesAssemblies/ 273 | 274 | # GhostDoc plugin setting file 275 | *.GhostDoc.xml 276 | 277 | # Node.js Tools for Visual Studio 278 | .ntvs_analysis.dat 279 | node_modules/ 280 | 281 | # Visual Studio 6 build log 282 | *.plg 283 | 284 | # Visual Studio 6 workspace options file 285 | *.opt 286 | 287 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 288 | *.vbw 289 | 290 | # Visual Studio LightSwitch build output 291 | **/*.HTMLClient/GeneratedArtifacts 292 | **/*.DesktopClient/GeneratedArtifacts 293 | **/*.DesktopClient/ModelManifest.xml 294 | **/*.Server/GeneratedArtifacts 295 | **/*.Server/ModelManifest.xml 296 | _Pvt_Extensions 297 | 298 | # Paket dependency manager 299 | .paket/paket.exe 300 | paket-files/ 301 | 302 | # FAKE - F# Make 303 | .fake/ 304 | 305 | # CodeRush personal settings 306 | .cr/personal 307 | 308 | # Python Tools for Visual Studio (PTVS) 309 | __pycache__/ 310 | *.pyc 311 | 312 | # Cake - Uncomment if you are using it 313 | # tools/** 314 | # !tools/packages.config 315 | 316 | # Tabs Studio 317 | *.tss 318 | 319 | # Telerik's JustMock configuration file 320 | *.jmconfig 321 | 322 | # BizTalk build output 323 | *.btp.cs 324 | *.btm.cs 325 | *.odx.cs 326 | *.xsd.cs 327 | 328 | # OpenCover UI analysis results 329 | OpenCover/ 330 | 331 | # Azure Stream Analytics local run output 332 | ASALocalRun/ 333 | 334 | # MSBuild Binary and Structured Log 335 | *.binlog 336 | 337 | # NVidia Nsight GPU debugger configuration file 338 | *.nvuser 339 | 340 | # MFractors (Xamarin productivity tool) working folder 341 | .mfractor/ 342 | 343 | # Local History for Visual Studio 344 | .localhistory/ 345 | 346 | # BeatPulse healthcheck temp database 347 | healthchecksdb 348 | 349 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 350 | MigrationBackup/ 351 | 352 | # Ionide (cross platform F# VS Code tools) working folder 353 | .ionide/ 354 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Tim 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TimsWpfControls 2 | Some missing WPF Controls that integrates with MahApps.Metro 3 | 4 | > **ATTENTION** This libary may not be production ready 5 | 6 | ## MahApps-Integration 7 | Whenever a control is implemented in MahApps it will be removed here. Please Stay tuned if you use this library. 8 | 9 | ## Disclaimer 10 | This libary is provided without any warrenty. It will change to whatever I need, so there might be some breaking changes when you update. 11 | 12 | ## BaseClass 13 | The `BaseClass` implements `INotifyPropertyChanged, INotifyPropertyChanging, INotifyDataErrorInfo` and can be used to autmatically set and validate any property. 14 | This class will be deleted once the WindowsCommunityToolkit-MVVM package is available and provides the same functionallity. 15 | 16 | 17 | ## Converters 18 | 19 | ### EnumToBool Converter 20 | This converter can be used to bind an `enum` to a group of `RadioButtons` 21 | 22 | Consider the following `enum` in your Model: 23 | ```c# 24 | public enum Gender 25 | { 26 | Female, 27 | Male, 28 | Diverse 29 | } 30 | ``` 31 | 32 | In your XAML define these namespaces: 33 | ```xaml 34 | xmlns:timsConverter="clr-namespace:TimsWpfControls.Converter;assembly=TimsWpfControls" 35 | xmlns:model="MyApp.MyModel" 36 | ``` 37 | 38 | And here is your group of `RadioButtons` 39 | 40 | ```xaml 41 | 42 | 45 | 48 | 51 | 52 | ``` -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29709.97 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimsWpfControls", "TimsWpfControls\TimsWpfControls.csproj", "{36D58E2D-90FC-4201-AAC7-613439D4470D}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimsWpfControls_Demo", "TimsWpfControls_Demo\TimsWpfControls_Demo.csproj", "{2F70D8D7-6324-434A-8AB0-2B3D68185CDA}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {36D58E2D-90FC-4201-AAC7-613439D4470D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {36D58E2D-90FC-4201-AAC7-613439D4470D}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {36D58E2D-90FC-4201-AAC7-613439D4470D}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {36D58E2D-90FC-4201-AAC7-613439D4470D}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {2F70D8D7-6324-434A-8AB0-2B3D68185CDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {2F70D8D7-6324-434A-8AB0-2B3D68185CDA}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {2F70D8D7-6324-434A-8AB0-2B3D68185CDA}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {2F70D8D7-6324-434A-8AB0-2B3D68185CDA}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {11E149C8-9661-4B83-9BF7-DF676FE54792} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Markup; 3 | 4 | [assembly: ThemeInfo( 5 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 6 | //(used if a resource is not found in the page, 7 | // or application resource dictionaries) 8 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 9 | //(used if a resource is not found in the page, 10 | // app, or any theme specific resource dictionaries) 11 | )] 12 | 13 | 14 | [assembly: XmlnsPrefix(@"https://github.com/timunie/TimsWpfControls", "timsWpf")] 15 | [assembly: XmlnsDefinition(@"https://github.com/timunie/TimsWpfControls", "TimsWpfControls")] 16 | [assembly: XmlnsDefinition(@"https://github.com/timunie/TimsWpfControls", "TimsWpfControls.Converter")] -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Controls/ArcSegment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Media; 9 | using TimsWpfControls.ExtensionMethods; 10 | 11 | namespace TimsWpfControls 12 | { 13 | public class ArcSegment : Control 14 | { 15 | static ArcSegment() 16 | { 17 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ArcSegment), new FrameworkPropertyMetadata(typeof(ArcSegment))); 18 | } 19 | 20 | private PathFigure PART_ArcSegment; 21 | 22 | public static readonly DependencyProperty StartDegreesProperty = DependencyProperty.Register("StartDegrees", typeof(double), typeof(ArcSegment), new FrameworkPropertyMetadata(-90d, FrameworkPropertyMetadataOptions.AffectsRender)); 23 | public static readonly DependencyProperty SweepDegreesProperty = DependencyProperty.Register("SweepDegrees", typeof(double), typeof(ArcSegment), new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender)); 24 | public static readonly DependencyProperty StrokeThicknessProperty = DependencyProperty.Register("StrokeThickness", typeof(double), typeof(ArcSegment), new FrameworkPropertyMetadata(5d, FrameworkPropertyMetadataOptions.AffectsRender)); 25 | public static readonly DependencyProperty IsFilledProperty = DependencyProperty.Register("IsFilled", typeof(bool), typeof(ArcSegment), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); 26 | 27 | public double StartDegrees 28 | { 29 | get { return (double)GetValue(StartDegreesProperty); } 30 | set { SetValue(StartDegreesProperty, value); } 31 | } 32 | 33 | 34 | public double SweepDegrees 35 | { 36 | get { return (double)GetValue(SweepDegreesProperty); } 37 | set { SetValue(SweepDegreesProperty, value); } 38 | } 39 | 40 | 41 | public double StrokeThickness 42 | { 43 | get { return (double)GetValue(StrokeThicknessProperty); } 44 | set { SetValue(StrokeThicknessProperty, value); } 45 | } 46 | 47 | public bool IsFilled 48 | { 49 | get { return (bool)GetValue(IsFilledProperty); } 50 | set { SetValue(IsFilledProperty, value); } 51 | } 52 | 53 | private void UpdateArcSegment() 54 | { 55 | if (PART_ArcSegment is null) return; 56 | 57 | // degrees to radians conversion 58 | double startRadians = StartDegrees * Math.PI / 180.0; 59 | double sweepRadians = SweepDegrees * Math.PI / 180.0; 60 | 61 | // x and y radius 62 | double dx = (ActualWidth - StrokeThickness) / 2; 63 | double dy = (ActualHeight - StrokeThickness) / 2; 64 | 65 | dx = dx < 0 ? 0 : dx; 66 | dy = dy < 0 ? 0 : dy; 67 | 68 | Size EllipseSize = new Size(dx, dy); 69 | 70 | // determine the start point 71 | Point StartPoint = new Point(ActualWidth / 2 + Math.Cos(startRadians) * dx, 72 | ActualHeight / 2 + Math.Sin(startRadians) * dy); 73 | 74 | // determine the end point 75 | Point EndPoint = new Point(ActualWidth / 2 + Math.Cos(startRadians + sweepRadians) * dx, 76 | ActualHeight / 2 + Math.Sin(startRadians + sweepRadians) * dy); 77 | 78 | // draw the arc 79 | bool isLargeArc = Math.Abs(SweepDegrees) > 180; 80 | SweepDirection sweepDirection = SweepDegrees < 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise; 81 | 82 | PART_ArcSegment.Segments.Clear(); 83 | PART_ArcSegment.StartPoint = StartPoint; 84 | if (SweepDegrees.ApproximateEqualTo(360)) 85 | { 86 | EndPoint = new Point(ActualWidth / 2 + Math.Cos(startRadians + Math.PI) * dx, 87 | ActualHeight / 2 + Math.Sin(startRadians + Math.PI) * dy); 88 | PART_ArcSegment.Segments.Add(new System.Windows.Media.ArcSegment(EndPoint, EllipseSize, 0, false, sweepDirection, true)); 89 | PART_ArcSegment.Segments.Add(new System.Windows.Media.ArcSegment(StartPoint, EllipseSize, 0, true, sweepDirection, true)); 90 | } 91 | else if (SweepDegrees.ApproximateEqualTo(0)) 92 | { 93 | // Do not draw anyting if there is nothing to see 94 | } 95 | else 96 | { 97 | PART_ArcSegment.Segments.Add(new System.Windows.Media.ArcSegment(EndPoint, EllipseSize, 0, isLargeArc, sweepDirection, true)); 98 | if (IsFilled) 99 | { 100 | PART_ArcSegment.Segments.Add(new LineSegment(new Point(dx + StrokeThickness / 2, dy + StrokeThickness / 2), true)); 101 | PART_ArcSegment.Segments.Add(new LineSegment(StartPoint, true)); 102 | } 103 | } 104 | } 105 | 106 | 107 | public override void OnApplyTemplate() 108 | { 109 | base.OnApplyTemplate(); 110 | 111 | PART_ArcSegment = (PathFigure)GetTemplateChild(nameof(PART_ArcSegment)); 112 | } 113 | 114 | protected override void OnRender(DrawingContext drawingContext) 115 | { 116 | UpdateArcSegment(); 117 | base.OnRender(drawingContext); 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Controls/MultiSelectionComboBox/AddedItemEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace TimsWpfControls 10 | { 11 | /// 12 | /// Provides data for the 13 | /// 14 | public class AddedItemEventArgs : RoutedEventArgs 15 | { 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | /// The AddedItemEvent/param> 20 | /// The source object 21 | /// The added object 22 | /// The target where the should be added 23 | public AddedItemEventArgs(RoutedEvent routedEvent, 24 | object source, 25 | object addedItem, 26 | IList targetList) : base(routedEvent, source) 27 | { 28 | AddedItem = addedItem; 29 | TargetList = targetList; 30 | } 31 | 32 | /// 33 | /// Gets the added item 34 | /// 35 | public object AddedItem { get; } 36 | 37 | /// 38 | /// Gets the where the was added to 39 | /// 40 | public IList TargetList { get; } 41 | } 42 | 43 | /// 44 | /// RoutedEventHandler used for the . 45 | /// 46 | public delegate void AddedItemEventArgsHandler(object sender, AddedItemEventArgs args); 47 | } 48 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Controls/MultiSelectionComboBox/AddingItemEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Globalization; 4 | using System.Windows; 5 | 6 | namespace TimsWpfControls 7 | { 8 | /// 9 | /// Provides data for the 10 | /// 11 | public class AddingItemEventArgs : RoutedEventArgs 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The AddingItemEvent/param> 17 | /// The source object 18 | /// The input string to parse 19 | /// The parsed object 20 | /// if the is accepted otherwise /param> 21 | /// The target where the should be added 22 | /// the target to which the should be converted to 23 | /// the string format which can be used to control the 24 | /// the culture which can be used to control the 25 | /// The used parser 26 | public AddingItemEventArgs(RoutedEvent routedEvent, 27 | object source, 28 | string input, 29 | object parsedObject, 30 | bool accepted, 31 | IList targetList, 32 | Type targetType, 33 | string stringFormat, 34 | CultureInfo culture, 35 | IParseStringToObject parser) : base(routedEvent, source) 36 | { 37 | Input = input; 38 | ParsedObject = parsedObject; 39 | Accepted = accepted; 40 | TargetList = targetList; 41 | TargetType = targetType; 42 | StringFormat = stringFormat; 43 | Culture = culture; 44 | Parser = parser; 45 | } 46 | 47 | /// 48 | /// The Textinput to parse 49 | /// 50 | public string Input { get; } 51 | 52 | /// 53 | /// Gets or sets the parsed object to add. You can override it 54 | /// 55 | public object ParsedObject { get; set; } 56 | 57 | /// 58 | /// Gets the string format which can be used to control the 59 | /// 60 | public string StringFormat { get; } 61 | 62 | /// 63 | /// Gets the culture which can be used to control the 64 | /// 65 | public CultureInfo Culture { get; } 66 | 67 | /// 68 | /// Gets the -Instance which was used to parse the to the 69 | /// 70 | public IParseStringToObject Parser { get; } 71 | 72 | /// 73 | /// Gets the target to which the should be converted to 74 | /// 75 | public Type TargetType { get; } 76 | 77 | /// 78 | /// Gets the where the should be added 79 | /// 80 | public IList TargetList { get; } 81 | 82 | /// 83 | /// Gets or sets wether the is accepted and can be added 84 | /// 85 | public bool Accepted { get; set; } 86 | } 87 | 88 | /// 89 | /// RoutedEventHandler used for the . 90 | /// 91 | public delegate void AddingItemEventArgsHandler(object sender, AddingItemEventArgs args); 92 | } 93 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Controls/MultiSelectionComboBox/BuiltInStringToObjectParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Globalization; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace TimsWpfControls 11 | { 12 | /// 13 | /// This class is a helper class for the . 14 | /// It uses the for the elements . If you need more control 15 | /// over the conversion you should create your own class which implements 16 | /// 17 | public class BuiltInStringToObjectParser : IParseStringToObject 18 | { 19 | private static BuiltInStringToObjectParser instance; 20 | public static BuiltInStringToObjectParser Instance => instance ??= new BuiltInStringToObjectParser(); 21 | 22 | public bool TryCreateObjectFromString(string input, out object result, CultureInfo culture = null, string stringFormat = null, Type targetType = null) 23 | { 24 | try 25 | { 26 | // If the input is null the result is also null 27 | if (input is null) 28 | { 29 | result = null; 30 | return true; 31 | } 32 | 33 | // If we don't know the target type we cannot convert in this class. Either provide the target type or roll your own class implementing IParseStringToObject 34 | if (targetType is null) 35 | { 36 | result = null; 37 | return false; 38 | } 39 | 40 | var typeConverter = TypeDescriptor.GetConverter(targetType); 41 | 42 | if (!(typeConverter is null)) 43 | { 44 | result = typeConverter.ConvertFromString(null, culture ?? CultureInfo.InvariantCulture, input); 45 | return true; 46 | } 47 | else 48 | { 49 | result = null; 50 | return false; 51 | } 52 | } 53 | catch 54 | { 55 | result = null; 56 | return false; 57 | } 58 | } 59 | 60 | 61 | /// 62 | /// Tries to get the elemts for a given 63 | /// 64 | /// Any collection of elements 65 | /// the elements 66 | public Type GetElementType(IEnumerable list) 67 | { 68 | if (list is null) 69 | { 70 | return null; 71 | } 72 | 73 | var listType = list.GetType(); 74 | 75 | if (listType.IsGenericType) 76 | { 77 | return listType.GetGenericArguments().FirstOrDefault(); 78 | } 79 | else 80 | { 81 | return listType.GetElementType(); 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Controls/MultiSelectionComboBox/ICompareObjectToString.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Markup; 7 | 8 | namespace TimsWpfControls 9 | { 10 | /// 11 | /// Defines a function that is used to check if a given string represents a given object of any type. 12 | /// 13 | public interface ICompareObjectToString 14 | { 15 | /// 16 | /// Checks if the given input string matches to the given object 17 | /// 18 | /// The string to compare 19 | /// The object to compare 20 | /// The used to check if the string matches 21 | /// The string format to apply 22 | /// true if the string represents the object, otherwise false. 23 | public bool CheckIfStringMatchesObject(string input, object objectToCompare, StringComparison stringComparison, string stringFormat); 24 | } 25 | 26 | [MarkupExtensionReturnType(typeof(DefaultObjectToStringComparer))] 27 | public class DefaultObjectToStringComparer : MarkupExtension, ICompareObjectToString 28 | { 29 | /// 30 | public bool CheckIfStringMatchesObject(string input, object objectToCompare, StringComparison stringComparison, string stringFormat) 31 | { 32 | if (input is null) 33 | { 34 | return objectToCompare is null; 35 | } 36 | 37 | if (objectToCompare is null) 38 | { 39 | return false; 40 | } 41 | 42 | string objectText; 43 | if (string.IsNullOrEmpty(stringFormat)) 44 | { 45 | objectText = objectToCompare.ToString(); 46 | } 47 | else if (stringFormat.Contains('{') && stringFormat.Contains('}')) 48 | { 49 | objectText = string.Format(stringFormat, objectToCompare); 50 | } 51 | else 52 | { 53 | objectText = string.Format($"{{0:{stringFormat}}}", objectToCompare); 54 | } 55 | 56 | return input.Equals(objectText, stringComparison); 57 | } 58 | 59 | /// 60 | public override object ProvideValue(IServiceProvider serviceProvider) 61 | { 62 | return this; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Controls/MultiSelectionComboBox/IParseStringToObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace TimsWpfControls 9 | { 10 | 11 | /// 12 | /// This interfaces is used to parse a string to any object. 13 | /// 14 | public interface IParseStringToObject 15 | { 16 | /// 17 | /// Parses the given input to an object of the given type. 18 | /// 19 | /// The input string to parse 20 | /// The object if successful, otherwise null 21 | /// The culture which should be used to parse. This parameter is optional 22 | /// The string format to apply. This parameter is optional 23 | /// the to which the input should be converted to. This parameter is optional 24 | /// if converting successful, otherwise 25 | bool TryCreateObjectFromString(string input, out object result, CultureInfo culture = null, string stringFormat = null, Type targetType = null); 26 | } 27 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Controls/MultiSelectionComboBox/SelectedItemsOrderType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace TimsWpfControls 8 | { 9 | /// 10 | /// Defines how the selected Items should be arranged for display 11 | /// 12 | public enum SelectedItemsOrderType 13 | { 14 | /// 15 | /// Displays the selected items in the same order as they were selected 16 | /// 17 | SelectedOrder, 18 | 19 | /// 20 | /// Displays the selected items in the same order as they are stored in the ItemsSource 21 | /// 22 | ItemsSourceOrder 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Converter/ColorToSolidColorBrushConverter.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Converters; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Media; 9 | 10 | namespace TimsWpfControls.Converter 11 | { 12 | public class ColorToSolidColorBrushConverter : MarkupConverter 13 | { 14 | protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | if (value is Color color) 17 | { 18 | return new SolidColorBrush(color); 19 | } 20 | return null; 21 | } 22 | 23 | protected override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 24 | { 25 | if (value is SolidColorBrush brush) 26 | { 27 | return brush.Color; 28 | } 29 | return Colors.Transparent; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Converter/DataGridIsNewRowToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Data; 9 | 10 | namespace TimsWpfControls 11 | { 12 | public class DataGridIsNewRowToVisibilityConverter : IValueConverter 13 | { 14 | private static DataGridIsNewRowToVisibilityConverter _Instance; 15 | public static DataGridIsNewRowToVisibilityConverter Instance => _Instance ??= new(); 16 | 17 | object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) 18 | { 19 | return value == CollectionView.NewItemPlaceholder ? Visibility.Collapsed : Visibility.Visible; 20 | } 21 | 22 | object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 23 | { 24 | throw new NotSupportedException(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Converter/EnumLocalizedDescriptionConverter.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Converters; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using TimsWpfControls.Model; 9 | 10 | namespace TimsWpfControls.Converter 11 | { 12 | public class EnumLocalizedDescriptionConverter : MarkupConverter 13 | { 14 | EnumLocalizedDescriptionConverter _Instance; 15 | protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | if (!(value is Enum inputEnum)) 18 | { 19 | return null; 20 | } 21 | 22 | if (inputEnum.GetType().GetField(inputEnum.ToString()).GetCustomAttributes(false).OfType().FirstOrDefault() is LocalizedDescriptionAttribute descriptionAttribute) 23 | { 24 | return descriptionAttribute.Description; 25 | } 26 | else 27 | { 28 | return inputEnum.ToString(); 29 | } 30 | } 31 | 32 | protected override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 33 | { 34 | throw new NotSupportedException(); 35 | } 36 | 37 | public override object ProvideValue(IServiceProvider serviceProvider) 38 | { 39 | return _Instance ??= new EnumLocalizedDescriptionConverter(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Converter/EnumToBoolConverter.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Converters; 2 | using System; 3 | using System.Globalization; 4 | using System.Windows.Data; 5 | 6 | namespace TimsWpfControls.Converter 7 | { 8 | [ValueConversion(typeof(Enum), typeof(bool), ParameterType = typeof(Enum))] 9 | public class EnumToBoolConverter : MarkupConverter 10 | { 11 | protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture) 12 | { 13 | return value?.Equals(parameter); 14 | } 15 | 16 | protected override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 17 | { 18 | return (bool)value == true ? parameter : Binding.DoNothing; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Converter/EnumToItemSourceConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Data; 8 | using System.Windows.Markup; 9 | 10 | namespace TimsWpfControls.Converter 11 | { 12 | public class EnumToItemSourceConverter : MarkupExtension, IValueConverter 13 | { 14 | static EnumToItemSourceConverter _Instance; 15 | 16 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 17 | { 18 | if (value is Enum) 19 | { 20 | return Enum.GetValues(value.GetType()); 21 | } 22 | throw new ArgumentException("the provided value is not a valid Enum"); 23 | } 24 | 25 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 26 | { 27 | throw new NotSupportedException(); 28 | } 29 | 30 | public override object ProvideValue(IServiceProvider serviceProvider) 31 | { 32 | return _Instance ??= new EnumToItemSourceConverter(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Converter/InvertBoolConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Data; 8 | 9 | namespace TimsWpfControls.Converter 10 | { 11 | [ValueConversion(typeof(bool), typeof(bool))] 12 | public class InvertBoolConverter : IValueConverter 13 | { 14 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | if (value is bool val) 17 | { 18 | return !val; 19 | } 20 | throw new ArgumentException("value is not a bool."); 21 | } 22 | 23 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 24 | { 25 | if (value is bool val) 26 | { 27 | return !val; 28 | } 29 | throw new ArgumentException("value is not a bool."); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Converter/NotNullToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Converters; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows; 9 | 10 | namespace TimsWpfControls.Converter 11 | { 12 | public class NotNullToVisibilityConverter : MarkupConverter 13 | { 14 | static NotNullToVisibilityConverter instance; 15 | 16 | protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture) 17 | { 18 | return value == null ? Visibility.Collapsed : Visibility.Visible; 19 | } 20 | 21 | protected override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 22 | { 23 | throw new NotSupportedException(); 24 | } 25 | 26 | public override object ProvideValue(IServiceProvider serviceProvider) 27 | { 28 | return instance ??= new NotNullToVisibilityConverter(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Converter/NullImageConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Data; 8 | using System.Windows; 9 | 10 | namespace TimsWpfControls.Converter 11 | { 12 | public class NullImageConverter : IValueConverter 13 | { 14 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | return value is null ? DependencyProperty.UnsetValue : value; 17 | } 18 | 19 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 20 | { 21 | throw new NotImplementedException(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Converter/PercentageToGridLengthConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Data; 9 | 10 | namespace TimsWpfControls.Converter 11 | { 12 | public class PercentageToGridLengthConverter : IValueConverter 13 | { 14 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | 17 | bool inverse = (parameter as string)?.ToLowerInvariant() == "true"; 18 | 19 | if (value is double @double) 20 | { 21 | if (inverse) 22 | { 23 | @double = 1 - @double; 24 | } 25 | return new GridLength(@double, GridUnitType.Star); 26 | } 27 | 28 | throw new NotImplementedException(); 29 | } 30 | 31 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 32 | { 33 | throw new NotImplementedException(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Converter/SolidColorBrushToColorConverter.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Converters; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Media; 9 | 10 | namespace TimsWpfControls.Converter 11 | { 12 | public class SolidColorBrushToColorConverter : MarkupConverter 13 | { 14 | protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | if (value is SolidColorBrush brush) 17 | { 18 | return brush.Color; 19 | } 20 | return Colors.Transparent; 21 | } 22 | 23 | protected override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 24 | { 25 | if (value is Color color) 26 | { 27 | return new SolidColorBrush(color); 28 | } 29 | return null; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/ExtensionMethods/NumericExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TimsWpfControls.ExtensionMethods 4 | { 5 | public static class NumericExtensions 6 | { 7 | /// 8 | /// Checks if two double values are "equal enough" 9 | /// 10 | /// The value to compare 11 | /// The value to compare to 12 | /// The tolerance. Default: 1e-5 13 | /// 14 | public static bool ApproximateEqualTo(this double value, double ValueToCompare, double MaxDeviation = 1e-5) 15 | { 16 | if (double.IsNaN(value) || double.IsNaN(ValueToCompare)) 17 | { 18 | return value == ValueToCompare; 19 | } 20 | else 21 | { 22 | return Math.Abs(value - ValueToCompare) <= MaxDeviation; 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/ExtensionMethods/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace TimsWpfControls.ExtensionMethods 5 | { 6 | public static class StringExtensions 7 | { 8 | internal static string GetStringToTheRight(this string input, int CaretIndex, char StopCharacter) 9 | { 10 | var StartIndex = input.LastIndexOf(StopCharacter, CaretIndex - 1); 11 | if (StartIndex < 0) StartIndex = 0; 12 | return input[StartIndex..CaretIndex].Trim(StopCharacter).TrimStart(); 13 | } 14 | 15 | internal static string GetStringToTheRight(this string input, int CaretIndex, char[] StopCharacters) 16 | { 17 | int StartIndex = -1; 18 | 19 | for (int i = 0; i < StopCharacters.Length; i++) 20 | { 21 | var StartIndexTemp = input.LastIndexOf(StopCharacters[i], CaretIndex - 1); 22 | if (StartIndexTemp > StartIndex) StartIndex = StartIndexTemp; 23 | } 24 | 25 | if (StartIndex < 0) StartIndex = 0; 26 | return input[StartIndex..CaretIndex].Trim(StopCharacters).TrimStart(); 27 | } 28 | 29 | internal static string GetStringToTheRight(this string input, int CaretIndex, string[] StopCharacters) 30 | { 31 | int StartIndex = -1; 32 | 33 | for (int i = 0; i < StopCharacters.Length; i++) 34 | { 35 | var StartIndexTemp = input.LastIndexOf(StopCharacters[i], CaretIndex - 1, StringComparison.Ordinal); 36 | if (StartIndexTemp > StartIndex) StartIndex = StartIndexTemp; 37 | } 38 | 39 | if (StartIndex < 0) StartIndex = 0; 40 | var result = input[StartIndex..CaretIndex].TrimStart(); 41 | 42 | foreach (var str in StopCharacters) 43 | { 44 | if (result.StartsWith(str, StringComparison.Ordinal)) 45 | { 46 | result = result.Remove(0, str.Length); 47 | } 48 | } 49 | return result; 50 | } 51 | 52 | internal static string GetStringToTheRight(this string input, int CaretIndex, object StopCharacters) 53 | { 54 | return StopCharacters switch 55 | { 56 | char[] charArray => input.GetStringToTheRight(CaretIndex, charArray), 57 | string[] stringArray => input.GetStringToTheRight(CaretIndex, stringArray), 58 | string str => input.GetStringToTheRight(CaretIndex, str.ToCharArray()), 59 | _ => throw new ArgumentException("StopCharacters must either be char[], string[] or string") 60 | }; 61 | } 62 | 63 | public static string ReplaceFirst(this string text, string search, string replace, StringComparison stringComparison = StringComparison.Ordinal) 64 | { 65 | int pos = text.IndexOf(search, stringComparison); 66 | if (pos < 0) 67 | { 68 | return text; 69 | } 70 | return text.Substring(0, pos) + replace + text[(pos + search.Length)..]; 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Helper/BindingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Data; 8 | 9 | namespace TimsWpfControls.Helper 10 | { 11 | public static class BindingHelper 12 | { 13 | private static readonly DependencyProperty DummyProperty = DependencyProperty.RegisterAttached( 14 | "Dummy", 15 | typeof(object), 16 | typeof(DependencyObject), 17 | new UIPropertyMetadata(null)); 18 | 19 | public static object Eval(object source, string expression) 20 | { 21 | Binding binding = new Binding(expression) { Source = source }; 22 | return Eval(binding); 23 | } 24 | 25 | public static object Eval(object source, string expression, string format) 26 | { 27 | Binding binding = new Binding(expression) { Source = source, StringFormat=format }; 28 | return Eval(binding); 29 | } 30 | 31 | public static object Eval(Binding binding, object source) 32 | { 33 | if (binding is null) throw new ArgumentNullException(nameof(binding)); 34 | 35 | Binding newBinding = new Binding() 36 | { 37 | Source = source, 38 | AsyncState = binding.AsyncState, 39 | BindingGroupName = binding.BindingGroupName, 40 | BindsDirectlyToSource = binding.BindsDirectlyToSource, 41 | Path = binding.Path, 42 | Converter = binding.Converter, 43 | ConverterCulture = binding.ConverterCulture, 44 | ConverterParameter = binding.ConverterParameter, 45 | FallbackValue = binding.FallbackValue, 46 | IsAsync = binding.IsAsync, 47 | Mode = BindingMode.OneWay, 48 | StringFormat = binding.StringFormat, 49 | TargetNullValue = binding.TargetNullValue 50 | }; 51 | return Eval(newBinding); 52 | } 53 | 54 | public static object Eval(Binding binding, DependencyObject dependencyObject = null) 55 | { 56 | dependencyObject ??= new DependencyObject(); 57 | BindingOperations.SetBinding(dependencyObject, DummyProperty, binding); 58 | return dependencyObject.GetValue(DummyProperty); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Helper/DataContextProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | 8 | namespace TimsWpfControls 9 | { 10 | /// 11 | /// This is a simple Binding Proxy to get rid of the FindAnchestor issues. 12 | /// Idea taken from here: https://code.4noobz.net/wpf-mvvm-proxy-binding/ 13 | /// 14 | public class DataContextProxy : Freezable 15 | { 16 | #region Overrides of Freezable 17 | 18 | protected override Freezable CreateInstanceCore() 19 | { 20 | return new DataContextProxy(); 21 | } 22 | 23 | #endregion 24 | 25 | /// 26 | /// Gets or Sets the Data which you want to bind to. 27 | /// 28 | public object Data 29 | { 30 | get { return (object)GetValue(DataProperty); } 31 | set { SetValue(DataProperty, value); } 32 | } 33 | 34 | public static readonly DependencyProperty DataProperty = DependencyProperty.Register(nameof(Data), typeof(object), typeof(DataContextProxy), new UIPropertyMetadata(null)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Helper/DialogHelper.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Controls; 2 | using MahApps.Metro.Controls.Dialogs; 3 | using System; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | 8 | namespace TimsWpfControls 9 | { 10 | public static class DialogHelper 11 | { 12 | public static async Task ShowErrorMessage(Exception e, string Header = "Error") 13 | { 14 | MetroWindow window = Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); 15 | if (window is null) 16 | { 17 | MessageBox.Show(e.Message, Header); 18 | } 19 | else 20 | { 21 | await window.ShowMessageAsync(Header, e.Message, MessageDialogStyle.Affirmative); 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Helper/FileHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using TimsWpfControls.ExtensionMethods; 10 | 11 | namespace TimsWpfControls.Helper 12 | { 13 | public static class FileHelper 14 | { 15 | public static bool IsFullyQualifiedAdvanced(string fileName) 16 | { 17 | try 18 | { 19 | if (string.IsNullOrEmpty(fileName)) return false; 20 | return IsFullyQualifiedAdvanced(new Uri(fileName)); 21 | } 22 | catch 23 | { 24 | return false; 25 | } 26 | } 27 | 28 | public static bool IsFullyQualifiedAdvanced(Uri uri) 29 | { 30 | try 31 | { 32 | return uri.Host == Dns.GetHostEntry(uri.Host).HostName; 33 | } 34 | catch 35 | { 36 | return false; 37 | } 38 | } 39 | 40 | 41 | public static string GetFullyQualifiedAdvanced(string fileName) 42 | { 43 | try 44 | { 45 | var uri = new Uri(fileName); 46 | 47 | if (!uri.IsUnc) 48 | { 49 | return fileName; 50 | } 51 | else if (IsFullyQualifiedAdvanced(uri)) 52 | { 53 | return fileName; 54 | } 55 | else 56 | { 57 | return fileName.ReplaceFirst(uri.Host, Dns.GetHostEntry(uri.Host).HostName); 58 | } 59 | } 60 | catch 61 | { 62 | return null; 63 | } 64 | } 65 | 66 | 67 | [DllImport("mpr.dll")] 68 | static extern int WNetGetUniversalNameA(string lpLocalPath, int dwInfoLevel, IntPtr lpBuffer, ref int lpBufferSize); 69 | 70 | // I think max length for UNC is actually 32,767 71 | public static string LocalPathToUNC(string localPath, int maxLen = 2000) 72 | { 73 | IntPtr lpBuff; 74 | 75 | // Allocate the memory 76 | try 77 | { 78 | lpBuff = Marshal.AllocHGlobal(maxLen); 79 | } 80 | catch (OutOfMemoryException) 81 | { 82 | return null; 83 | } 84 | 85 | try 86 | { 87 | int res = WNetGetUniversalNameA(localPath, 1, lpBuff, ref maxLen); 88 | 89 | if (res != 0) 90 | return GetFullyQualifiedAdvanced(localPath); 91 | 92 | // lpbuff is a structure, whose first element is a pointer to the UNC name (just going to be lpBuff + sizeof(int)) 93 | var result = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(lpBuff)); 94 | 95 | return GetFullyQualifiedAdvanced(result); 96 | } 97 | catch (Exception) 98 | { 99 | return null; 100 | } 101 | finally 102 | { 103 | Marshal.FreeHGlobal(lpBuff); 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Helper/SolidAccentsLibaryThemeProvider.cs: -------------------------------------------------------------------------------- 1 | using ControlzEx.Theming; 2 | using MahApps.Metro.Controls; 3 | using MahApps.Metro.Theming; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Globalization; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows.Media; 11 | 12 | namespace TimsWpfControls.Helper 13 | { 14 | public class SolidAccentsLibaryThemeProvider : LibraryThemeProvider 15 | 16 | { 17 | public static readonly SolidAccentsLibaryThemeProvider DefaultInstance = new SolidAccentsLibaryThemeProvider(); 18 | 19 | /// 20 | public SolidAccentsLibaryThemeProvider() : base(true) 21 | { 22 | } 23 | 24 | public override void FillColorSchemeValues(Dictionary values, RuntimeThemeColorValues colorValues) 25 | { 26 | if (values is null) throw new ArgumentNullException(nameof(values)); 27 | if (colorValues is null) throw new ArgumentNullException(nameof(colorValues)); 28 | 29 | if (colorValues.Options.UseHSL) 30 | { 31 | Color background = (Color)ColorConverter.ConvertFromString(colorValues.Options.BaseColorScheme.Values["MahApps.Colors.ThemeBackground"]); 32 | Color foreground = (Color)ColorConverter.ConvertFromString(colorValues.Options.BaseColorScheme.Values["MahApps.Colors.ThemeForeground"]); 33 | Color accent = colorValues.AccentBaseColor; 34 | double factor = colorValues.Options.BaseColorScheme.Name == "Dark" ? 0.1 : 0.2; 35 | 36 | var accentHsv = new HSVColor(accent); 37 | var backgroundHsv = new HSVColor(background); 38 | var foregroundHsv = new HSVColor(foreground); 39 | 40 | values.Add("MahApps.Colors.AccentBase", accent.ToString(CultureInfo.InvariantCulture)); 41 | values.Add("MahApps.Colors.Accent", GetAccentedColor(accentHsv, backgroundHsv, factor * 1).ToString(CultureInfo.InvariantCulture)); 42 | values.Add("MahApps.Colors.Accent2", GetAccentedColor(accentHsv, backgroundHsv, factor * 2).ToString(CultureInfo.InvariantCulture)); 43 | values.Add("MahApps.Colors.Accent3", GetAccentedColor(accentHsv, backgroundHsv, factor * 3).ToString(CultureInfo.InvariantCulture)); 44 | values.Add("MahApps.Colors.Accent4", GetAccentedColor(accentHsv, backgroundHsv, factor * 4).ToString(CultureInfo.InvariantCulture)); 45 | 46 | values.Add("MahApps.Colors.Highlight", GetAccentedColor(accentHsv, foregroundHsv, factor).ToString(CultureInfo.InvariantCulture)); 47 | values.Add("MahApps.Colors.IdealForeground", colorValues.IdealForegroundColor.ToString(CultureInfo.InvariantCulture)); 48 | } 49 | else 50 | { 51 | values.Add("MahApps.Colors.AccentBase", colorValues.AccentBaseColor.ToString()); 52 | values.Add("MahApps.Colors.Accent", colorValues.AccentColor80.ToString()); 53 | values.Add("MahApps.Colors.Accent2", colorValues.AccentColor60.ToString()); 54 | values.Add("MahApps.Colors.Accent3", colorValues.AccentColor40.ToString()); 55 | values.Add("MahApps.Colors.Accent4", colorValues.AccentColor20.ToString()); 56 | 57 | values.Add("MahApps.Colors.Highlight", colorValues.HighlightColor.ToString()); 58 | values.Add("MahApps.Colors.IdealForeground", colorValues.IdealForegroundColor.ToString()); 59 | } 60 | 61 | } 62 | 63 | public override string GetThemeGeneratorParametersContent() 64 | { 65 | return MahAppsLibraryThemeProvider.DefaultInstance.GetThemeGeneratorParametersContent(); 66 | } 67 | 68 | public override string GetThemeTemplateContent() 69 | { 70 | return MahAppsLibraryThemeProvider.DefaultInstance.GetThemeTemplateContent(); 71 | } 72 | 73 | private static Color GetAccentedColor (HSVColor accentBase, HSVColor background, double percentage) 74 | { 75 | double newSaturation = accentBase.Saturation + (background.Saturation - accentBase.Saturation) * percentage; 76 | double newValue = accentBase.Value + (background.Value - accentBase.Value) * percentage; 77 | 78 | return new HSVColor(accentBase.Hue, newSaturation, newValue).ToColor(); 79 | } 80 | 81 | 82 | } 83 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Helper/ThemingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Collections.ObjectModel; 5 | using System.Globalization; 6 | using System.Linq; 7 | using System.Resources; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows.Media; 11 | 12 | namespace TimsWpfControls 13 | { 14 | public static class ThemingHelper 15 | { 16 | static Dictionary _AccentColorNamesDictionary; 17 | public static Dictionary AccentColorNamesDictionary 18 | { 19 | get 20 | { 21 | if (_AccentColorNamesDictionary == null) 22 | { 23 | _AccentColorNamesDictionary = new Dictionary(); 24 | var rm = new ResourceManager(typeof(Lang.AccentColorNames)); 25 | var resourceSet = rm.GetResourceSet(CultureInfo.CurrentCulture, true, true); 26 | foreach (var entry in resourceSet.OfType()) 27 | { 28 | try 29 | { 30 | var color = (Color)ColorConverter.ConvertFromString(entry.Key.ToString()); 31 | _AccentColorNamesDictionary.Add(color, entry.Value.ToString()); 32 | } 33 | catch (Exception) 34 | { 35 | Console.WriteLine(entry.Key.ToString() + " is not a valid color-key"); 36 | } 37 | } 38 | } 39 | return _AccentColorNamesDictionary; 40 | } 41 | set { _AccentColorNamesDictionary = value; } 42 | } 43 | 44 | 45 | static ObservableCollection _AccentColorsPalette; 46 | public static ObservableCollection AccentColorsPalette 47 | { 48 | get 49 | { 50 | if (_AccentColorsPalette == null) 51 | { 52 | _AccentColorsPalette = new ObservableCollection( 53 | AccentColorNamesDictionary 54 | .OrderBy(x => x.Value) 55 | .Select(x => x.Key)); 56 | 57 | return _AccentColorsPalette; 58 | } 59 | return _AccentColorsPalette; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Helper/TreeHelper.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Controls; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls.Primitives; 9 | 10 | namespace TimsWpfControls.Helper 11 | { 12 | public static class TreeHelper 13 | { 14 | public static bool IsDescendantOf(this DependencyObject node, DependencyObject reference) 15 | { 16 | bool success = false; 17 | 18 | DependencyObject curr = node; 19 | 20 | while (curr != null) 21 | { 22 | if (curr == reference) 23 | { 24 | success = true; 25 | break; 26 | } 27 | 28 | if (curr is Popup popup) 29 | { 30 | curr = popup; 31 | 32 | if (popup != null) 33 | { 34 | // Try the poup Parent 35 | curr = popup.Parent; 36 | 37 | // Otherwise fall back to placement target 38 | if (curr == null) 39 | { 40 | curr = popup.PlacementTarget; 41 | } 42 | } 43 | } 44 | else // Otherwise walk tree 45 | { 46 | curr = curr.GetParentObject(); 47 | } 48 | 49 | } 50 | 51 | return success; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/AccentColorNames.de-DE.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | Kobalt 122 | 123 | 124 | Blau 125 | 126 | 127 | Smaragdgrün 128 | 129 | 130 | Blaugrün 131 | 132 | 133 | Cyanblau 134 | 135 | 136 | Grün 137 | 138 | 139 | Lila 140 | 141 | 142 | Stahl 143 | 144 | 145 | Indigo 146 | 147 | 148 | Olivgrün 149 | 150 | 151 | Malvenfarbe 152 | 153 | 154 | Braun 155 | 156 | 157 | Braungrau 158 | 159 | 160 | Ockergelb 161 | 162 | 163 | Karmesinrot 164 | 165 | 166 | Limone 167 | 168 | 169 | Violett 170 | 171 | 172 | Magenta 173 | 174 | 175 | Rot 176 | 177 | 178 | Bernstein 179 | 180 | 181 | Rosa 182 | 183 | 184 | Orange 185 | 186 | 187 | Gelb 188 | 189 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/AccentColorNames.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | Amber 122 | 123 | 124 | Blue 125 | 126 | 127 | Brown 128 | 129 | 130 | Cobalt 131 | 132 | 133 | Crimson 134 | 135 | 136 | Cyan 137 | 138 | 139 | Emerald 140 | 141 | 142 | Green 143 | 144 | 145 | Indigo 146 | 147 | 148 | Lime 149 | 150 | 151 | Magenta 152 | 153 | 154 | Mauve 155 | 156 | 157 | Olive 158 | 159 | 160 | Orange 161 | 162 | 163 | Pink 164 | 165 | 166 | Purple 167 | 168 | 169 | Red 170 | 171 | 172 | Sienna 173 | 174 | 175 | Steel 176 | 177 | 178 | Taupe 179 | 180 | 181 | Teal 182 | 183 | 184 | Violet 185 | 186 | 187 | Yellow 188 | 189 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/FileSelectionTextBox.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 TimsWpfControls.Lang { 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", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | public class FileSelectionTextBox { 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 FileSelectionTextBox() { 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 | public 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("TimsWpfControls.Lang.FileSelectionTextBox", typeof(FileSelectionTextBox).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 | public static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized string similar to Any File (*.*)|*.*. 65 | /// 66 | public static string FilterAnyFile { 67 | get { 68 | return ResourceManager.GetString("FilterAnyFile", resourceCulture); 69 | } 70 | } 71 | 72 | /// 73 | /// Looks up a localized string similar to Select a file. 74 | /// 75 | public static string SelectFile { 76 | get { 77 | return ResourceManager.GetString("SelectFile", resourceCulture); 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/FileSelectionTextBox.de-DE.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | Wähle eine Datei 122 | 123 | 124 | Alle Dateien (*.*)|*.* 125 | 126 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/FileSelectionTextBox.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | text/microsoft-resx 90 | 91 | 92 | 1.3 93 | 94 | 95 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 96 | 97 | 98 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 99 | 100 | 101 | Select a file 102 | 103 | 104 | Any File (*.*)|*.* 105 | 106 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/MultiSelectionComboBox.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 TimsWpfControls.Lang { 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", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | public class MultiSelectionComboBox { 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 MultiSelectionComboBox() { 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 | public 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("TimsWpfControls.Lang.MultiSelectionComboBox", typeof(MultiSelectionComboBox).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 | public static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized string similar to Reset Text. 65 | /// 66 | public static string ResetTextToSelectedItems { 67 | get { 68 | return ResourceManager.GetString("ResetTextToSelectedItems", resourceCulture); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/MultiSelectionComboBox.de.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | Text zurücksetzen 122 | 123 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/MultiSelectionComboBox.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | text/microsoft-resx 90 | 91 | 92 | 1.3 93 | 94 | 95 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 96 | 97 | 98 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 99 | 100 | 101 | Reset Text 102 | This text is shown on the popup overlay if the text is userdefined. 103 | 104 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/ValidationMessages.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 TimsWpfControls.Lang { 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", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class ValidationMessages { 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 ValidationMessages() { 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("TimsWpfControls.Lang.ValidationMessages", typeof(ValidationMessages).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 | /// Looks up a localized string similar to The collection "{0}" may not be empty. 65 | /// 66 | internal static string CollectionMayNotBeEmpty { 67 | get { 68 | return ResourceManager.GetString("CollectionMayNotBeEmpty", resourceCulture); 69 | } 70 | } 71 | 72 | /// 73 | /// Looks up a localized string similar to The Filename of "{0}" is not fully qualified. 74 | /// 75 | internal static string FilenameIsNotFullyQualified { 76 | get { 77 | return ResourceManager.GetString("FilenameIsNotFullyQualified", resourceCulture); 78 | } 79 | } 80 | 81 | /// 82 | /// Looks up a localized string similar to "{0}" must be greater than {1}. 83 | /// 84 | internal static string PropertyMustBeGreaterThanMessage { 85 | get { 86 | return ResourceManager.GetString("PropertyMustBeGreaterThanMessage", resourceCulture); 87 | } 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/ValidationMessages.de-DE.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | "{0}" muss größer als {1} sein 122 | 123 | 124 | Der Dateiname für "{0}" ist nicht vollständig definiert 125 | 126 | 127 | Die Auflistung "{0}" darf nicht leer sein 128 | 129 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Lang/ValidationMessages.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | text/microsoft-resx 90 | 91 | 92 | 1.3 93 | 94 | 95 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 96 | 97 | 98 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 99 | 100 | 101 | "{0}" must be greater than {1} 102 | 103 | 104 | The Filename of "{0}" is not fully qualified 105 | 106 | 107 | The collection "{0}" may not be empty 108 | 109 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Model/LocalizedDescriptionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Resources; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace TimsWpfControls.Model 10 | { 11 | 12 | 13 | public class LocalizedDescriptionAttribute : DescriptionAttribute 14 | { 15 | private readonly ResourceManager resourceManager; 16 | private readonly string resourceKey; 17 | 18 | /// 19 | /// Creates a new LocalizedDescription-Attribute 20 | /// 21 | /// the Key of the the resourcestring to lookup 22 | /// the type of the ResourceDictionary where the data is stored 23 | public LocalizedDescriptionAttribute(string resourceKey, Type resourceType) 24 | { 25 | this.resourceKey = resourceKey; 26 | this.resourceManager = new ResourceManager(resourceType); 27 | } 28 | 29 | public override string Description 30 | { 31 | get 32 | { 33 | string description = resourceManager.GetString(resourceKey); 34 | return string.IsNullOrWhiteSpace(description) ? resourceKey : description; 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Model/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Input; 3 | 4 | namespace TimsWpfControls.Model 5 | { 6 | [Obsolete ("Use any other MVVM Toolkit instead, e.g.: Microsoft.Toolkit.Mvvm")] 7 | public class RelayCommand : ICommand 8 | { 9 | private Action execute; 10 | 11 | private Predicate canExecute; 12 | 13 | private event EventHandler CanExecuteChangedInternal; 14 | 15 | public RelayCommand(Action execute) : this(execute, DefaultCanExecute) 16 | { 17 | } 18 | 19 | public RelayCommand(Action execute, Predicate canExecute) 20 | { 21 | this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); 22 | this.canExecute = canExecute ?? throw new ArgumentNullException(nameof(canExecute)); 23 | } 24 | 25 | public event EventHandler CanExecuteChanged 26 | { 27 | add 28 | { 29 | CommandManager.RequerySuggested += value; 30 | this.CanExecuteChangedInternal += value; 31 | } 32 | 33 | remove 34 | { 35 | CommandManager.RequerySuggested -= value; 36 | this.CanExecuteChangedInternal -= value; 37 | } 38 | } 39 | 40 | public bool CanExecute(object parameter) 41 | { 42 | return this.canExecute != null && this.canExecute(parameter); 43 | } 44 | 45 | public void Execute(object parameter) 46 | { 47 | this.execute(parameter); 48 | } 49 | 50 | public void OnCanExecuteChanged() 51 | { 52 | EventHandler handler = this.CanExecuteChangedInternal; 53 | if (handler != null) 54 | { 55 | handler.Invoke(this, EventArgs.Empty); 56 | } 57 | } 58 | 59 | public void Destroy() 60 | { 61 | this.canExecute = _ => false; 62 | this.execute = _ => { return; }; 63 | } 64 | 65 | private static bool DefaultCanExecute(object parameter) 66 | { 67 | return true; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/PushBinding/FreezableBinding.cs: -------------------------------------------------------------------------------- 1 | // see: https://meleak.wordpress.com/2011/08/28/onewaytosource-binding-for-readonly-dependency-property/ 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.ComponentModel; 8 | using System.Collections.ObjectModel; 9 | using System.Windows; 10 | using System.Windows.Data; 11 | using System.Globalization; 12 | using System.Windows.Controls; 13 | using System.Windows.Markup; 14 | using System.Xml; 15 | 16 | namespace TimsWpfControls 17 | { 18 | public class FreezableBinding : Freezable 19 | { 20 | #region Properties 21 | 22 | private Binding _binding; 23 | protected Binding Binding 24 | { 25 | get 26 | { 27 | if (_binding == null) 28 | { 29 | _binding = new Binding(); 30 | } 31 | return _binding; 32 | } 33 | } 34 | 35 | [DefaultValue(null)] 36 | public object AsyncState 37 | { 38 | get { return Binding.AsyncState; } 39 | set { Binding.AsyncState = value; } 40 | } 41 | 42 | [DefaultValue(false)] 43 | public bool BindsDirectlyToSource 44 | { 45 | get { return Binding.BindsDirectlyToSource; } 46 | set { Binding.BindsDirectlyToSource = value; } 47 | } 48 | 49 | [DefaultValue(null)] 50 | public IValueConverter Converter 51 | { 52 | get { return Binding.Converter; } 53 | set { Binding.Converter = value; } 54 | } 55 | 56 | [TypeConverter(typeof(CultureInfoIetfLanguageTagConverter)), DefaultValue(null)] 57 | public CultureInfo ConverterCulture 58 | { 59 | get { return Binding.ConverterCulture; } 60 | set { Binding.ConverterCulture = value; } 61 | } 62 | 63 | [DefaultValue(null)] 64 | 65 | public object ConverterParameter 66 | { 67 | get { return Binding.ConverterParameter; } 68 | set { Binding.ConverterParameter = value; } 69 | } 70 | 71 | [DefaultValue(null)] 72 | public string ElementName 73 | { 74 | get { return Binding.ElementName; } 75 | set { Binding.ElementName = value; } 76 | } 77 | 78 | [DefaultValue(null)] 79 | public object FallbackValue 80 | { 81 | get { return Binding.FallbackValue; } 82 | set { Binding.FallbackValue = value; } 83 | } 84 | 85 | [DefaultValue(false)] 86 | public bool IsAsync 87 | { 88 | get { return Binding.IsAsync; } 89 | set { Binding.IsAsync = value; } 90 | } 91 | 92 | [DefaultValue(BindingMode.Default)] 93 | public BindingMode Mode 94 | { 95 | get { return Binding.Mode; } 96 | set { Binding.Mode = value; } 97 | } 98 | 99 | [DefaultValue(false)] 100 | public bool NotifyOnSourceUpdated 101 | { 102 | get { return Binding.NotifyOnSourceUpdated; } 103 | set { Binding.NotifyOnSourceUpdated = value; } 104 | } 105 | 106 | [DefaultValue(false)] 107 | public bool NotifyOnTargetUpdated 108 | { 109 | get { return Binding.NotifyOnTargetUpdated; } 110 | set { Binding.NotifyOnTargetUpdated = value; } 111 | } 112 | 113 | [DefaultValue(false)] 114 | public bool NotifyOnValidationError 115 | { 116 | get { return Binding.NotifyOnValidationError; } 117 | set { Binding.NotifyOnValidationError = value; } 118 | } 119 | 120 | [DefaultValue(null)] 121 | public PropertyPath Path 122 | { 123 | get { return Binding.Path; } 124 | set { Binding.Path = value; } 125 | } 126 | 127 | [DefaultValue(null)] 128 | public RelativeSource RelativeSource 129 | { 130 | get { return Binding.RelativeSource; } 131 | set { Binding.RelativeSource = value; } 132 | } 133 | 134 | [DefaultValue(null)] 135 | public object Source 136 | { 137 | get { return Binding.Source; } 138 | set { Binding.Source = value; } 139 | } 140 | 141 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] 142 | public UpdateSourceExceptionFilterCallback UpdateSourceExceptionFilter 143 | { 144 | get { return Binding.UpdateSourceExceptionFilter; } 145 | set { Binding.UpdateSourceExceptionFilter = value; } 146 | } 147 | 148 | [DefaultValue(UpdateSourceTrigger.PropertyChanged)] 149 | public UpdateSourceTrigger UpdateSourceTrigger 150 | { 151 | get { return Binding.UpdateSourceTrigger; } 152 | set { Binding.UpdateSourceTrigger = value; } 153 | } 154 | 155 | [DefaultValue(false)] 156 | public bool ValidatesOnDataErrors 157 | { 158 | get { return Binding.ValidatesOnDataErrors; } 159 | set { Binding.ValidatesOnDataErrors = value; } 160 | } 161 | 162 | [DefaultValue(false)] 163 | public bool ValidatesOnExceptions 164 | { 165 | get { return Binding.ValidatesOnExceptions; } 166 | set { Binding.ValidatesOnExceptions = value; } 167 | } 168 | 169 | [DefaultValue(null)] 170 | public string XPath 171 | { 172 | get { return Binding.XPath; } 173 | set { Binding.XPath = value; } 174 | } 175 | 176 | [DefaultValue(null)] 177 | public Collection ValidationRules 178 | { 179 | get { return Binding.ValidationRules; } 180 | } 181 | 182 | #endregion // Properties 183 | 184 | #region Freezable overrides 185 | 186 | protected override void CloneCore(Freezable sourceFreezable) 187 | { 188 | FreezableBinding freezableBindingClone = sourceFreezable as FreezableBinding; 189 | if (freezableBindingClone.ElementName != null) 190 | { 191 | ElementName = freezableBindingClone.ElementName; 192 | } 193 | else if (freezableBindingClone.RelativeSource != null) 194 | { 195 | RelativeSource = freezableBindingClone.RelativeSource; 196 | } 197 | else if (freezableBindingClone.Source != null) 198 | { 199 | Source = freezableBindingClone.Source; 200 | } 201 | AsyncState = freezableBindingClone.AsyncState; 202 | BindsDirectlyToSource = freezableBindingClone.BindsDirectlyToSource; 203 | Converter = freezableBindingClone.Converter; 204 | ConverterCulture = freezableBindingClone.ConverterCulture; 205 | ConverterParameter = freezableBindingClone.ConverterParameter; 206 | FallbackValue = freezableBindingClone.FallbackValue; 207 | IsAsync = freezableBindingClone.IsAsync; 208 | Mode = freezableBindingClone.Mode; 209 | NotifyOnSourceUpdated = freezableBindingClone.NotifyOnSourceUpdated; 210 | NotifyOnTargetUpdated = freezableBindingClone.NotifyOnTargetUpdated; 211 | NotifyOnValidationError = freezableBindingClone.NotifyOnValidationError; 212 | Path = freezableBindingClone.Path; 213 | UpdateSourceExceptionFilter = freezableBindingClone.UpdateSourceExceptionFilter; 214 | UpdateSourceTrigger = freezableBindingClone.UpdateSourceTrigger; 215 | ValidatesOnDataErrors = freezableBindingClone.ValidatesOnDataErrors; 216 | ValidatesOnExceptions = freezableBindingClone.ValidatesOnExceptions; 217 | XPath = XPath; 218 | foreach (ValidationRule validationRule in freezableBindingClone.ValidationRules) 219 | { 220 | ValidationRules.Add(validationRule); 221 | } 222 | base.CloneCore(sourceFreezable); 223 | } 224 | 225 | protected override Freezable CreateInstanceCore() 226 | { 227 | return new FreezableBinding(); 228 | } 229 | 230 | #endregion // Freezable overrides 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/PushBinding/PushBinding.cs: -------------------------------------------------------------------------------- 1 | // see: https://meleak.wordpress.com/2011/08/28/onewaytosource-binding-for-readonly-dependency-property/ 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Windows; 8 | using System.ComponentModel; 9 | using System.Windows.Data; 10 | 11 | namespace TimsWpfControls 12 | { 13 | public class PushBinding : FreezableBinding 14 | { 15 | #region Dependency Properties 16 | 17 | public static DependencyProperty TargetPropertyMirrorProperty = 18 | DependencyProperty.Register("TargetPropertyMirror", 19 | typeof(object), 20 | typeof(PushBinding)); 21 | public static DependencyProperty TargetPropertyListenerProperty = 22 | DependencyProperty.Register("TargetPropertyListener", 23 | typeof(object), 24 | typeof(PushBinding), 25 | new UIPropertyMetadata(null, OnTargetPropertyListenerChanged)); 26 | 27 | private static void OnTargetPropertyListenerChanged(object sender, DependencyPropertyChangedEventArgs e) 28 | { 29 | PushBinding pushBinding = sender as PushBinding; 30 | pushBinding.TargetPropertyValueChanged(); 31 | } 32 | 33 | #endregion // Dependency Properties 34 | 35 | #region Constructor 36 | 37 | public PushBinding() 38 | { 39 | Mode = BindingMode.OneWayToSource; 40 | } 41 | 42 | #endregion // Constructor 43 | 44 | #region Properties 45 | 46 | public object TargetPropertyMirror 47 | { 48 | get { return GetValue(TargetPropertyMirrorProperty); } 49 | set { SetValue(TargetPropertyMirrorProperty, value); } 50 | } 51 | public object TargetPropertyListener 52 | { 53 | get { return GetValue(TargetPropertyListenerProperty); } 54 | set { SetValue(TargetPropertyListenerProperty, value); } 55 | } 56 | 57 | [DefaultValue(null)] 58 | public string TargetProperty 59 | { 60 | get; 61 | set; 62 | } 63 | 64 | [DefaultValue(null)] 65 | public DependencyProperty TargetDependencyProperty 66 | { 67 | get; 68 | set; 69 | } 70 | 71 | #endregion // Properties 72 | 73 | #region Public Methods 74 | 75 | public void SetupTargetBinding(DependencyObject targetObject) 76 | { 77 | if (targetObject == null) 78 | { 79 | return; 80 | } 81 | 82 | // Prevent the designer from reporting exceptions since 83 | // changes will be made of a Binding in use if it is set 84 | if (DesignerProperties.GetIsInDesignMode(this) == true) 85 | return; 86 | 87 | // Bind to the selected TargetProperty, e.g. ActualHeight and get 88 | // notified about changes in OnTargetPropertyListenerChanged 89 | Binding listenerBinding = new() 90 | { 91 | Source = targetObject, 92 | Mode = BindingMode.OneWay 93 | }; 94 | if (TargetDependencyProperty != null) 95 | { 96 | listenerBinding.Path = new PropertyPath(TargetDependencyProperty); 97 | } 98 | else 99 | { 100 | listenerBinding.Path = new PropertyPath(TargetProperty); 101 | } 102 | BindingOperations.SetBinding(this, TargetPropertyListenerProperty, listenerBinding); 103 | 104 | // Set up a OneWayToSource Binding with the Binding declared in Xaml from 105 | // the Mirror property of this class. The mirror property will be updated 106 | // everytime the Listener property gets updated 107 | BindingOperations.SetBinding(this, TargetPropertyMirrorProperty, Binding); 108 | 109 | TargetPropertyValueChanged(); 110 | if (targetObject is FrameworkElement element1) 111 | { 112 | element1.Loaded += delegate { TargetPropertyValueChanged(); }; 113 | } 114 | else if (targetObject is FrameworkContentElement element) 115 | { 116 | element.Loaded += delegate { TargetPropertyValueChanged(); }; 117 | } 118 | } 119 | 120 | #endregion // Public Methods 121 | 122 | #region Private Methods 123 | 124 | private void TargetPropertyValueChanged() 125 | { 126 | object targetPropertyValue = GetValue(TargetPropertyListenerProperty); 127 | this.SetValue(TargetPropertyMirrorProperty, targetPropertyValue); 128 | } 129 | 130 | #endregion // Private Methods 131 | 132 | #region Freezable overrides 133 | 134 | protected override void CloneCore(Freezable sourceFreezable) 135 | { 136 | PushBinding pushBinding = sourceFreezable as PushBinding; 137 | TargetProperty = pushBinding.TargetProperty; 138 | TargetDependencyProperty = pushBinding.TargetDependencyProperty; 139 | base.CloneCore(sourceFreezable); 140 | } 141 | 142 | protected override Freezable CreateInstanceCore() 143 | { 144 | return new PushBinding(); 145 | } 146 | 147 | #endregion // Freezable overrides 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/PushBinding/PushBindingCollection.cs: -------------------------------------------------------------------------------- 1 | // see: https://meleak.wordpress.com/2011/08/28/onewaytosource-binding-for-readonly-dependency-property/ 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Windows; 8 | using System.Collections.Specialized; 9 | using System.Collections.ObjectModel; 10 | 11 | namespace TimsWpfControls 12 | { 13 | public class PushBindingCollection : FreezableCollection 14 | { 15 | public PushBindingCollection() { } 16 | 17 | public PushBindingCollection(DependencyObject targetObject) 18 | { 19 | TargetObject = targetObject; 20 | ((INotifyCollectionChanged)this).CollectionChanged += CollectionChanged; 21 | } 22 | 23 | void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) 24 | { 25 | if (e.Action == NotifyCollectionChangedAction.Add) 26 | { 27 | foreach (PushBinding pushBinding in e.NewItems) 28 | { 29 | pushBinding.SetupTargetBinding(TargetObject); 30 | } 31 | } 32 | } 33 | 34 | public DependencyObject TargetObject 35 | { 36 | get; 37 | private set; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/PushBinding/PushBindingManager.cs: -------------------------------------------------------------------------------- 1 | // see: https://meleak.wordpress.com/2011/08/28/onewaytosource-binding-for-readonly-dependency-property/ 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Windows; 8 | using System.Windows.Markup; 9 | using System.ComponentModel; 10 | using System.Collections; 11 | 12 | namespace TimsWpfControls 13 | { 14 | public class PushBindingManager 15 | { 16 | public static DependencyProperty PushBindingsProperty = 17 | DependencyProperty.RegisterAttached("PushBindingsInternal", 18 | typeof(PushBindingCollection), 19 | typeof(PushBindingManager), 20 | new UIPropertyMetadata(null)); 21 | 22 | public static PushBindingCollection GetPushBindings(DependencyObject obj) 23 | { 24 | if (obj.GetValue(PushBindingsProperty) == null) 25 | { 26 | obj.SetValue(PushBindingsProperty, new PushBindingCollection(obj)); 27 | } 28 | return (PushBindingCollection)obj.GetValue(PushBindingsProperty); 29 | } 30 | public static void SetPushBindings(DependencyObject obj, PushBindingCollection value) 31 | { 32 | obj.SetValue(PushBindingsProperty, value); 33 | } 34 | 35 | 36 | public static DependencyProperty StylePushBindingsProperty = 37 | DependencyProperty.RegisterAttached("StylePushBindings", 38 | typeof(PushBindingCollection), 39 | typeof(PushBindingManager), 40 | new UIPropertyMetadata(null, StylePushBindingsChanged)); 41 | 42 | public static PushBindingCollection GetStylePushBindings(DependencyObject obj) 43 | { 44 | return (PushBindingCollection)obj.GetValue(StylePushBindingsProperty); 45 | } 46 | public static void SetStylePushBindings(DependencyObject obj, PushBindingCollection value) 47 | { 48 | obj.SetValue(StylePushBindingsProperty, value); 49 | } 50 | 51 | public static void StylePushBindingsChanged(DependencyObject target, DependencyPropertyChangedEventArgs e) 52 | { 53 | if (target != null) 54 | { 55 | PushBindingCollection stylePushBindings = e.NewValue as PushBindingCollection; 56 | PushBindingCollection pushBindingCollection = GetPushBindings(target); 57 | foreach (PushBinding pushBinding in stylePushBindings) 58 | { 59 | PushBinding pushBindingClone = pushBinding.Clone() as PushBinding; 60 | pushBindingCollection.Add(pushBindingClone); 61 | } 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Themes/ArcSegment.xaml: -------------------------------------------------------------------------------- 1 |  4 | 33 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Themes/CircularProgressBar.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 90 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls/Themes/Generic.xaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using ControlzEx.Theming; 2 | using System.Data; 3 | using System.Linq; 4 | using System.Windows; 5 | using System.Windows.Media; 6 | 7 | namespace TimsWpfControls_Demo 8 | { 9 | /// 10 | /// Interaction logic for App.xaml 11 | /// 12 | /// 13 | public partial class App : Application 14 | { 15 | protected override void OnStartup(StartupEventArgs e) 16 | { 17 | base.OnStartup(e); 18 | var theme = ThemeManager.Current.DetectTheme(); 19 | 20 | foreach (var item in theme.Resources.Keys.Cast() 21 | .Where(key => theme.Resources[key] is Brush) 22 | .Select(key => key.ToString()) 23 | .OrderBy(s => s)) 24 | { 25 | // BrushEditor.SystemBrushes.Append(new BrushItem() { Name = item, Brush = (Brush)theme.Resources[item] }); 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/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 | )] -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 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 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 94 | 95 | 103 | 104 | 112 | 113 | 121 | 122 | 133 | 134 | 164 | 165 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Controls; 2 | 3 | namespace TimsWpfControls_Demo 4 | { 5 | /// 6 | /// Interaction logic for MainWindow.xaml 7 | /// 8 | public partial class MainWindow : MetroWindow 9 | { 10 | public MainWindow() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Model/DemoProperty.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Toolkit.Mvvm.ComponentModel; 2 | using System; 3 | using System.ComponentModel; 4 | using System.Windows; 5 | using TimsWpfControls.Model; 6 | 7 | namespace TimsWpfControls_Demo.Model 8 | { 9 | public class DemoProperty : ObservableObject 10 | { 11 | public DemoProperty(DependencyPropertyDescriptor descriptor) 12 | { 13 | this.Descriptor = descriptor; 14 | } 15 | 16 | private DependencyPropertyDescriptor _Descriptor; 17 | public DependencyPropertyDescriptor Descriptor 18 | { 19 | get { return _Descriptor; } 20 | set { SetProperty(ref _Descriptor, value); } 21 | } 22 | 23 | private object _Value; 24 | public object Value 25 | { 26 | get { return _Value; } 27 | set { SetProperty(ref _Value, value); } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Model/DemoPropertyTemplateSelector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | 6 | namespace TimsWpfControls_Demo.Model 7 | { 8 | public class DemoPropertyTemplateSelector : DataTemplateSelector 9 | { 10 | static DemoPropertyTemplateSelector() 11 | { 12 | BuildInDataTemplates.Add(typeof(string), (DataTemplate)Application.Current.Resources["Demo.DataTemplates.String"]); 13 | BuildInDataTemplates.Add(typeof(bool), (DataTemplate)Application.Current.Resources["Demo.DataTemplates.Bool"]); 14 | BuildInDataTemplates.Add(typeof(bool?), (DataTemplate)Application.Current.Resources["Demo.DataTemplates.Bool.Nullable"]); 15 | BuildInDataTemplates.Add(typeof(Enum), (DataTemplate)Application.Current.Resources["Demo.DataTemplates.Enum"]); 16 | BuildInDataTemplates.Add(typeof(double), (DataTemplate)Application.Current.Resources["Demo.DataTemplates.Numeric"]); 17 | BuildInDataTemplates.Add(typeof(double?), (DataTemplate)Application.Current.Resources["Demo.DataTemplates.Numeric"]); 18 | BuildInDataTemplates.Add(typeof(int), (DataTemplate)Application.Current.Resources["Demo.DataTemplates.Numeric"]); 19 | BuildInDataTemplates.Add(typeof(int?), (DataTemplate)Application.Current.Resources["Demo.DataTemplates.Numeric"]); 20 | } 21 | 22 | public static Dictionary BuildInDataTemplates { get; } = new Dictionary(); 23 | 24 | 25 | public DataTemplate FallbackTemplate { get; set; } 26 | 27 | public override DataTemplate SelectTemplate(object item, DependencyObject container) 28 | { 29 | if (item is DemoProperty demoProperty) 30 | { 31 | if (demoProperty.Descriptor.PropertyType.IsEnum) 32 | { 33 | return BuildInDataTemplates[typeof(Enum)]; 34 | } 35 | 36 | return BuildInDataTemplates.TryGetValue(demoProperty.Descriptor.PropertyType, out DataTemplate result) ? result : BuildInDataTemplates[typeof(string)]; 37 | } 38 | else 39 | { 40 | return FallbackTemplate; 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Model/Gender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace TimsWpfControls_Demo.Model 8 | { 9 | public enum Gender 10 | { 11 | Female, 12 | Male, 13 | Diverse 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Model/MainViewModel.cs: -------------------------------------------------------------------------------- 1 | using ControlzEx.Theming; 2 | using Microsoft.Toolkit.Mvvm.ComponentModel; 3 | using System.Collections.Generic; 4 | using System.Collections.ObjectModel; 5 | using System.Linq; 6 | using System.Windows.Media; 7 | using TimsWpfControls.Model; 8 | 9 | namespace TimsWpfControls_Demo.Model 10 | { 11 | public class MainViewModel : ObservableObject 12 | { 13 | 14 | public MainViewModel() 15 | { 16 | // Create AccentColorPalette 17 | foreach (var accent in ThemeManager.Current.Themes.GroupBy(x => x.ColorScheme).OrderBy(a => a.Key).Select(a => a.First())) 18 | { 19 | this.AccentColorNamesDictionary.Add(accent.PrimaryAccentColor, "MahApps." + accent.ColorScheme); 20 | } 21 | } 22 | 23 | public static List IntellisenseSource { get; } = new List() 24 | { 25 | "Hello", 26 | "World", 27 | "Welcome", 28 | "to", 29 | "my", 30 | "short", 31 | "sample" 32 | }; 33 | 34 | 35 | public static Collection People { get; } = new Collection() 36 | { 37 | new Person(){ FirstName="Donald", LastName="Duck", Age=-1, Gender = Gender.Male }, 38 | new Person(){ FirstName="Daisy", Age=2, Gender=Gender.Female }, 39 | new Person(){ FirstName="Tim", LastName="U", Age=32, Gender = Gender.Male }, 40 | new Person(){ FirstName="Person 1", LastName="Person A", Age=5, Gender = Gender.Diverse }, 41 | }; 42 | 43 | 44 | 45 | #region ColorPicker 46 | public List TintedColors 47 | { 48 | get 49 | { 50 | var list = new List 51 | { 52 | // Add GrayScale 53 | Colors.Transparent 54 | }; 55 | for (int i = 0; i < 23; i++) 56 | { 57 | list.Add(new HSLColor(1, 0, 0, 1 - i / 22d).ToColor()); 58 | } 59 | 60 | // Add fully saturated colors 61 | for (int i = 0; i < 360; i += 15) 62 | { 63 | list.Add(new HSLColor(1, i, 1, 0.5).ToColor()); 64 | } 65 | 66 | for (double i = 0.9; i > 0.1; i -= 0.1) 67 | { 68 | for (int j = 0; j < 360; j += 15) 69 | { 70 | list.Add(new HSLColor(1, j, 1, i).ToColor()); 71 | } 72 | } 73 | 74 | return list; 75 | } 76 | } 77 | 78 | public Dictionary AccentColorNamesDictionary { get; } = new Dictionary(); 79 | public IEnumerable AccentColorsPalette => AccentColorNamesDictionary.Keys; 80 | #endregion 81 | 82 | #region ThemeMananger 83 | 84 | private Color _AccentColor = Colors.Blue; 85 | 86 | public Color AccentColor 87 | { 88 | get { return _AccentColor; } 89 | set { _AccentColor = value; OnPropertyChanged(nameof(AccentColor)); } 90 | } 91 | 92 | 93 | private Color _HighlightColor = Colors.Orange; 94 | 95 | public Color HighlightColor 96 | { 97 | get { return _HighlightColor; } 98 | set { _HighlightColor = value; OnPropertyChanged(nameof(HighlightColor)); } 99 | } 100 | 101 | 102 | public ReadOnlyObservableCollection BaseThemes => ThemeManager.Current.BaseColors; 103 | private string _BaseTheme = "Light"; 104 | 105 | public string BaseTheme 106 | { 107 | get { return _BaseTheme; } 108 | set { _BaseTheme = value; OnPropertyChanged(nameof(BaseTheme)); ChangeAppTheme(); } 109 | } 110 | 111 | private bool _UseSolidAccent; 112 | public bool UseSolidAccent 113 | { 114 | get { return _UseSolidAccent; } 115 | set { _UseSolidAccent = value; OnPropertyChanged(nameof(UseSolidAccent)); ChangeAppTheme(); } 116 | } 117 | 118 | 119 | internal void ChangeAppTheme() 120 | { 121 | RuntimeThemeGenerator.Current.Options.UseHSL = UseSolidAccent; 122 | 123 | Theme newTheme = new Theme("Custom", 124 | "Custom", 125 | BaseTheme, 126 | AccentColor.ToString(), 127 | AccentColor, 128 | new SolidColorBrush(AccentColor), 129 | true, 130 | false); 131 | 132 | newTheme.Resources["MahApps.Colors.Highlight"] = HighlightColor; 133 | newTheme.Resources["MahApps.Brushes.Highlight"] = new SolidColorBrush(HighlightColor); 134 | 135 | ThemeManager.Current.ChangeTheme(App.Current, newTheme); 136 | } 137 | 138 | #endregion ThemeMananger 139 | 140 | public static Collection AccentColors = new Collection() 141 | { 142 | (Color)App.Current.Resources["MahApps.Colors.Accent"], 143 | (Color)App.Current.Resources["MahApps.Colors.Accent2"], 144 | (Color)App.Current.Resources["MahApps.Colors.Accent3"], 145 | (Color)App.Current.Resources["MahApps.Colors.Accent4"], 146 | (Color)App.Current.Resources["MahApps.Colors.Highlight"], 147 | }; 148 | 149 | } 150 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Model/Person.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Toolkit.Mvvm.ComponentModel; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Text; 6 | using TimsWpfControls.Model; 7 | 8 | namespace TimsWpfControls_Demo.Model 9 | { 10 | public class Person : ObservableValidator 11 | { 12 | 13 | private Gender _Gender; 14 | public Gender Gender 15 | { 16 | get { return _Gender; } 17 | set { SetProperty(ref _Gender, value); } 18 | } 19 | 20 | 21 | private string _FirstName; 22 | 23 | [Required (ErrorMessage = "Everybody has a first name")] 24 | public string FirstName 25 | { 26 | get { return _FirstName; } 27 | set { SetProperty(ref _FirstName, value, true); } 28 | } 29 | 30 | private string _LastName; 31 | 32 | [Required(ErrorMessage = "Everybody has a last name")] 33 | public string LastName 34 | { 35 | get { return _LastName; } 36 | set { SetProperty(ref _LastName, value, true); } 37 | } 38 | 39 | private int _Age; 40 | [Range(0, 120, ErrorMessage = "This is a quite strange age")] 41 | public int Age 42 | { 43 | get { return _Age; } 44 | set { SetProperty(ref _Age, value, true); } 45 | } 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Model/SelectableProperty.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Toolkit.Mvvm.ComponentModel; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using TimsWpfControls.Model; 6 | 7 | namespace TimsWpfControls_Demo.Model 8 | { 9 | public class SelectableProperty : ObservableObject 10 | { 11 | public static List Test { get; } = new List 12 | { 13 | new SelectableProperty("Abc"), 14 | new SelectableProperty("Def"), 15 | new SelectableProperty("Ghi"), 16 | new SelectableProperty("Jkl") 17 | }; 18 | 19 | public SelectableProperty(string content) 20 | { 21 | Content = content; 22 | } 23 | 24 | private bool _IsSelected; 25 | public bool IsSelected 26 | { 27 | get { return _IsSelected; } 28 | set { _IsSelected = value; OnPropertyChanged(nameof(IsSelected)); } 29 | } 30 | 31 | 32 | private string _Content; 33 | public string Content 34 | { 35 | get { return _Content; } 36 | set { _Content = value; OnPropertyChanged(nameof(Content)); } 37 | } 38 | 39 | public override string ToString() 40 | { 41 | return Content; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/TimsWpfControls_Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WinExe 5 | net5.0-windows 6 | true 7 | latest 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Views/BoolToEnumConverterExample.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 36 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Views/BoolToEnumConverterExample.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace TimsWpfControls_Demo.Views 17 | { 18 | /// 19 | /// Interaction logic for BoolToEnumConverterExample.xaml 20 | /// 21 | public partial class BoolToEnumConverterExample : UserControl 22 | { 23 | public BoolToEnumConverterExample() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Views/ExampleViewBase.xaml.cs: -------------------------------------------------------------------------------- 1 | using ICSharpCode.AvalonEdit; 2 | using Microsoft.Xaml.Behaviors; 3 | using System; 4 | using System.CodeDom; 5 | using System.Collections.ObjectModel; 6 | using System.ComponentModel; 7 | using System.Diagnostics; 8 | using System.Reflection; 9 | using System.Windows; 10 | using System.Windows.Controls; 11 | using System.Windows.Data; 12 | using System.Windows.Markup; 13 | using System.Windows.Media; 14 | using TimsWpfControls_Demo.Model; 15 | 16 | namespace TimsWpfControls_Demo.Views 17 | { 18 | /// 19 | /// Interaction logic for ExampleViewBase.xaml 20 | /// 21 | /// 22 | [TemplatePart(Name = nameof(PART_XamlTextEditor), Type = typeof(TextEditor))] 23 | [TemplatePart(Name = nameof(PART_PropertiesList), Type = typeof(DataGrid))] 24 | public partial class ExampleViewBase : ContentControl 25 | { 26 | 27 | 28 | public ExampleViewBase() 29 | { 30 | DemoProperties.CollectionChanged += DemoProperties_CollectionChanged; 31 | } 32 | 33 | private void DemoProperties_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 34 | { 35 | if (e.NewItems is not null) 36 | { 37 | foreach (DemoProperty demoProperty in e.NewItems) 38 | { 39 | demoProperty.PropertyChanged += DemoProperty_PropertyChanged; 40 | } 41 | 42 | FillExampleXaml(); 43 | } 44 | 45 | if (e.OldItems is not null) 46 | { 47 | foreach (DemoProperty demoProperty in e.OldItems) 48 | { 49 | demoProperty.PropertyChanged += DemoProperty_PropertyChanged; 50 | } 51 | 52 | FillExampleXaml(); 53 | } 54 | } 55 | 56 | private void DemoProperty_PropertyChanged(object sender, PropertyChangedEventArgs e) 57 | { 58 | FillExampleXaml(); 59 | } 60 | 61 | private TextEditor PART_XamlTextEditor; 62 | private DataGrid PART_PropertiesList; 63 | 64 | public ObservableCollection DemoProperties { get; } = new ObservableCollection(); 65 | 66 | 67 | 68 | public static readonly DependencyProperty ExampleXamlProperty = DependencyProperty.Register("ExampleXaml", typeof(string), typeof(ExampleViewBase), new PropertyMetadata(null, ExampleXamlChanged)); 69 | public string ExampleXaml 70 | { 71 | get { return (string)GetValue(ExampleXamlProperty); } 72 | set { SetValue(ExampleXamlProperty, value); } 73 | } 74 | 75 | 76 | private static void ExampleXamlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 77 | { 78 | if (d is ExampleViewBase exampleView && exampleView.PART_XamlTextEditor != null) 79 | { 80 | exampleView.FillExampleXaml(); 81 | } 82 | } 83 | 84 | bool canFillXaml = true; 85 | internal void FillExampleXaml () 86 | { 87 | if (!canFillXaml || PART_XamlTextEditor is null) return; 88 | 89 | var result = ExampleXaml; 90 | 91 | if (string.IsNullOrEmpty(result) && ExampleContent is not null) 92 | { 93 | // result = XamlWriter.Save(ExampleContent); 94 | } 95 | else 96 | { 97 | foreach (var property in DemoProperties) 98 | { 99 | result = result.Replace($"[{property.Descriptor.Name}]", property.Value?.ToString()); 100 | } 101 | } 102 | 103 | PART_XamlTextEditor.Text = result; 104 | } 105 | 106 | 107 | /// Identifies the dependency property. 108 | public static readonly DependencyProperty ExampleContentProperty = 109 | DependencyProperty.Register(nameof(ExampleContent), typeof(FrameworkElement), typeof(ExampleViewBase), new PropertyMetadata(null)); 110 | 111 | public object ExampleContent 112 | { 113 | get { return (object)GetValue(ExampleContentProperty); } 114 | set { SetValue(ExampleContentProperty, value); } 115 | } 116 | 117 | public void AddDemoProperty(DependencyPropertyDescriptor descriptor, FrameworkElement bindingTarget) 118 | { 119 | if (descriptor.IsReadOnly || descriptor.DesignTimeOnly || !descriptor.IsBrowsable) return; 120 | 121 | var demoProperty = new DemoProperty(descriptor); 122 | 123 | DemoProperties.Add(demoProperty); 124 | 125 | try 126 | { 127 | demoProperty.Value = bindingTarget.GetValue(descriptor.DependencyProperty); 128 | 129 | var binding = new Binding(nameof(DemoProperty.Value)) 130 | { 131 | Source = demoProperty, 132 | UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 133 | }; 134 | 135 | bindingTarget.SetBinding(descriptor.DependencyProperty, binding); 136 | } 137 | catch (Exception e) 138 | { 139 | Debug.WriteLine($"{e.Message} ({e.Source}"); 140 | } 141 | } 142 | 143 | 144 | public void GetAllProperties(FrameworkElement dependencyObject) 145 | { 146 | ExampleContent = dependencyObject; 147 | 148 | canFillXaml = false; 149 | 150 | foreach (var property in TypeDescriptor.GetProperties(dependencyObject)) 151 | { 152 | if (DependencyPropertyDescriptor.FromProperty(property as PropertyDescriptor) is DependencyPropertyDescriptor descriptor) 153 | { 154 | AddDemoProperty(descriptor, dependencyObject); 155 | } 156 | } 157 | 158 | canFillXaml = true; 159 | FillExampleXaml(); 160 | } 161 | 162 | public override void OnApplyTemplate() 163 | { 164 | base.OnApplyTemplate(); 165 | 166 | PART_XamlTextEditor = this.GetTemplateChild(nameof(PART_XamlTextEditor)) as TextEditor; 167 | FillExampleXaml(); 168 | 169 | if (PART_PropertiesList is not null) PART_PropertiesList.SizeChanged -= PART_PropertiesList_SizeChanged; 170 | PART_PropertiesList = this.GetTemplateChild(nameof(PART_PropertiesList)) as DataGrid; 171 | PART_PropertiesList.SizeChanged += PART_PropertiesList_SizeChanged; 172 | 173 | } 174 | 175 | private void PART_PropertiesList_SizeChanged(object sender, SizeChangedEventArgs e) 176 | { 177 | if (sender is DataGrid dataGrid) 178 | { 179 | foreach (var column in dataGrid.Columns) 180 | { 181 | var size = column.Width; 182 | column.ClearValue(DataGrid.ColumnWidthProperty); 183 | column.SetValue(DataGrid.ColumnWidthProperty, size); 184 | } 185 | } 186 | } 187 | } 188 | } -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Views/FileSelectionTextBoxExample.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | ]]> 14 | 15 | 16 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Views/FileSelectionTextBoxExample.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace TimsWpfControls_Demo.Views 4 | { 5 | /// 6 | /// Interaction logic for FileSelectionTextBoxExample.xaml 7 | /// 8 | public partial class FileSelectionTextBoxExample : UserControl 9 | { 10 | public FileSelectionTextBoxExample() 11 | { 12 | InitializeComponent(); 13 | 14 | ExampleView.GetAllProperties(fileSelectionTextBox); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Views/IntellisenseTextBoxExample.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Views/IntellisenseTextBoxExample.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Windows; 5 | using System.Windows.Controls; 6 | using System.Windows.Data; 7 | using System.Windows.Documents; 8 | using System.Windows.Input; 9 | using System.Windows.Media; 10 | using System.Windows.Media.Imaging; 11 | using System.Windows.Navigation; 12 | using System.Windows.Shapes; 13 | using TimsWpfControls; 14 | 15 | namespace TimsWpfControls_Demo.Views 16 | { 17 | /// 18 | /// Interaction logic for IntellisenseTextBoxExample.xaml 19 | /// 20 | public partial class IntellisenseTextBoxExample : UserControl 21 | { 22 | public IntellisenseTextBoxExample() 23 | { 24 | InitializeComponent(); 25 | 26 | ExampleViewBase.GetAllProperties(IntellisenseTextBox); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /TimsWpfControls/TimsWpfControls_Demo/Views/MultiselectionComboBox.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 66 | 67 | 70 | 71 | 72 | 73 |