ScrollViewer for Lefties

Josh says “Windows Presentation Foundation (aka WPF, aka Avalon) is the best thing to happen to Tablet PC's.”

Josh, I couldn't have said that better...  well done!  (We're trying hard to live up to your expectations, anyway. :-)

This reminds me -- at a recent talk, I happened to mention (to a group of Tablet PC developers) how ScrollViewer could be re-styled to align the scrollbar on the left, for left-handed users.  The response was quite enthusiastic!  Here's the XAML:

<Application

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

  <Application.Resources>

    <Style x:Key="LeftieScrollViewer" TargetType="{x:Type ScrollViewer}">

      <Setter Property="Template">

        <Setter.Value>

          <ControlTemplate>

            <Grid>

              <Grid.ColumnDefinitions>

                <ColumnDefinition Width="Auto"/>

                <ColumnDefinition Width="*"/>

              </Grid.ColumnDefinitions>

              <Grid.RowDefinitions>

                <RowDefinition Height="*"/>

                <RowDefinition Height="Auto"/>

              </Grid.RowDefinitions>

              <Border Grid.Row="0" Grid.Column="1">

                <ScrollContentPresenter Content="{TemplateBinding ScrollViewer.Content}" />

              </Border>

              <ScrollBar

                  Name="PART_VerticalScrollBar" Orientation="Vertical" Grid.Row="0" Grid.Column="0"

                  Minimum="0" Maximum="{TemplateBinding ScrollViewer.ScrollableHeight}"

                  Value="{TemplateBinding ScrollViewer.VerticalOffset}"

                  ViewportSize="{TemplateBinding ScrollViewer.ViewportHeight}"

                  Visibility="{TemplateBinding ScrollViewer.ComputedVerticalScrollBarVisibility}" />

              <ScrollBar

                  Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1" Grid.Column="1"

                  Minimum="0" Maximum="{TemplateBinding ScrollViewer.ScrollableWidth}"

                  Value="{TemplateBinding ScrollViewer.HorizontalOffset}"

                  ViewportSize="{TemplateBinding ScrollViewer.ViewportWidth}"

                  Visibility="{TemplateBinding ScrollViewer.ComputedHorizontalScrollBarVisibility }" />

            </Grid>

          </ControlTemplate>

        </Setter.Value>

      </Setter>

    </Style>

  </Application.Resources>

</Application>

Updated: Thu, 09 Mar 2006 07:48:14 GMT