Salut,
A la base, je souhaite créer une ProgressBar customisée qui affiche en dessous d'elle une TickBar afin d'avoir une graduation de la progression.
Voir le rendu souhaité dans la pièce jointe.
Voici la méthode que j'utilise :
1) création d'un style et d'un ControlTemplate afin que ma ProgressBar soit en fait composée d'une ProgressBar et d'une TickBar :
2) Création d'une classe fille de TickBar, afin que celle-ci affiche la valeur correspondant à chaque graduation (pour cela je surcharge la méthode OnRender) :
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 <ControlTemplate x:Key="tickedProgressBar" TargetType="{x:Type ProgressBar}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" MinHeight="{TemplateBinding ProgressBar.MinHeight}" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <ProgressBar x:Name="progressBar" Grid.Row="0" Height="12" Minimum="{TemplateBinding ProgressBar.Minimum}" Maximum="{TemplateBinding ProgressBar.Maximum}" Value="{TemplateBinding ProgressBar.Value}" Background="{TemplateBinding ProgressBar.Background}" Foreground="{TemplateBinding ProgressBar.Foreground}" Width="{TemplateBinding ProgressBar.Width}" /> <utils:LabeledTickBar x:Name="BottomTick" SnapsToDevicePixels="True" Grid.Row="1" Fill="Black" Placement="Bottom" Height="10" Visibility="Visible" TickFrequency="1000" Minimum="{TemplateBinding ProgressBar.Minimum}" Maximum="{TemplateBinding ProgressBar.Maximum}" /> </Grid> </ControlTemplate> <Style x:Key="tickedProgressBarStyle" TargetType="{x:Type ProgressBar}"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="OverridesDefaultStyle" Value="true" /> <Style.Triggers> <Trigger Property="Orientation" Value="Horizontal"> <Setter Property="Template" Value="{StaticResource tickedProgressBar}" /> </Trigger> </Style.Triggers> </Style>
Mon problème est qu'en fait j'ai des ComboBox dans la fenêtre dans laquelle j'utilise cette ProgressBar customisée et qu'une fois la méthode OnRender surchargée, si je clique sur une ComboBox, celle-ci ouvre la liste des items dispo dans le coin supérieur gauche de ma fenêtre et non pas en dessous de la ComboBox.
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class LabeledTickBar : TickBar { /// <summary> /// Render ticks : draw a tick (vertical line) and the corresponding value. /// </summary> /// <param name="dc"></param> protected override void OnRender(DrawingContext dc) { //base.OnRender(dc); Size size = new Size(base.ActualWidth, base.ActualHeight); double num = this.Maximum - this.Minimum; int tickNumber = (int)(num / TickFrequency); Point point = new Point(0, 0); Point point2 = new Point(0, 0); double y = this.ReservedSpace * 0.5; FormattedText formattedText = null; DoubleCollection ticks = new DoubleCollection(tickNumber); // The starting position of the tick. int startingPosition; // The ending position of the tick. // Initialized with a negative value in order to draw the first tick. int endingPosition = -20; if (tickNumber != 0) { for (int i = 0; i < tickNumber + 1; i++) { formattedText = new FormattedText((i * TickFrequency).ToString(), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 8, Brushes.Black); dc.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), new Point((i * (size.Width / tickNumber)), 2), new Point((i * (size.Width / tickNumber)), 6)); // We draw the tick only if it does not override the previously drawn tick startingPosition = (int)(i * (size.Width / tickNumber) - formattedText.Width / 2); if (startingPosition > endingPosition) { dc.DrawText(formattedText, new Point(startingPosition, 10)); ticks.Add(i * TickFrequency); endingPosition = (int)(i * (size.Width / tickNumber) + formattedText.Width / 2); } } Ticks = ticks; } } }
Cf 2nde pièce jointe.
Si je ne surcharge pas la méthode OnRender, l'affichage des ComboBox est correct (mais je n'ai pas les valeurs de ma TickBar affichées, bien entendu).
Du coup, j'aimerai savoir comment faire pour que l'affichage des mes ComboBox se fassent correctement. Ca doit avoir un lien avec le DrawingContext, mais je ne sais pas quoi...
Merci d'avance.
Partager