andrew4582

CustomSlider WPF

Jul 29th, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. /*
  2.      <vw:CustomSlider Minimum="1"
  3.                     AutoToolTipPlacement="TopLeft"
  4.                     AutoToolTipContent="{Binding DateFiltersToolTip}"
  5.                     Maximum="{Binding DateFilters.Count}"
  6.                     TickFrequency="1"
  7.                     TickPlacement="BottomRight"
  8.                     HorizontalAlignment="Left"
  9.                     SmallChange="1" LargeChange="5"
  10.                                 Width="200"
  11.                                 Visibility="Collapsed"
  12.                         ValueChanged="Slider_ValueChanged"/>
  13.      */
  14.     public class CustomSlider : Slider
  15.     {
  16.         public object AutoToolTipContent
  17.         {
  18.             get { return GetValue(AutoToolTipContentProperty); }
  19.             set { SetValue(AutoToolTipContentProperty, value); }
  20.         }
  21.  
  22.         // Using a DependencyProperty as the backing store for AutoToolTip.  This enables animation, styling, binding, etc...
  23.         public static readonly DependencyProperty AutoToolTipContentProperty =
  24.             DependencyProperty.Register("AutoToolTipContent", typeof(object), typeof(CustomSlider), new PropertyMetadata(null));
  25.  
  26.  
  27.         protected override void OnThumbDragStarted(System.Windows.Controls.Primitives.DragStartedEventArgs e)
  28.         {
  29.             base.OnThumbDragStarted(e);
  30.             AutoToolTipObj.Content = this.AutoToolTipContent;
  31.         }
  32.  
  33.         protected override void OnThumbDragDelta(System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  34.         {
  35.             base.OnThumbDragDelta(e);
  36.             AutoToolTipObj.Content = this.AutoToolTipContent;
  37.         }
  38.  
  39.         ToolTip autoToolTipObj;
  40.         public ToolTip AutoToolTipObj
  41.         {
  42.             get
  43.             {
  44.                 if (autoToolTipObj == null)
  45.                 {
  46.                     var fld = typeof(Slider).GetField("_autoToolTip", BindingFlags.NonPublic | BindingFlags.Instance);
  47.                     if (fld != null)
  48.                         autoToolTipObj = fld.GetValue(this) as ToolTip;
  49.                 }
  50.                 return autoToolTipObj;
  51.             }
  52.         }
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment