gpt4 book ai didi

c# - WPF 中的进度条样式是过时的。酒吧的增量。如何实现带有vista或windows-7 shady glow效果的进度条?

转载 作者:太空狗 更新时间:2023-10-30 00:05:26 25 4
gpt4 key购买 nike

WPF 中的进度条样式是过时的。酒吧的增量。如何实现vista或windows-7 shady glow效果的进度条?

Image http://quickshare.my3gb.com/download/2.JPG

甚至检查了 Progressbar 的属性。但是,没有与发光效果相关的属性。

还有,有没有动画或者跟正常进度条不一样的地方/

编辑

代码:

<ProgressBar Height="41" HorizontalAlignment="Left"    Margin="372,215,0,0" Name="progressBar1" VerticalAlignment="Top" Width="150">

</ProgressBar>

最佳答案

自己动手应该不会太难。

创建一个具有标准进度条属性的用户控件

Value
Maximum
Minimum

您可以创建派生属性,使用公式计算条形的大小:

ProgressBarWidth = (Value / (Maximum + Minimum) * ControlWidth) - Padding

当值、最大值或最小值更新时哪个会改变

将其绑定(bind)到进度条控件模板中“bar”的宽度 - 这样当 Value 属性更新时,进度条将调整大小。

你的条形看起来如何取决于你,但我猜你只是想要大量花哨的填充/渐变/发光效果 - 你可以在 Blend 中添加这些

免责声明:公式可能不正确!

如果你想尝试自己动手,这是我刚刚敲出来的,看起来还不错

public partial class MyProgressBar : UserControl
{
public MyProgressBar()
{
InitializeComponent();

Loaded += new RoutedEventHandler(MyProgressBar_Loaded);
}

void MyProgressBar_Loaded(object sender, RoutedEventArgs e)
{
Update();
}

private static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(double), typeof(MyProgressBar), new PropertyMetadata(100d, OnMaximumChanged));
public double Maximum
{
get { return (double)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}


private static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(double), typeof(MyProgressBar), new PropertyMetadata(0d, OnMinimumChanged));
public double Minimum
{
get { return (double)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}

private static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(MyProgressBar), new PropertyMetadata(50d, OnValueChanged));
public double Value
{
get { return (double)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}



private static readonly DependencyProperty ProgressBarWidthProperty = DependencyProperty.Register("ProgressBarWidth", typeof(double), typeof(MyProgressBar), null);
private double ProgressBarWidth
{
get { return (double)GetValue(ProgressBarWidthProperty); }
set { SetValue(ProgressBarWidthProperty, value); }
}

static void OnValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
(o as MyProgressBar).Update();
}

static void OnMinimumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
(o as MyProgressBar).Update();
}

static void OnMaximumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
(o as MyProgressBar).Update();
}


void Update()
{
// The -2 is for the borders - there are probably better ways of doing this since you
// may want your template to have variable bits like border width etc which you'd use
// TemplateBinding for
ProgressBarWidth = Math.Min((Value / (Maximum + Minimum) * this.ActualWidth) - 2, this.ActualWidth - 2);


}
}

XAML

<UserControl x:Class="WpfApplication1.MyProgressBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" x:Name="uc">
<Grid>
<Border Background="White">
<Border BorderBrush="Gray" BorderThickness="1">
<Grid>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE5E5E5" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Grid Width="{Binding ProgressBarWidth, ElementName=uc}" HorizontalAlignment="Left">
<Grid.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFCBFFD0" Offset="0" />
<GradientStop Color="#FF62EF73" Offset="1" />
<GradientStop Color="#FFAEE56D" Offset="0.39" />
</LinearGradientBrush>
</Grid.Background>
</Grid>
</Grid>
</Border>
</Border>
</Grid>
</UserControl>

结果:

Progress bar... home grown!

就像我说的,像这样的事情很简单,但仍然考虑重新定义模板或使用原始模板,因为它在正确的操作系统上支持发光

这是我在控件模板中添加“Percent”依赖属性并绑定(bind)到它之后的样子:

Home grown with number!

更新 Percent 的代码是

   Percentage = Math.Min((int)(Value / (Maximum + Minimum) * 100), 100);

编辑 2:

我把填充搞乱了,添加了一个白色的内边框,这样看起来更有光泽。唯一缺少的是 Shiny 的动画

上面一个是我的控件,下面一个是默认的WPF控件

请记住,所有这一切都可以通过编辑进度条控件模板来实现

Oooh shiny...

这是更新后的 XAML:

<UserControl x:Class="WpfApplication1.MyProgressBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" x:Name="uc">
<Grid>
<Border Background="White" BorderBrush="Gray" BorderThickness="1">
<Border BorderBrush="White" BorderThickness="1">
<Grid>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE5E5E5" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Grid Width="{Binding ProgressBarWidth, ElementName=uc, FallbackValue=200}" HorizontalAlignment="Left">
<Grid.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FF8BBA91" Offset="0" />
<GradientStop Color="#FF8BBA91" Offset="1" />
<GradientStop Color="#FF9ED76A" Offset="0.8" />
<GradientStop Color="#FF9ED76A" Offset="0.2" />
</LinearGradientBrush>
</Grid.Background>
</Grid>
<Border>
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#89E2E2E2" Offset="0" />
<GradientStop Color="#C1FFFFFF" Offset="0.5" />
<GradientStop Color="Transparent" Offset="0.52" />
</LinearGradientBrush>
</Border.Background>
</Border>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Percentage, ElementName=uc}"></TextBlock>
</Grid>
</Border>
</Border>
</Grid>
</UserControl>

关于c# - WPF 中的进度条样式是过时的。酒吧的增量。如何实现带有vista或windows-7 shady glow效果的进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11967898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com