mooshon78

Hello there.

This is my scrollbar style :

Code Snippet

<Style x:Key="ScrollBarStyle1" TargetType="{x:Type ScrollBar}">

<Setter Property="Stylus.IsPressAndHoldEnabled" Value="true"/>

<Setter Property="Stylus.IsFlicksEnabled" Value="false"/>

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="{x:Type ScrollBar}">

<Grid Width="35" x:Name="ScrollBarGrid" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

<Grid.RowDefinitions>

<RowDefinition Height="30"/>

<RowDefinition Height="*"/>

<RowDefinition Height="30"/>

</Grid.RowDefinitions>

<Rectangle Fill="#FFE5E3E3" Stroke="#FF908E8E" RadiusX="13" RadiusY="13" Margin="4,0,4,0" Grid.RowSpan="3"/>

<Viewbox Stretch="Fill"

Grid.RowSpan="1"

Margin="7.5,5,7.5,5" Height="20" Width="20" VerticalAlignment="Top">

<RepeatButton MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Style="{StaticResource ScrollBarLineButtonStyle}" Command="{x:Static ScrollBar.LineUpCommand}" />

</Viewbox>

<Track HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto" Grid.Row="1" Grid.RowSpan="1" Maximum="93" Value="0" ViewportSize="90" IsDirectionReversed="True">

<Track.Thumb>

<Thumb Style="{DynamicResource ThumbStyle2}" />

</Track.Thumb>

<Track.DecreaseRepeatButton>

<RepeatButton Content="RepeatButton" Template="{DynamicResource RepeatButtonControlTemplate1}" Command="{x:Static ScrollBar.PageUpCommand}"/>

</Track.DecreaseRepeatButton>

<Track.IncreaseRepeatButton>

<RepeatButton Content="RepeatButton" Template="{DynamicResource RepeatButtonControlTemplate1}" Command="{x:Static ScrollBar.PageDownCommand}"/>

</Track.IncreaseRepeatButton>

</Track>

<Viewbox Grid.Row="2"

Stretch="Fill"

Margin="7.5,5,7.5,5"

Grid.RowSpan="1" VerticalAlignment="Bottom" Height="20" Width="20">

<RepeatButton MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Style="{DynamicResource RepeatButtonDownStyle}" Command="{x:Static ScrollBar.LineDownCommand}" />

</Viewbox>

</Grid>

</ControlTemplate>

</Setter.Value>

</Setter>

<Style.Triggers>

<Trigger Property="Orientation" Value="Horizontal">

<Setter Property="Width" Value="Auto"/>

<Setter Property="MinWidth" Value="0"/>

<Setter Property="Height" Value="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}"/>

<Setter Property="MinHeight" Value="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}"/>

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="{x:Type ScrollBar}">

<Grid Background="{TemplateBinding Background}">

<Grid.ColumnDefinitions>

<ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"/>

<ColumnDefinition Width="0.00001*"/>

<ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"/>

</Grid.ColumnDefinitions>

<Viewbox Stretch="Fill">

<RepeatButton MinHeight="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}" Style="{StaticResource ScrollBarLineButtonStyle}" Width="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" Content="M 0 4 L 4 8 L 4 0 Z" Command="{x:Static ScrollBar.LineLeftCommand}"/>

</Viewbox>

<Viewbox Grid.Column="2" Stretch="Fill">

<RepeatButton MinHeight="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}" Style="{StaticResource ScrollBarLineButtonStyle}" Width="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" Content="M 0 0 L 0 8 L 4 4 Z" Command="{x:Static ScrollBar.LineRightCommand}"/>

</Viewbox>

</Grid>

</ControlTemplate>

</Setter.Value>

</Setter>

</Trigger>

</Style.Triggers>

</Style>

now the problem is with the Thumb template. i can't seem to find why the thumb won't move on clicking the repeat buttons that scroll my viewer (the ones that in the ViewBoxes).

the scrolling happens fine however the Thumb template in my Tracker doesn't move as it does in the original ScrollBar Template.

I know i am missing something so here is my shout out for help.



Re: Windows Presentation Foundation (WPF) scrollviewer templates

Yi-Lun Luo - MSFT

Hello, you must set your Track¡¯s Name to PART_Track:

<Track x:Name=¡±PART_Track¡± ¡­>

When defining your own ControlTemplate, you should make sure not to remove any element whose name begins with ¡°PART¡±, or your Control won¡¯t behave properly.






Re: Windows Presentation Foundation (WPF) scrollviewer templates

Marlon Grech

If I might add a suggestion, I use this trick. Whenever I have to do a control template for a control, I always go to defenition in VS2005 so that I check if the controls in the control template need to have a name... for instance PART_TRACK can be clearly seen in the defenition of the class as attribute decorators





Re: Windows Presentation Foundation (WPF) scrollviewer templates

mooshon78

thank you.