Skip to content

Commit 6480266

Browse files
jespershKeboo
authored andcommitted
Prevent 24th minute and second showing up as 0
1 parent 3ae2c21 commit 6480266

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

MaterialDesignThemes.Wpf/Clock.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,16 @@ private void GenerateButtons()
278278
if (Is24Hours)
279279
{
280280
GenerateButtons(hoursCanvas, Enumerable.Range(13, 12).ToList(), ButtonRadiusRatio,
281-
new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Hours, Is24Hours), i => "ButtonStyle", "00");
281+
new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Hours, Is24Hours), i => "ButtonStyle", "00",
282+
ClockDisplayMode.Hours);
282283
GenerateButtons(hoursCanvas, Enumerable.Range(1, 12).ToList(), ButtonRadiusInnerRatio,
283-
new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Hours, Is24Hours), i => "ButtonStyle", "#");
284+
new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Hours, Is24Hours), i => "ButtonStyle", "#",
285+
ClockDisplayMode.Hours);
284286
}
285287
else
286288
GenerateButtons(hoursCanvas, Enumerable.Range(1, 12).ToList(), ButtonRadiusRatio,
287-
new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Hours, Is24Hours), i => "ButtonStyle", "0");
289+
new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Hours, Is24Hours), i => "ButtonStyle", "0",
290+
ClockDisplayMode.Hours);
288291
}
289292

290293
if (GetTemplateChild(MinutesCanvasPartName) is Canvas minutesCanvas)
@@ -293,7 +296,8 @@ private void GenerateButtons()
293296

294297
GenerateButtons(minutesCanvas, Enumerable.Range(1, 60).ToList(), ButtonRadiusRatio,
295298
new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Minutes, Is24Hours),
296-
i => ((i / 5.0) % 1) == 0.0 ? "ButtonStyle" : "LesserButtonStyle", "0");
299+
i => ((i / 5.0) % 1) == 0.0 ? "ButtonStyle" : "LesserButtonStyle", "0",
300+
ClockDisplayMode.Minutes);
297301
}
298302

299303
if (GetTemplateChild(SecondsCanvasPartName) is Canvas secondsCanvas)
@@ -302,7 +306,8 @@ private void GenerateButtons()
302306

303307
GenerateButtons(secondsCanvas, Enumerable.Range(1, 60).ToList(), ButtonRadiusRatio,
304308
new ClockItemIsCheckedConverter(() => Time, ClockDisplayMode.Seconds, Is24Hours),
305-
i => ((i / 5.0) % 1) == 0.0 ? "ButtonStyle" : "LesserButtonStyle", "0");
309+
i => ((i / 5.0) % 1) == 0.0 ? "ButtonStyle" : "LesserButtonStyle", "0",
310+
ClockDisplayMode.Seconds);
306311
}
307312

308313
void RemoveExistingButtons(Canvas canvas)
@@ -333,7 +338,7 @@ private void HourReadOutPartNameOnPreviewMouseLeftButtonDown(object sender, Mous
333338
}
334339

335340
private void GenerateButtons(Panel canvas, ICollection<int> range, double radiusRatio, IValueConverter isCheckedConverter, Func<int, string> stylePropertySelector,
336-
string format)
341+
string format, ClockDisplayMode clockDisplayMode)
337342
{
338343
var anglePerItem = 360.0 / range.Count;
339344
var radiansPerItem = anglePerItem * (Math.PI / 180);
@@ -359,7 +364,7 @@ private void GenerateButtons(Panel canvas, ICollection<int> range, double radius
359364
button.SetBinding(Canvas.LeftProperty, GetBinding("X", button));
360365
button.SetBinding(Canvas.TopProperty, GetBinding("Y", button));
361366

362-
button.Content = (i == 60 ? 0 : (i == 24 ? 0 : i)).ToString(format);
367+
button.Content = (i == 60 ? 0 : (i == 24 && clockDisplayMode == ClockDisplayMode.Hours ? 0 : i)).ToString(format);
363368
canvas.Children.Add(button);
364369
}
365370
}

0 commit comments

Comments
 (0)