mercoledì 10 agosto 2011

Setting a minimum height of the thumb on a vertical scrollbar

This topic has been discussed here http://social.msdn.microsoft.com/Forums/en/wpf/thread/1a7f71bd-d64f-4341-9b7f-9db90afa6e8b
Developing a touch application, the size and the shape of the thumb is very important. In a standard Windows application, the thumb's size is automatically calculated. When the content is very large, the thumb size could be too small to be touched.
To force a minimal size for the thumb:

<Style TargetType="ScrollBar">
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="ScrollBar">
              <Track Name="PART_Track"
                     IsDirectionReversed="true">
                <Track.Resources>
                  <!-- Thumb's minimum height is half of this metric -->
                  <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarButtonHeightKey}">
                    100
                  </sys:Double>
                </Track.Resources>
                <Track.DecreaseRepeatButton>
                  <RepeatButton Command="ScrollBar.PageUpCommand"/>
                </Track.DecreaseRepeatButton>
                <Track.IncreaseRepeatButton>
                  <RepeatButton Command="ScrollBar.PageDownCommand"/>
                </Track.IncreaseRepeatButton>
                <Track.Thumb>
                  <Thumb/>
                </Track.Thumb>
              </Track>
              <ControlTemplate.Triggers>
                <Trigger SourceName="PART_Track" Property="IsEnabled" Value="false">
                  <Setter TargetName="PART_Track" Property="Visibility" Value="Hidden"/>
                </Trigger>
              </ControlTemplate.Triggers>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>

Add this in the namespaces section of the control to access System library:
xmlns:sys="clr-namespace:System;assembly=mscorlib"

http://stackoverflow.com/questions/2003372/how-to-represent-system-constants-in-xaml-like-double-maxvalue.

Nessun commento:

Posta un commento