J'ai une progressBar qui fonctionne bien et dont le value est bindé à PourcentageAvancement.
Je voudrais ajouter un TaskbarItemInfo mais, alors que la progressbar progresse bien, le TaskbarItemInfo reste invariablement à 0 et sa description reste vide, alors qu'elle se modifie correctement ailleurs.
Voici ce que j'ai :
fichier XAML :
Code xaml : 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
22
23
24
25
26 ... <Window.Resources> <converters:IntPercentageToDoubleConverter x:Key="intPercentageToDoubleConverter" /> </Window.Resources> <Window.TaskbarItemInfo> <TaskbarItemInfo Description="{Binding StatusBarText}" ProgressValue="{Binding Mode=OneWay, Path=PourcentageAvancement, Converter={StaticResource intPercentageToDoubleConverter}, UpdateSourceTrigger=PropertyChanged}" ProgressState="Normal" /> </Window.TaskbarItemInfo> <DockPanel LastChildFill="true"> <StatusBar DockPanel.Dock="Bottom" DataContext="{StaticResource Windows1ViewModel}"> <StatusBarItem> <Grid Name="Progression" Margin="2" Visibility="{Binding ProgressBarVisibility}"> <ProgressBar Width="150" Value="{Binding PourcentageAvancement, Mode=OneWay}" IsIndeterminate="{Binding ProgressBarIsIndeterminate}"/> <TextBlock Text="{Binding ProgressionText}" HorizontalAlignment="Center" VerticalAlignment="Center" /> </Grid> </StatusBarItem> <Separator Visibility="{Binding ProgressBarVisibility}"/> <StatusBarItem> <TextBlock Text="{Binding StatusBarText}"/> </StatusBarItem> </StatusBar> ...
Dans le CS :
Le converter :
Code : 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 private int _pourcentageavancement; public int PourcentageAvancement { get { return _pourcentageavancement; } set { if (_pourcentageavancement != value) { if (value < 0) value = 0; else if (value > 100) value = 100; _pourcentageavancement = value; if (_pourcentageavancement == 0) ProgressionText = null; RaisePropertyChanged(() => PourcentageAvancement); } } }
Qu'est-ce que j'ai mal fait ou oublié ?
Code : 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
22
23
24 public class IntPercentageToDoubleConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double res = 0.0d; if (value is int) { int intVal = (int)value; res = intVal / 100.0d; if (res < 0.0d) res = 0.0d; else if (res > 100.0d) res = 100.0d; } return res; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } }
Comment dois-je faire pour régler le pbl ?
Merci de vos z'avis z'avisés,
JM
Partager