<Window x:Class="Commands.CustomControlWithCommand"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Commands"
    Title="CustomControlWithCommand" Height="500" Width="400"
    >
  <Window.Resources>
    <local:FontStringValueConverter x:Key="StringConverterResource"/>
    <local:FontDoubleValueConverter x:Key="DoubleConverterResource"/>
  </Window.Resources>
  <StackPanel>
    <Border BorderBrush="Black"
            BorderThickness="2"
            Margin="10"
            Width="400"
            Height="400">
      <StackPanel>
        <StackPanel Margin="10">
          <Label HorizontalAlignment="Center">
            Custom Slider that Invokes a Command
          </Label>
          <Border Width="350" Background="LightBlue">            
              <local:CommandSlider x:Name="FontSlider"
                                    Background="AliceBlue"
                                    Minimum="0"
                                    Maximum="60"
                                    Value="12"
                                    TickFrequency="5"
                                    Height="50"
                                    Width="275"
                                    TickPlacement="BottomRight"
                                    LargeChange="5"
                                    SmallChange="5"
                                    AutoToolTipPlacement="BottomRight"
                                    AutoToolTipPrecision="0"
                                    Command="{x:Static local:CustomControlWithCommand.FontUpdateCommand}"
                                    CommandTarget="{Binding ElementName=txtBoxTarget}"
                                    CommandParameter="{Binding ElementName=FontSlider,
                                     Path=Value,
                                     Converter={StaticResource DoubleConverterResource}}"
                                    Focusable="False"/>             
            
          </Border>
        </StackPanel>
        <Border BorderBrush="Black"
                BorderThickness="1"
                Height="150"
                Width="300"
                Margin="15">
          <StackPanel Margin="5">
            <CheckBox IsChecked="False"
                      Checked="OnReadOnlyChecked"
                      Unchecked="OnReadOnlyUnChecked"
                      Content="Read Only"
                      Margin="5"
                      FontSize="12" />
            <TextBox Name="txtBoxTarget" Height="100" Width="275" Margin="3">
              <TextBox.CommandBindings>
                <CommandBinding Command="{x:Static local:CustomControlWithCommand.FontUpdateCommand}"
                            Executed="SliderUpdateExecuted"
                            CanExecute="SliderUpdateCanExecute" />
              </TextBox.CommandBindings>              
              Hello
            </TextBox>
          </StackPanel>
        </Border>
        <StackPanel>
          <Label HorizontalAlignment="Center">
            More Command Sources for the Font Update Command
          </Label>
          <StackPanel Margin="10" HorizontalAlignment="Left" Background="LightBlue">
            <Button Command="{x:Static local:CustomControlWithCommand.FontUpdateCommand}"
                  CommandTarget="{Binding ElementName=txtBoxTarget}"
                  CommandParameter="{Binding ElementName=txtValue,
                                     Path=Text,
                                     Converter={
                                     StaticResource StringConverterResource}}"
                  Height="50"
                  Width="150"
                  Margin="1">
              Update Font Via Command
            </Button>
            <TextBox Name="txtValue"
                     MaxLength="2"
                     Width="25"
                     Background="AliceBlue"
                     Margin="0,0,0,3">5</TextBox>
          </StackPanel>
        </StackPanel>
      </StackPanel>
    </Border>
  </StackPanel>
</Window>
