├── .gitignore ├── LICENSE ├── README.md ├── WpfRangeControls.png ├── WpfRangeControls.sln ├── WpfRangeControls ├── Properties │ ├── Resources.resx │ └── Settings.settings ├── RangeAlignment.cs ├── RangeItemsControl.cs ├── RangePanel.cs ├── RangeScrollbar.cs ├── ThemeInfo.cs ├── Themes │ └── Generic.xaml └── WpfRangeControls.csproj └── demo ├── App.xaml ├── App.xaml.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties ├── Resources.resx └── Settings.settings └── demo.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ladislav Šeps 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WpfRangeControls 2 | Customized WPF controls, RangePanel with custom vertical/horizontal positioning, RangeItemsControl with bindable ItemsSource and Visual Studio-like scrollbar with markers 3 | 4 | ![demo screenshot](WpfRangeControls.png) 5 | 6 | ## RangePanel 7 | Custom arrangment panel (similar to stackpanel or canvas) with vertical or horizontal orientation. 8 | Positioning of children is controled by: 9 | 10 | 1. Bounds set by Minimum and maximum properties (like Minimum and Maximum on scrollbar or trackbar) 11 | 12 | 2. And three attached properties on each child element 13 | - RangePanel.Position: Position of child in RangePanel, similar to Value in scrollbar or trackbar 14 | - RangePanel.Alignment: (Begin, Center, End) which part of Children is aligned to Position. (See blue bars on screenshot) 15 | - RangePanel.Range: Width (on horizontal panel) or Height (on vertical) of element in relative units (full length is (Maximum - Minimum)) 16 | - Minimum 0, Maximum 60, RangePanel.Range 20 => item width will be one third panel width 17 | 18 | ## RangeItemsControl 19 | ItemsControl with RangePanel as ItemsPanel 20 | - ItemsSource and ItemTemplate can be used to visualize data collection 21 | 22 | ## RangeScrollbar 23 | Scrollbar with RangePanel overlay. 24 | - can be used as ScrollBar with markings like the one in Eclipse or Visual studio 25 | - see bottom and right of screenshot 26 | - usable as ItemsControl, support ItemsSource bindings and multi element content 27 | -------------------------------------------------------------------------------- /WpfRangeControls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ttxman/WpfRangeControls/15d8c3442af82e75d6cf4d452790ff867316bd9a/WpfRangeControls.png -------------------------------------------------------------------------------- /WpfRangeControls.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.22823.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfRangeControls", "WpfRangeControls\WpfRangeControls.csproj", "{8BD896F3-4860-4797-9FE5-78E2980B4F75}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "demo", "demo\demo.csproj", "{E03FDE0D-9FC8-4B44-8796-C4EBB592A738}" 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 | {8BD896F3-4860-4797-9FE5-78E2980B4F75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {8BD896F3-4860-4797-9FE5-78E2980B4F75}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {8BD896F3-4860-4797-9FE5-78E2980B4F75}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {8BD896F3-4860-4797-9FE5-78E2980B4F75}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {E03FDE0D-9FC8-4B44-8796-C4EBB592A738}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {E03FDE0D-9FC8-4B44-8796-C4EBB592A738}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {E03FDE0D-9FC8-4B44-8796-C4EBB592A738}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {E03FDE0D-9FC8-4B44-8796-C4EBB592A738}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /WpfRangeControls/Properties/Resources.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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /WpfRangeControls/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /WpfRangeControls/RangeAlignment.cs: -------------------------------------------------------------------------------- 1 | namespace WpfRangeControls 2 | { 3 | public enum RangeAlignment 4 | { 5 | Begin, 6 | End, 7 | Center 8 | } 9 | } -------------------------------------------------------------------------------- /WpfRangeControls/RangeItemsControl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | using System.Windows.Data; 10 | using System.Windows.Documents; 11 | using System.Windows.Input; 12 | using System.Windows.Media; 13 | using System.Windows.Media.Imaging; 14 | using System.Windows.Navigation; 15 | using System.Windows.Shapes; 16 | 17 | namespace WpfRangeControls 18 | { 19 | public class RangeItemsControl : ItemsControl 20 | { 21 | 22 | public static DependencyProperty OrientationProperty = RangePanel.OrientationProperty.AddOwner(typeof(RangeItemsControl)); 23 | 24 | public static DependencyProperty MinimumProperty = RangePanel.MinimumProperty.AddOwner(typeof(RangeItemsControl)); 25 | 26 | public static DependencyProperty MaximumProperty = RangePanel.MaximumProperty.AddOwner(typeof(RangeItemsControl)); 27 | 28 | static RangeItemsControl() 29 | { 30 | DefaultStyleKeyProperty.OverrideMetadata(typeof(RangeItemsControl), new FrameworkPropertyMetadata(typeof(RangeItemsControl))); 31 | } 32 | 33 | 34 | public Orientation Orientation 35 | { 36 | get { return (Orientation)GetValue(OrientationProperty); } 37 | set { SetValue(OrientationProperty, value); } 38 | } 39 | 40 | /// 41 | /// Minimum restricts the minimum value of range 42 | /// 43 | [Bindable(true), Category("Behavior")] 44 | public double Minimum 45 | { 46 | get { return (double)GetValue(MinimumProperty); } 47 | set { SetValue(MinimumProperty, value); } 48 | } 49 | 50 | 51 | /// 52 | /// Minimum restricts the minimum value of range 53 | /// 54 | [Bindable(true), Category("Behavior")] 55 | public double Maximum 56 | { 57 | get { return (double)GetValue(MaximumProperty); } 58 | set { SetValue(MaximumProperty, value); } 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /WpfRangeControls/RangePanel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows; 9 | using System.Windows.Controls; 10 | using System.Windows.Controls.Primitives; 11 | using System.Windows.Media; 12 | 13 | namespace WpfRangeControls 14 | { 15 | public class RangePanel : Panel 16 | { 17 | 18 | static RangePanel() 19 | { 20 | ClipToBoundsProperty.OverrideMetadata(typeof(RangePanel), new FrameworkPropertyMetadata(true)); 21 | 22 | HorizontalAlignmentProperty.OverrideMetadata(typeof(RangePanel), new FrameworkPropertyMetadata(HorizontalAlignment.Stretch)); 23 | 24 | VerticalAlignmentProperty.OverrideMetadata(typeof(RangePanel), new FrameworkPropertyMetadata(VerticalAlignment.Stretch)); 25 | } 26 | 27 | public static double GetPosition(DependencyObject obj) 28 | { 29 | return (double)obj.GetValue(PositionProperty); 30 | } 31 | 32 | public static void SetPosition(DependencyObject obj, double value) 33 | { 34 | obj.SetValue(PositionProperty, value); 35 | } 36 | 37 | // Using a DependencyProperty as the backing store for Position. This enables animation, styling, binding, etc... 38 | public static readonly DependencyProperty PositionProperty = 39 | DependencyProperty.RegisterAttached( 40 | "Position", 41 | typeof(double), 42 | typeof(RangePanel), 43 | new FrameworkPropertyMetadata( 44 | (double)0, 45 | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsParentMeasure) 46 | ); 47 | 48 | 49 | 50 | public static RangeAlignment GetAlignment(DependencyObject obj) 51 | { 52 | return (RangeAlignment)obj.GetValue(AlignmentProperty); 53 | } 54 | 55 | public static void SetAlignment(DependencyObject obj, RangeAlignment value) 56 | { 57 | obj.SetValue(AlignmentProperty, value); 58 | } 59 | 60 | // Using a DependencyProperty as the backing store for Alignment. This enables animation, styling, binding, etc... 61 | public static readonly DependencyProperty AlignmentProperty = 62 | DependencyProperty.RegisterAttached( 63 | "Alignment", 64 | typeof(RangeAlignment), 65 | typeof(RangePanel), 66 | new FrameworkPropertyMetadata( 67 | RangeAlignment.Center, 68 | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsParentMeasure) 69 | , new ValidateValueCallback(IsValidRangeAlignment)); 70 | 71 | private static bool IsValidRangeAlignment(object value) 72 | { 73 | var val = (RangeAlignment)value; 74 | return (val == RangeAlignment.Begin || val == RangeAlignment.Center || val == RangeAlignment.End); 75 | } 76 | 77 | public static double GetRange(DependencyObject obj) 78 | { 79 | return (double)obj.GetValue(RangeProperty); 80 | } 81 | 82 | public static void SetRange(DependencyObject obj, double value) 83 | { 84 | obj.SetValue(RangeProperty, value); 85 | } 86 | 87 | // Using a DependencyProperty as the backing store for Range. This enables animation, styling, binding, etc... 88 | public static readonly DependencyProperty RangeProperty = 89 | DependencyProperty.RegisterAttached( 90 | "Range", 91 | typeof(double), 92 | typeof(RangePanel), 93 | new FrameworkPropertyMetadata( 94 | double.NaN, 95 | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsParentMeasure)); 96 | 97 | 98 | 99 | protected override bool HasLogicalOrientation 100 | { 101 | get 102 | { 103 | return true; 104 | } 105 | } 106 | 107 | protected override Orientation LogicalOrientation 108 | { 109 | get 110 | { 111 | return this.Orientation; 112 | } 113 | } 114 | 115 | public Orientation Orientation 116 | { 117 | get { return (Orientation)GetValue(OrientationProperty); } 118 | set { SetValue(OrientationProperty, value); } 119 | } 120 | 121 | // Using a DependencyProperty as the backing store for Orientation. This enables animation, styling, binding, etc... 122 | public static readonly DependencyProperty OrientationProperty = 123 | DependencyProperty.Register( 124 | "Orientation", 125 | typeof(Orientation), 126 | typeof(RangePanel), 127 | new FrameworkPropertyMetadata( 128 | Orientation.Vertical, 129 | FrameworkPropertyMetadataOptions.AffectsMeasure, 130 | new PropertyChangedCallback(OnOrientationChanged)), 131 | new ValidateValueCallback(IsValidOrientation)); 132 | 133 | private static bool IsValidOrientation(object o) 134 | { 135 | Orientation value = (Orientation)o; 136 | return value == Orientation.Horizontal || value == Orientation.Vertical; 137 | } 138 | 139 | private static void OnOrientationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 140 | { 141 | var el = (d as UIElement); 142 | if (el == null) 143 | return; 144 | el.InvalidateMeasure(); 145 | } 146 | 147 | private static bool IsValidDoubleValue(object value) 148 | { 149 | double d = (double)value; 150 | return !(double.IsNaN(d) || double.IsInfinity(d)); 151 | } 152 | 153 | #region minimum property 154 | public static readonly DependencyProperty MinimumProperty = 155 | DependencyProperty.Register( 156 | "Minimum", 157 | typeof(double), 158 | typeof(RangePanel), 159 | new FrameworkPropertyMetadata( 160 | 0.0d, 161 | FrameworkPropertyMetadataOptions.AffectsMeasure, 162 | new PropertyChangedCallback(OnMinimumChanged), 163 | new CoerceValueCallback(CoerceMinimum)), 164 | new ValidateValueCallback(IsValidDoubleValue)); 165 | 166 | 167 | private static object CoerceMinimum(DependencyObject d, object value) 168 | { 169 | RangePanel pan = (RangePanel)d; 170 | double max = pan.Maximum; 171 | if ((double)value > max) 172 | { 173 | return max; 174 | } 175 | return value; 176 | } 177 | 178 | 179 | /// 180 | /// Minimum restricts the minimum value of range 181 | /// 182 | [Bindable(true), Category("Behavior")] 183 | public double Minimum 184 | { 185 | get { return (double)GetValue(MinimumProperty); } 186 | set { SetValue(MinimumProperty, value); } 187 | } 188 | 189 | /// 190 | /// Called when MinimumProperty is changed on "d." 191 | /// 192 | private static void OnMinimumChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 193 | { 194 | RangePanel pan = (RangePanel)d; 195 | pan.CoerceValue(MaximumProperty); 196 | pan.OnMinimumChanged((double)e.OldValue, (double)e.NewValue); 197 | } 198 | 199 | /// 200 | /// This method is invoked when the Minimum property changes. 201 | /// 202 | /// The old value of the Minimum property. 203 | /// The new value of the Minimum property. 204 | protected virtual void OnMinimumChanged(double oldMinimum, double newMinimum) 205 | { 206 | } 207 | 208 | #endregion 209 | 210 | #region Maximum property 211 | public static readonly DependencyProperty MaximumProperty = 212 | DependencyProperty.Register( 213 | "Maximum", 214 | typeof(double), 215 | typeof(RangePanel), 216 | new FrameworkPropertyMetadata( 217 | 100.0d, 218 | FrameworkPropertyMetadataOptions.AffectsMeasure, 219 | new PropertyChangedCallback(OnMaximumChanged), 220 | new CoerceValueCallback(CoerceMaximum)), 221 | new ValidateValueCallback(IsValidDoubleValue)); 222 | 223 | 224 | private static object CoerceMaximum(DependencyObject d, object value) 225 | { 226 | RangePanel pan = (RangePanel)d; 227 | double min = pan.Minimum; 228 | if ((double)value < min) 229 | { 230 | return min; 231 | } 232 | return value; 233 | } 234 | /// 235 | /// Minimum restricts the minimum value of range 236 | /// 237 | [Bindable(true), Category("Behavior")] 238 | public double Maximum 239 | { 240 | get { return (double)GetValue(MaximumProperty); } 241 | set { SetValue(MaximumProperty, value); } 242 | } 243 | 244 | /// 245 | /// Called when MinimumProperty is changed on "d." 246 | /// 247 | private static void OnMaximumChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 248 | { 249 | RangePanel pan = (RangePanel)d; 250 | // pan.CoerceValue(MinimumProperty); 251 | pan.OnMaximumChanged((double)e.OldValue, (double)e.NewValue); 252 | } 253 | 254 | 255 | /// 256 | /// This method is invoked when the Maximum property changes. 257 | /// 258 | /// The old value of the Maximum property. 259 | /// The new value of the Maximum property. 260 | protected virtual void OnMaximumChanged(double oldMaximum, double newMaximum) 261 | { 262 | } 263 | 264 | #endregion 265 | 266 | public RangePanel() 267 | { 268 | ClipToBounds = true; 269 | } 270 | 271 | 272 | /// 273 | /// this should do same thing as canvas arrange 274 | /// 275 | /// 276 | /// 277 | protected override Size MeasureOverride(Size constraint) 278 | { 279 | 280 | double w = 0; 281 | double h = 0; 282 | 283 | foreach (UIElement child in InternalChildren) 284 | { 285 | child.Measure(constraint); 286 | var s = GetItemPosition(constraint,child); 287 | 288 | if (s.Right > w) 289 | w = s.Right; 290 | 291 | if (s.Bottom > h) 292 | h = s.Bottom; 293 | } 294 | 295 | if (!double.IsNaN(this.Width)) 296 | w = this.Width; 297 | 298 | 299 | if (!double.IsNaN(this.Height)) 300 | h = this.Height; 301 | 302 | if (HorizontalAlignment == HorizontalAlignment.Stretch) 303 | w = 0; 304 | 305 | if (VerticalAlignment == VerticalAlignment.Stretch) 306 | h = 0; 307 | 308 | return new Size(w, h); 309 | } 310 | 311 | 312 | private double ScaleToSize(double val, double size) 313 | { 314 | var len = Maximum - Minimum; 315 | return val / len * size; 316 | } 317 | /// 318 | /// this should do same thing as canvas arrange 319 | /// 320 | /// 321 | /// 322 | protected override Size ArrangeOverride(Size arrangeSize) 323 | { 324 | foreach (UIElement item in InternalChildren) 325 | { 326 | Rect r = GetItemPosition(arrangeSize, item); 327 | item.Arrange(r); 328 | } 329 | return arrangeSize; 330 | } 331 | 332 | private Rect GetItemPosition(Size arrangeSize, UIElement item) 333 | { 334 | if (item is ContentPresenter && item.ReadLocalValue(PositionProperty) == DependencyProperty.UnsetValue) 335 | { //should this be recursive until uielement with set Position is found? 336 | 337 | var elm = VisualTreeHelper.GetChild(item, 0) as UIElement; 338 | if (elm != null) 339 | item = elm; 340 | } 341 | 342 | 343 | var pos = GetPosition(item); 344 | var range = GetRange(item); 345 | var align = GetAlignment(item); 346 | 347 | double x = 0; 348 | double y = 0; 349 | double w = item.DesiredSize.Width; 350 | double h = item.DesiredSize.Height; 351 | 352 | if (!double.IsNaN(range)) 353 | { 354 | if ((Orientation == Orientation.Horizontal)) 355 | w = ScaleToSize(range, arrangeSize.Width); 356 | else 357 | h = ScaleToSize(range, arrangeSize.Height); 358 | } 359 | 360 | 361 | Size size; 362 | 363 | if (Orientation == Orientation.Horizontal) 364 | { 365 | x = ScaleToSize(pos, arrangeSize.Width); 366 | size = new Size(w, arrangeSize.Height); 367 | x -= SizeAdjustment(align, w); 368 | } 369 | else 370 | { 371 | y = ScaleToSize(pos, arrangeSize.Height); 372 | size = new Size(arrangeSize.Width, h); 373 | y -= SizeAdjustment(align, h); 374 | } 375 | 376 | return new Rect(new Point(x, y), size); 377 | } 378 | 379 | private static double SizeAdjustment(RangeAlignment align, double size) 380 | { 381 | switch (align) //how to place item beside given pos 382 | { 383 | case RangeAlignment.Center: 384 | return size / 2; 385 | case RangeAlignment.End: 386 | return size; 387 | } 388 | 389 | return 0; 390 | } 391 | 392 | protected override Geometry GetLayoutClip(Size layoutSlotSize) 393 | { 394 | return base.GetLayoutClip(layoutSlotSize); 395 | } 396 | } 397 | 398 | } 399 | -------------------------------------------------------------------------------- /WpfRangeControls/RangeScrollbar.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.Controls.Primitives; 9 | using System.Windows.Data; 10 | using System.Windows.Documents; 11 | using System.Windows.Input; 12 | using System.Windows.Media; 13 | using System.Windows.Media.Imaging; 14 | using System.Windows.Navigation; 15 | using System.Windows.Shapes; 16 | using System.Windows.Markup; 17 | using System.Collections.ObjectModel; 18 | using System.Collections.Specialized; 19 | using System.Globalization; 20 | using System.ComponentModel; 21 | using System.Collections; 22 | 23 | namespace WpfRangeControls 24 | { 25 | 26 | [TemplatePart(Name = "PART_RangeOverlay", Type = typeof(RangeItemsControl))] 27 | [ContentProperty("Items")] 28 | public class RangeScrollbar : ScrollBar, INotifyPropertyChanged 29 | { 30 | 31 | static RangeScrollbar() 32 | { 33 | DefaultStyleKeyProperty.OverrideMetadata(typeof(RangeScrollbar), new FrameworkPropertyMetadata(typeof(RangeScrollbar))); 34 | } 35 | 36 | public RangeScrollbar() 37 | { 38 | 39 | } 40 | 41 | public override void OnApplyTemplate() 42 | { 43 | base.OnApplyTemplate(); 44 | _RangeControl = base.GetTemplateChild("PART_RangeOverlay") as RangeItemsControl; 45 | 46 | 47 | if (_RangeControl == null) 48 | return; 49 | 50 | if (_iItems != null && _iItems.Count > 0) 51 | { 52 | foreach (var item in _iItems) 53 | _RangeControl.Items.Add(item); 54 | 55 | if (PropertyChanged != null) 56 | PropertyChanged(this, new PropertyChangedEventArgs("Items")); 57 | 58 | _iItems = null; 59 | 60 | } 61 | } 62 | 63 | 64 | RangeItemsControl _RangeControl; 65 | [Bindable(false), Category("Content")] 66 | public RangeItemsControl RangeControl 67 | { 68 | get { return _RangeControl; } 69 | } 70 | 71 | 72 | ObservableCollection _iItems = new ObservableCollection(); 73 | 74 | public event PropertyChangedEventHandler PropertyChanged; 75 | 76 | [Bindable(true), Category("Content")] 77 | public IList Items 78 | { 79 | get 80 | { 81 | if (_RangeControl == null) 82 | ApplyTemplate(); 83 | if (_RangeControl != null) 84 | return _RangeControl.Items; 85 | 86 | return _iItems; 87 | } 88 | } 89 | 90 | public static readonly DependencyProperty ItemsSourceProperty = ItemsControl.ItemsSourceProperty.AddOwner(typeof(RangeScrollbar)); 91 | [Bindable(true), Category("Content")] 92 | public IEnumerable ItemsSource 93 | { 94 | get { return (IEnumerable)GetValue(ItemsSourceProperty); } 95 | set { SetValue(ItemsSourceProperty, value); } 96 | } 97 | 98 | 99 | public static readonly DependencyProperty ItemTemplateProperty = ItemsControl.ItemTemplateProperty.AddOwner(typeof(RangeScrollbar)); 100 | [Bindable(true), Category("Content")] 101 | public DataTemplate ItemTemplate 102 | { 103 | get { return (DataTemplate)GetValue(ItemTemplateProperty); } 104 | set { SetValue(ItemTemplateProperty, value); } 105 | } 106 | 107 | public static readonly DependencyProperty AlternationCountProperty = ItemsControl.AlternationCountProperty.AddOwner(typeof(RangeScrollbar)); 108 | [Bindable(true), Category("Content")] 109 | public int AlternationCount 110 | { 111 | get { return (int)GetValue(AlternationCountProperty); } 112 | set { SetValue(AlternationCountProperty, value); } 113 | } 114 | 115 | 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /WpfRangeControls/ThemeInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] 11 | -------------------------------------------------------------------------------- /WpfRangeControls/Themes/Generic.xaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 34 | 35 | 36 | 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 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 133 | 134 | 135 | 136 | 137 | 138 | 145 | 146 | 147 | 148 | 149 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 358 | 359 | 360 | 361 | 362 | 363 | 370 | 371 | 372 | 373 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 476 | 477 | -------------------------------------------------------------------------------- /WpfRangeControls/WpfRangeControls.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net6.0-windows 4 | Library 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | SettingsSingleFileGenerator 18 | Settings.Designer.cs 19 | 20 | 21 | -------------------------------------------------------------------------------- /demo/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /demo/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace demo 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /demo/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | positioned on 50%, fixed height align begin center end 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | positioned on 25% fixed width 5px horizontal alignment 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 75% fixed width 5px horizontal alignment, margin 3 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 50%, 8px width, horizontal alignment, margin 2 10% 25% 66% range 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | databinding RangeItemsControl RangeScrollbar 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 10 119 | 25 120 | 35 121 | 50 122 | 60 123 | 75 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 10 172 | 25 173 | 35 174 | 50 175 | 60 176 | 75 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 10 195 | 25 196 | 35 197 | 50 198 | 60 199 | 75 200 | 88 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | -------------------------------------------------------------------------------- /demo/MainWindow.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 | using WpfRangeControls; 16 | 17 | namespace demo 18 | { 19 | /// 20 | /// Interaction logic for MainWindow.xaml 21 | /// 22 | public partial class MainWindow : Window 23 | { 24 | public MainWindow() 25 | { 26 | InitializeComponent(); 27 | } 28 | 29 | private void button_Click(object sender, RoutedEventArgs e) 30 | { 31 | //ascbar.Marks.Add(new Rectangle() { Fill = Brushes.Green, Width = 10, Height = 10 }); 32 | } 33 | 34 | private void button_Copy_Click(object sender, RoutedEventArgs e) 35 | { 36 | //var pos = AdvancedScrollbar.GetPosition(mover); 37 | //AdvancedScrollbar.SetPosition(mover, (pos + 13) % ascbar.Maximum); 38 | 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /demo/Properties/Resources.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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /demo/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /demo/demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net6.0-windows 4 | WinExe 5 | true 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | --------------------------------------------------------------------------------