CustomSliderControl.xaml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <UserControl x:Class="Compdfkit_Tools.Common.CustomSliderControl"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:local="clr-namespace:Compdfkit_Tools.Common"
  7. mc:Ignorable="d"
  8. d:DesignHeight="40" d:DesignWidth="400">
  9. <UserControl.Resources>
  10. <DropShadowEffect x:Key="UnhoverThumbEffect" BlurRadius="5" ShadowDepth="0" Opacity="0.3" Color="RoyalBlue"/>
  11. <DropShadowEffect x:Key="HoverThumbEffect" BlurRadius="5" ShadowDepth="0" Opacity="0.5" Color="RoyalBlue"/>
  12. <DropShadowEffect x:Key="DragThumbEffect" BlurRadius="8" ShadowDepth="0" Opacity="1" Color="RoyalBlue"/>
  13. <Style x:Key="BaseSliderStyle" TargetType="Slider">
  14. <Setter Property="Width" Value="200"/>
  15. <Setter Property="Margin" Value="0"/>
  16. <Setter Property="Maximum" Value="{Binding Maxium, Mode=OneWay}"/>
  17. <Setter Property="IsSnapToTickEnabled" Value="True"/>
  18. <Setter Property="IsMoveToPointEnabled" Value="True"></Setter>
  19. <Setter Property="LargeChange" Value="10"></Setter>
  20. <Setter Property="SmallChange" Value="1"></Setter>
  21. <Setter Property="Background" Value="LightGray"></Setter>
  22. <Setter Property="Foreground" Value="RoyalBlue"></Setter>
  23. <Setter Property="SnapsToDevicePixels" Value="True"/>
  24. </Style>
  25. <Style x:Key="DefaultLeftRepeatButtonStyle" TargetType="RepeatButton">
  26. <Setter Property="IsTabStop" Value="False"></Setter>
  27. <Setter Property="Template">
  28. <Setter.Value>
  29. <ControlTemplate TargetType="RepeatButton">
  30. <Border Background="RoyalBlue" Height="4"></Border>
  31. </ControlTemplate>
  32. </Setter.Value>
  33. </Setter>
  34. </Style>
  35. <Style x:Key="DefaultRightRepeatButtonStyle" TargetType="RepeatButton">
  36. <Setter Property="IsTabStop" Value="False"></Setter>
  37. <Setter Property="Template">
  38. <Setter.Value>
  39. <ControlTemplate TargetType="RepeatButton">
  40. <Border Background="Transparent" Height="4"></Border>
  41. </ControlTemplate>
  42. </Setter.Value>
  43. </Setter>
  44. </Style>
  45. <Style x:Key="DefaultSliderThumbStyle" TargetType="Thumb">
  46. <Setter Property="Width" Value="15"></Setter>
  47. <Setter Property="Height" Value="15"></Setter>
  48. <Setter Property="Background" Value="#CDCDCD"></Setter>
  49. <Setter Property="SnapsToDevicePixels" Value="True"></Setter>
  50. <Setter Property="Template">
  51. <Setter.Value>
  52. <ControlTemplate TargetType="Thumb">
  53. <Ellipse Width="{TemplateBinding Width}"
  54. Height="{TemplateBinding Height}"
  55. Fill="{TemplateBinding Background}"
  56. Effect="{StaticResource UnhoverThumbEffect}">
  57. </Ellipse>
  58. <ControlTemplate.Triggers>
  59. <Trigger Property="IsMouseOver" Value="True">
  60. <Setter Property="Effect" Value="{StaticResource HoverThumbEffect}"></Setter>
  61. <Setter Property="Cursor" Value="Hand"></Setter>
  62. </Trigger>
  63. <Trigger Property="IsDragging" Value="True">
  64. <Setter Property="Effect" Value="{StaticResource DragThumbEffect}"></Setter>
  65. </Trigger>
  66. </ControlTemplate.Triggers>
  67. </ControlTemplate>
  68. </Setter.Value>
  69. </Setter>
  70. </Style>
  71. <Style x:Key="SlideStyle" TargetType="{x:Type Slider}" BasedOn="{StaticResource BaseSliderStyle}">
  72. <Setter Property="Template">
  73. <Setter.Value>
  74. <ControlTemplate TargetType="{x:Type Slider}">
  75. <Grid Width="{TemplateBinding Width}">
  76. <Grid.RowDefinitions>
  77. <RowDefinition Height="auto"></RowDefinition>
  78. <RowDefinition MinHeight="{TemplateBinding Height}" Height="auto"></RowDefinition>
  79. <RowDefinition Height="auto"></RowDefinition>
  80. </Grid.RowDefinitions>
  81. <TickBar x:Name="TopTick" Placement="Top" Height="4" Visibility="Collapsed" Fill="{TemplateBinding Foreground}"></TickBar>
  82. <Border Name="TrackBackground"
  83. Grid.Row="1"
  84. Height="4"
  85. Background="{TemplateBinding Background}"/>
  86. <Track Name="PART_Track" Grid.Row="1">
  87. <Track.DecreaseRepeatButton>
  88. <RepeatButton Style="{StaticResource DefaultLeftRepeatButtonStyle }" Command="Slider.DecreaseLarge"></RepeatButton>
  89. </Track.DecreaseRepeatButton>
  90. <Track.Thumb>
  91. <Thumb Style="{StaticResource DefaultSliderThumbStyle}"></Thumb>
  92. </Track.Thumb>
  93. <Track.IncreaseRepeatButton>
  94. <RepeatButton Style="{StaticResource DefaultRightRepeatButtonStyle}" Command="Slider.IncreaseLarge"></RepeatButton>
  95. </Track.IncreaseRepeatButton>
  96. </Track>
  97. <TickBar x:Name="BottomTick" Grid.Row="2" Placement="Bottom" Height="4" Visibility="Collapsed" Fill="Red"></TickBar>
  98. </Grid>
  99. <ControlTemplate.Triggers>
  100. <Trigger Property="TickPlacement" Value="Both">
  101. <Setter TargetName="TopTick" Property="Visibility" Value="Visible"></Setter>
  102. <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"></Setter>
  103. </Trigger>
  104. <Trigger Property="TickPlacement" Value="BottomRight">
  105. <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"></Setter>
  106. </Trigger>
  107. <Trigger Property="TickPlacement" Value="TopLeft">
  108. <Setter Property="Visibility" Value="Visible"></Setter>
  109. </Trigger>
  110. </ControlTemplate.Triggers>
  111. </ControlTemplate>
  112. </Setter.Value>
  113. </Setter>
  114. </Style>
  115. </UserControl.Resources>
  116. <Grid>
  117. <Slider Name="slider" Value="{Binding SliderValue, Mode=TwoWay}" Style="{StaticResource SlideStyle}" TickPlacement="Both" Width="{Binding SliderWidth, Mode=OneWay}"></Slider>
  118. </Grid>
  119. </UserControl>