在 UWP C# 中向滑块左侧添加渐变

问题描述 投票:0回答:1
c# visual-studio uwp slider gradient
1个回答
0
投票

它给了我解决方案,使右侧的颜色着色 当我移动滑块时,左侧未着色。

滑块的左侧没有着色,因为您没有设置前景属性。设置好这个属性后,就可以满足你的需求了。

private void VolumeSliderValue(object sender, RangeBaseValueChangedEventArgs e)
{
    SolidColorBrush greenBrush = new SolidColorBrush(Colors.Green);
    SolidColorBrush yellowBrush = new SolidColorBrush(Colors.Yellow);
    SolidColorBrush redBrush = new SolidColorBrush(Colors.Red);

    if (volumeSlider.Value >= 0 && volumeSlider.Value < 30) 
    {
        volumeSlider.Foreground = greenBrush;
        volumeSlider.Background = greenBrush;
               
    }
    else if (volumeSlider.Value >= 30 && volumeSlider.Value < 45)
    {
        volumeSlider.Foreground = yellowBrush;
        volumeSlider.Background = yellowBrush;
    }
    else if (volumeSlider.Value >= 45 && volumeSlider.Value <= 70)
    {
        volumeSlider.Foreground = redBrush;
        volumeSlider.Background = redBrush;
    }
          
}
© www.soinside.com 2019 - 2024. All rights reserved.