title: Slider-Button -> CheckBox using Controltemplate with Slider - Click doesn't change ischecked state
body: <p>im trying to make a sliding on-off button controltemplate for a CheckBox control. I decided to use the Slider control since it already delivers the basic functionality needed.
  What i did so far is creating the template with the slider in it and binding the slider value to the ischecked property of the TemplatedParent using a ValueConverter.</p>
  
  <p>So far the ControlTemplate is working as expected when dragging the slider with the mouse, or clicking on the track.
  However if i click on the Thumb i want the Slider to change value too, like you would expect from a normal Checkbox.</p>
  
  <p>If i disable HitTestVisibility of the Slider and put a Transparent rectangle over it the Control works like a normal Checkbox - Clicking toggles the IsChecked state. But with that i lose the feature of sliding it into the desired state.</p>
  
  <p>I have also tried using DataTriggers to set the Slider to the IsChecked state instead of DataBinding it:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;ControlTemplate.Triggers&gt;
      &lt;Setter TargetName="ControlSlider" Property="Value" Value="0"/&gt;
      &lt;Trigger Property="IsChecked" Value="True"&gt;
          &lt;Setter TargetName="ControlSlider" Property="Value" Value="1"/&gt;
      &lt;/Trigger&gt;
  &lt;/ControlTemplate.Triggers&gt;
  </code></pre>
  
  <p>This did work with the "No HitTestVisibility" approach mentioned above, but it doesn't do anything when i use the slider functionality.</p>
  
  <p>This is my Template and the Checkbox:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;ControlTemplate x:Key="OnOffSlider" TargetType="{x:Type CheckBox}"&gt;
      &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center"&gt;
          &lt;Grid Width="Auto" VerticalAlignment="Center"&gt;
              &lt;Slider x:Name="ControlSlider" Maximum="1" Minimum="0" IsEnabled="True" IsHitTestVisible="True" Width="30" TickFrequency="1" IsSnapToTickEnabled="True" Value="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource BooleanConverter}}"&gt;
              &lt;/Slider&gt;
          &lt;/Grid&gt;
          &lt;ContentPresenter Margin="10,0,0,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" RecognizesAccessKey="True" VerticalAlignment="Center" HorizontalAlignment="Center"/&gt;
      &lt;/StackPanel&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;CheckBox&gt;
      &lt;CheckBox.Style&gt;
          &lt;Style TargetType="CheckBox"&gt;
              &lt;Setter Property="Template" Value="{StaticResource OnOffSlider}"/&gt;
          &lt;/Style&gt;
      &lt;/CheckBox.Style&gt;
  &lt;/CheckBox&gt;
  </code></pre>
  
  <p>And the ValueConverter:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class BooleanConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
      {
          if (value is bool)
          {
              return ((bool)value) ? 1 : 0;
          }
          return null;
      }
  
      public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
      {
          if (value is double)
          {
              return ((double)value &gt;= 0.5) ? true : false;
          }
          return null;
      }
  }
  </code></pre>
  
  <p>I want the button to act as a slider with only to states (0 and 1) when dragging the thumb but toggle its state whenever i just click on it.
  Is this possible in xaml only. When yes, how would i make sure the Click event is changin the state properly?</p>