Bonjour, alors voilà, j'ai fait une "ProgressBar" en tant que UserControl et j'aimerais pouvoir animer le pourcentage visible (en gros voir la progression passée de 0 à 50 en 3 secondes) de celui ci.
j'ai donc :
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <UserControl x:Class="CooProgressBar" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="100" Height="27"> <Grid> <Grid.BitmapEffect> <DropShadowBitmapEffect ShadowDepth="7" /> </Grid.BitmapEffect> <Rectangle Stretch="fill" Fill="White" Opacity="0.5" Stroke="Black" /> <Rectangle x:Name="pourcentageVisible" Fill="#33CC00" Width="50" HorizontalAlignment="left" Stroke="Black"></Rectangle> <Label VerticalAlignment="center" Foreground="White" FontSize="14" x:Name="percent">%</Label> </Grid> </UserControl>
J'ai créé une propriété "ValueProperty"
Code VB.Net : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 Partial Public Class CooProgressBar Public Shared ReadOnly ValueProperty As DependencyProperty Shared Sub New() ValueProperty = DependencyProperty.Register("Value", GetType(Double), GetType(CooProgressBar)) End Sub Public Property Value() Get Return DirectCast(GetValue(ValueProperty), Double) End Get Set(ByVal value) SetValue(ValueProperty, CDbl(value)) pourcentageVisible.Width = value * Me.Width / 100 percent.Content = Math.Floor(value).ToString & "%" End Set End Property End Class
enfin pour l'animation (par exemple) :
Code VB.Net : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 Dim pb As New CooProgressBar pb.SetValue(Canvas.TopProperty, CDbl(0)) pb.SetValue(Canvas.RightProperty, CDbl(0)) pb.Width = 150 pb.Height = 30 Dim progressAnimation As New DoubleAnimation progressAnimation.From = 0 progressAnimation.To = 50 progressAnimation.AccelerationRatio = 0 progressAnimation.DecelerationRatio = 0.5 progressAnimation.Duration = New Duration(TimeSpan.FromSeconds(5)) pb.BeginAnimation(ProgressBar.ValueProperty, progressAnimation, HandoffBehavior.Compose)
j'ai essayé avec une ProgressBar simple, ça marchait très bien, et je ne sais pas pourquoi ça ne fonctionne pas avec la mienne.
Peut être faudrait il juste que "customise" la ProgressBar fournie ?
Merci pour vos éclaircissements
Partager