我正在编写一个自定义滚动条。当鼠标悬停在网格(滚动条)上时,它应该增加它的高度和拇指的高度并改变背景等。除了拇指的高度之外,一切都完成了,因为拇指是网格的子元素而不是它的属性之一。
这是完整的模板代码,它给了我找不到 TargetName“ellipse”的异常。
<ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}">
<Grid MaxHeight="28">
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="2"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition MaxWidth="2"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Track Name="PART_Track" Grid.Column="1" IsDirectionReversed="False">
<Track.DecreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageLeftCommand"
Style="{StaticResource ScrollBarPageButtonStyle}">
</RepeatButton>
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb IsTabStop="False" Margin="0,1,0,1" BorderBrush="{StaticResource StandardBorderBrush}">
<Thumb.Template>
<ControlTemplate TargetType="{x:Type Thumb}">
<Rectangle Height="12" Name="ellipse" Stroke="{StaticResource StandardBorderBrush}"
Fill="{StaticResource StandardBrush}" RadiusX="5" RadiusY="5"></Rectangle>
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageRightCommand"
Style="{StaticResource ScrollBarPageButtonStyle}">
</RepeatButton>
</Track.IncreaseRepeatButton>
</Track>
<Grid.Resources>
<Style TargetType="Grid">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Gray"></Setter>
<Setter TargetName="ellipse" Property="Height" Value="28"></Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter TargetName="ellipse" Property="Height" Value="14"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
</Grid>
</ControlTemplate>