title: Programmatically Focus on a ScrollBar
body: <p>In the code shown,</p>
  
  <ul>
  <li>Why doesn't the focus shift to the ScrollBar element?</li>
  <li>Why does <a href="https://msdn.microsoft.com/en-us/library/system.windows.uielement.focus(v=vs.110).aspx" rel="nofollow">UIElement.Focus</a> (TheScrollBar.Focus) return False?</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/dORMk.gif" rel="nofollow"><img src="https://i.stack.imgur.com/dORMk.gif" alt="enter image description here"></a></p>
  
  <p>XAML:</p>
  
  <pre><code>    &lt;Window x:Class="ScrollBarFocus.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:ScrollBarFocus"
          mc:Ignorable="d"
          ResizeMode="CanMinimize"
          SizeToContent="WidthAndHeight"
          Title="MainWindow"&gt;
      &lt;Grid HorizontalAlignment="Center" VerticalAlignment="Center"&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition/&gt;
              &lt;RowDefinition/&gt;
              &lt;RowDefinition/&gt;
              &lt;RowDefinition/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Button Grid.Row="0" Click="Button_Click" Content="Click me to focus on the ScrollBar"/&gt;
          &lt;ScrollBar x:Name="TheScrollBar" Grid.Row="1" Maximum="99" Orientation="Horizontal" SmallChange="1"/&gt;
          &lt;TextBox BorderBrush="Black" Grid.Row="2" IsReadOnly="True" Text="{Binding ElementName=TheScrollBar, Path=Value, StringFormat={}{0:####0}}" TextAlignment="Center"/&gt;
          &lt;Label x:Name="TheStatus" Grid.Row="3" Height="40" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="400"/&gt;
          &lt;x:Code&gt;
              &lt;![CDATA[
                  void Button_Click(object sender, RoutedEventArgs e) {
                      TheStatus.Content = "TheScrollBar.Focus() == " + TheScrollBar.Focus().ToString();
                  }
              ]]&gt;
          &lt;/x:Code&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>    using System.Windows;
      namespace ScrollBarFocus {
          public partial class MainWindow : Window {
              public MainWindow() {
                  InitializeComponent();
              }
          }
     }
  </code></pre>
  
  <p>I'm obviously missing something here. Does <a href="https://msdn.microsoft.com/en-us/library/system.windows.uielement.focus(v=vs.110).aspx" rel="nofollow">UIElement.Focus</a> not accept focus?</p>