开发者

Fill the slider control as it progresses

开发者 https://www.devze.com 2023-02-06 23:06 出处:网络
I have a horizontal slider control that I want to fill the Track with a certain color as it progresses to the right.

I have a horizontal slider control that I want to fill the Track with a certain color as it progresses to the right.

I'm looking at the default implementation (the relevant part below):

        <ControlTemplate x:Key="HorizontalSlider" TargetType="{x:Type Slider}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto" MinHeight="{TemplateBinding Slider.MinHeight}"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TickBar Name="TopTick" SnapsToDevicePixels="True" Placement="Top" Fill="{StaticResource GlyphBrush}"
                    Height="4" Visibility="Collapsed" />
            <Border Name="TrackBackground" Margin="0" CornerRadius="2" Height="4" Grid.Row="1"
                    Background="{StaticResource LightBrush}" BorderBrush="{StaticResource NormalBorderBrush}"
                    BorderThickness="1" />
            <Track Grid.Row="1" Name="PART_Track">
                <Track.DecreaseRepeatButton>
                    <RepeatButton Style="{StaticResource SliderButtonStyle}"
                                  Command="Slider.DecreaseLarge" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb Style="{StaticResource SliderThumbStyle}" />
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton Style="{StaticResource SliderButtonStyle}" Command="Slider.IncreaseLarge" />
                </Track.IncreaseRepeatButton>
            </Track>
            <TickBar Name="BottomTick" SnapsToDevicePixels="True" Grid.Row="2" Fill="{TemplateBinding Foreground}"
                     Placement="Bottom" Height="4" Visibility="Collapsed" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="TickPlacement" Value="TopLeft">
                <Setter TargetName="TopTick" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="TickPlacement" Value="BottomRight">
                <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="TickPlacement" Value="Both">
                <Setter TargetName="TopTick" Property="Visibility" Value="Visible"/>
                <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

And also identified what I want - set the Background of the Border named "TrackBackground" to, say Red, as it ticks. But I can't find the right property to use as a tr开发者_运维技巧igger.


If what you are trying to do is make the part of the slider to the left of the thumb be red, then you just need to replace the style of the Track.DecreaseRepeatButton so that it is always red. No need for triggers.

0

精彩评论

暂无评论...
验证码 换一张
取 消