如何在wpf中更改滑块中的轨道颜色

时间:2014-03-28 06:15:33

标签: wpf

这是代码,我必须在移动滑块时更改轨道的颜色。 请给我一个解决方案

  <Track x:Name="PART_Track" Grid.Row="1">
          <Track.DecreaseRepeatButton >
                                <RepeatButton    Style="{StaticResource    SliderRepeatButtonStyle}" Command="{x:Static Slider.DecreaseLarge}"/>
                            </Track.DecreaseRepeatButton>
                            <Track.IncreaseRepeatButton>
                                <RepeatButton     Style="{StaticResource SliderRepeatButtonStyle}" Command="{x:Static Slider.IncreaseLarge}"/>
                            </Track.IncreaseRepeatButton>
                            <Track.Thumb>
                                <Thumb x:Name="Thumb"  Style="{StaticResource CustomThumbForSlider}" Background="Black"/>
                            </Track.Thumb>
                        </Track>

1 个答案:

答案 0 :(得分:0)

您应该以 SliderRepeatButtonStyle 样式执行此操作。 背景属性定义轨道内部的颜色, BorderBrush 属性定义轨道边框的颜色。

<Style x:Key="SliderRepeatButtonStyle" TargetType="RepeatButton">
    <Setter Property="SnapsToDevicePixels" Value="true" />
    <Setter Property="OverridesDefaultStyle" Value="true" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="RepeatButton">
                <Border SnapsToDevicePixels="True" Background="Red"  BorderThickness="1" BorderBrush="OrangeRed" Height="3"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>