@@ -300,6 +300,92 @@ public double Radius
300
300
301
301
#endregion Radius read-only dependecy property
302
302
303
+ #region HourHandRadius dependency property
304
+
305
+ public static readonly DependencyProperty HourHandRadiusProperty = DependencyProperty . Register (
306
+ "HourHandRadius" ,
307
+ typeof ( double ) ,
308
+ typeof ( AnalogClockFace ) ,
309
+ new PropertyMetadata ( default ( double ) , AnalogClockFace . OnHourHandRadiusChanged ) ) ;
310
+
311
+ public double HourHandRadius { get => ( double ) GetValue ( AnalogClockFace . HourHandRadiusProperty ) ; set => SetValue ( AnalogClockFace . HourHandRadiusProperty , value ) ; }
312
+
313
+ #endregion HourHandRadius dependency property
314
+
315
+ #region MinuteHandRadius dependency property
316
+
317
+ public static readonly DependencyProperty MinuteHandRadiusProperty = DependencyProperty . Register (
318
+ "MinuteHandRadius" ,
319
+ typeof ( double ) ,
320
+ typeof ( AnalogClockFace ) ,
321
+ new PropertyMetadata ( default ( double ) , AnalogClockFace . OnMinuteHandRadiusChanged ) ) ;
322
+
323
+ public double MinuteHandRadius { get => ( double ) GetValue ( AnalogClockFace . MinuteHandRadiusProperty ) ; set => SetValue ( AnalogClockFace . MinuteHandRadiusProperty , value ) ; }
324
+
325
+ #endregion MinuteHandRadius dependency property
326
+
327
+ #region SecondHandRadius dependency property
328
+
329
+ public static readonly DependencyProperty SecondHandRadiusProperty = DependencyProperty . Register (
330
+ "SecondHandRadius" ,
331
+ typeof ( double ) ,
332
+ typeof ( AnalogClockFace ) ,
333
+ new PropertyMetadata ( default ( double ) , AnalogClockFace . OnSecondHandRadiusChanged ) ) ;
334
+
335
+ public double SecondHandRadius { get => ( double ) GetValue ( AnalogClockFace . SecondHandRadiusProperty ) ; set => SetValue ( AnalogClockFace . SecondHandRadiusProperty , value ) ; }
336
+
337
+ #endregion SecondHandRadius dependency property
338
+
339
+ #region HourHandDiameter read-only dependency property
340
+ protected static readonly DependencyPropertyKey HourHandDiameterPropertyKey = DependencyProperty . RegisterReadOnly (
341
+ "HourHandDiameter" ,
342
+ typeof ( double ) ,
343
+ typeof ( AnalogClockFace ) ,
344
+ new PropertyMetadata ( default ( double ) ) ) ;
345
+
346
+ public static readonly DependencyProperty HourHandDiameterProperty = AnalogClockFace . HourHandDiameterPropertyKey . DependencyProperty ;
347
+
348
+ public double HourHandDiameter
349
+ {
350
+ get => ( double ) GetValue ( AnalogClockFace . HourHandDiameterProperty ) ;
351
+ private set => SetValue ( AnalogClockFace . HourHandDiameterPropertyKey , value ) ;
352
+ }
353
+ #endregion HourHandDiameter read-only dependency property
354
+
355
+ #region MinuteHandDiameter read-only dependency property
356
+ protected static readonly DependencyPropertyKey MinuteHandDiameterPropertyKey = DependencyProperty . RegisterReadOnly (
357
+ "MinuteHandDiameter" ,
358
+ typeof ( double ) ,
359
+ typeof ( AnalogClockFace ) ,
360
+ new PropertyMetadata ( default ( double ) ) ) ;
361
+
362
+ public static readonly DependencyProperty MinuteHandDiameterProperty = AnalogClockFace . MinuteHandDiameterPropertyKey . DependencyProperty ;
363
+
364
+ public double MinuteHandDiameter
365
+ {
366
+ get => ( double ) GetValue ( AnalogClockFace . MinuteHandDiameterProperty ) ;
367
+ private set => SetValue ( AnalogClockFace . MinuteHandDiameterPropertyKey , value ) ;
368
+ }
369
+
370
+ #endregion MinuteHandDiameter read-only dependency property
371
+
372
+ #region SecondHandDiameter read-only dependency property
373
+ protected static readonly DependencyPropertyKey SecondHandDiameterPropertyKey = DependencyProperty . RegisterReadOnly (
374
+ "SecondHandDiameter" ,
375
+ typeof ( double ) ,
376
+ typeof ( AnalogClockFace ) ,
377
+ new PropertyMetadata ( default ( double ) ) ) ;
378
+
379
+ public static readonly DependencyProperty SecondHandDiameterProperty = AnalogClockFace . SecondHandDiameterPropertyKey . DependencyProperty ;
380
+
381
+ public double SecondHandDiameter
382
+ {
383
+ get => ( double ) GetValue ( AnalogClockFace . SecondHandDiameterProperty ) ;
384
+ private set => SetValue ( AnalogClockFace . SecondHandDiameterPropertyKey , value ) ;
385
+ }
386
+
387
+ #endregion SecondHandDiameter read-only dependency property
388
+
303
389
#region Is24HModeEnabled dependency property
304
390
305
391
public static readonly DependencyProperty Is24HModeEnabledProperty = DependencyProperty . Register (
@@ -345,9 +431,9 @@ private void InitializeClockFaceCanvas()
345
431
private void InitializeClockRotateTransforms ( )
346
432
{
347
433
this . IntervalElementTransform = new RotateTransform ( 0 , this . Radius , this . Radius ) ;
348
- this . HourHandTransform = new RotateTransform ( ) ;
349
- this . MinuteHandTransform = new RotateTransform ( 0 , this . Radius , this . Radius ) ;
350
- this . SecondHandTransform = new RotateTransform ( 0 , this . Radius , this . Radius ) ;
434
+ this . HourHandTransform = new RotateTransform ( GetClockAngle ( this . SelectedHour , this . Is24HModeEnabled ? 24 : 12 ) , this . Radius , this . Radius ) ;
435
+ this . MinuteHandTransform = new RotateTransform ( GetClockAngle ( this . SelectedMinute , 60 ) , this . Radius , this . Radius ) ;
436
+ this . SecondHandTransform = new RotateTransform ( GetClockAngle ( this . SelectedSecond , 60 ) , this . Radius , this . Radius ) ;
351
437
var radiusBinding = new Binding ( nameof ( this . Radius ) ) { Source = this } ;
352
438
BindingOperations . SetBinding ( this . IntervalElementTransform , RotateTransform . CenterXProperty , radiusBinding ) ;
353
439
BindingOperations . SetBinding ( this . IntervalElementTransform , RotateTransform . CenterYProperty , radiusBinding ) ;
@@ -366,7 +452,15 @@ private void InitializeClockRotateTransforms()
366
452
protected override Size MeasureOverride ( Size constraint )
367
453
{
368
454
constraint = base . MeasureOverride ( constraint ) ;
369
- DrawAnalogClock ( ) ;
455
+
456
+ if ( this . Is24HModeEnabled )
457
+ {
458
+ DrawAnalog24Clock ( ) ;
459
+ }
460
+ else
461
+ {
462
+ DrawAnalogClock ( ) ;
463
+ }
370
464
return constraint ;
371
465
}
372
466
@@ -419,6 +513,24 @@ private static void OnSelectedTimeChanged(DependencyObject d, DependencyProperty
419
513
this_ . OnSelectedTimeChanged ( ( DateTime ) e . OldValue , ( DateTime ) e . NewValue ) ;
420
514
}
421
515
516
+ private static void OnHourHandRadiusChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
517
+ {
518
+ var this_ = d as AnalogClockFace ;
519
+ this_ . HourHandDiameter = ( double ) e . NewValue * 2 ;
520
+ }
521
+
522
+ private static void OnMinuteHandRadiusChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
523
+ {
524
+ var this_ = d as AnalogClockFace ;
525
+ this_ . MinuteHandDiameter = ( double ) e . NewValue * 2 ;
526
+ }
527
+
528
+ private static void OnSecondHandRadiusChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
529
+ {
530
+ var this_ = d as AnalogClockFace ;
531
+ this_ . SecondHandDiameter = ( double ) e . NewValue * 2 ;
532
+ }
533
+
422
534
protected virtual void OnSelectedTimeChanged ( DateTime oldValue , DateTime newValue )
423
535
{
424
536
if ( this . IsUpdatingSelectedTimeComponent )
@@ -501,7 +613,7 @@ private static object CoerceSeconds(DependencyObject d, object basevalue)
501
613
502
614
protected virtual void OnSelectedHourChanged ( double oldValue , double newValue )
503
615
{
504
- double angle = GetClockAngle ( newValue , 12 ) ;
616
+ double angle = GetClockAngle ( newValue , this . Is24HModeEnabled ? 24 : 12 ) ;
505
617
this . HourHandTransform . Angle = angle ;
506
618
507
619
if ( this . IsUpdatingSelectedTime )
@@ -759,7 +871,7 @@ protected virtual void DrawAnalogClock()
759
871
UIElement intervalMarker = CreateIntervalMarker ( step ) ;
760
872
if ( intervalMarkerCenterPositionRadius . Equals ( - 1 ) )
761
873
{
762
- InitializeRadiusOfIntervalMarkers ( out intervalMarkerCenterPositionRadius , intervalMarker ) ;
874
+ InitializeRadiusOfIntervalMarkers ( out intervalMarkerCenterPositionRadius , intervalMarker , this . Radius ) ;
763
875
}
764
876
765
877
DrawIntervalMarker ( degreesOfCurrentStep , intervalMarkerCenterPositionRadius , intervalMarker ) ;
@@ -777,6 +889,93 @@ protected virtual void DrawAnalogClock()
777
889
OnClockFaceLoaded ( ) ;
778
890
}
779
891
892
+ protected virtual void DrawAnalog24Clock ( )
893
+ {
894
+ this . ClockFaceCanvas . Children . Clear ( ) ;
895
+
896
+ if ( this . Diameter == 0 )
897
+ {
898
+ return ;
899
+ }
900
+
901
+ double steps = 60.0 ;
902
+ double degreeOfStep = 360.0 / steps ;
903
+ double intervalMarkerCenterPositionRadius = - 1 ;
904
+ for ( int step = 0 ; step < steps ; step ++ )
905
+ {
906
+ double degreesOfCurrentStep = step * degreeOfStep ;
907
+
908
+ UIElement intervalMarker = CreateIntervalMarker ( step ) ;
909
+ if ( intervalMarkerCenterPositionRadius . Equals ( - 1 ) )
910
+ {
911
+ InitializeRadiusOfIntervalMarkers ( out intervalMarkerCenterPositionRadius , intervalMarker , this . MinuteHandRadius ) ;
912
+ }
913
+
914
+ DrawIntervalMarker ( degreesOfCurrentStep , intervalMarkerCenterPositionRadius , intervalMarker ) ;
915
+
916
+ if ( step % 5 == 0 )
917
+ {
918
+ UIElement intervalMarkerLabel = CreateIntervalLabel ( step ) ;
919
+ if ( intervalMarkerLabel != null )
920
+ {
921
+ DrawIntervalLabel ( intervalMarkerCenterPositionRadius , degreesOfCurrentStep , intervalMarkerLabel ) ;
922
+ }
923
+ }
924
+ }
925
+
926
+ steps = 24.0 ;
927
+ degreeOfStep = 360.0 / steps ;
928
+ intervalMarkerCenterPositionRadius = - 1 ;
929
+ for ( int step = 0 ; step < steps ; step ++ )
930
+ {
931
+ double degreesOfCurrentStep = step * degreeOfStep ;
932
+
933
+ UIElement intervalMarker = CreateIntervalMarker ( step ) ;
934
+ if ( intervalMarkerCenterPositionRadius . Equals ( - 1 ) )
935
+ {
936
+ InitializeRadiusOfIntervalMarkers ( out intervalMarkerCenterPositionRadius , intervalMarker , this . HourHandRadius ) ;
937
+ }
938
+
939
+ DrawIntervalMarker ( degreesOfCurrentStep , intervalMarkerCenterPositionRadius , intervalMarker ) ;
940
+
941
+ UIElement intervalMarkerLabel = CreateIntervalLabel ( step ) ;
942
+ if ( intervalMarkerLabel != null )
943
+ {
944
+ DrawIntervalLabel ( intervalMarkerCenterPositionRadius , degreesOfCurrentStep , intervalMarkerLabel ) ;
945
+ }
946
+ }
947
+
948
+ if ( this . MinuteHandRadius != this . SecondHandRadius )
949
+ {
950
+ steps = 60.0 ;
951
+ degreeOfStep = 360.0 / steps ;
952
+ intervalMarkerCenterPositionRadius = - 1 ;
953
+ for ( int step = 0 ; step < steps ; step ++ )
954
+ {
955
+ double degreesOfCurrentStep = step * degreeOfStep ;
956
+
957
+ UIElement intervalMarker = CreateIntervalMarker ( step ) ;
958
+ if ( intervalMarkerCenterPositionRadius . Equals ( - 1 ) )
959
+ {
960
+ InitializeRadiusOfIntervalMarkers ( out intervalMarkerCenterPositionRadius , intervalMarker , this . SecondHandRadius ) ;
961
+ }
962
+
963
+ DrawIntervalMarker ( degreesOfCurrentStep , intervalMarkerCenterPositionRadius , intervalMarker ) ;
964
+
965
+ //UIElement intervalMarkerLabel = CreateIntervalLabel(step);
966
+ //if (intervalMarkerLabel != null)
967
+ //{
968
+ // DrawIntervalLabel(intervalMarkerCenterPositionRadius, degreesOfCurrentStep, intervalMarkerLabel);
969
+ //}
970
+ }
971
+ }
972
+
973
+ Draw24ClockFaceBackground ( intervalMarkerCenterPositionRadius ) ;
974
+
975
+ AddClockHands ( ) ;
976
+ OnClockFaceLoaded ( ) ;
977
+ }
978
+
780
979
private void DrawClockFaceBackground ( double intervalMarkerCenterPositionRadius )
781
980
{
782
981
double deltaToMiddleRadius = ( this . Radius - intervalMarkerCenterPositionRadius ) * 2 ;
@@ -791,6 +990,17 @@ private void DrawClockFaceBackground(double intervalMarkerCenterPositionRadius)
791
990
0 ) ;
792
991
}
793
992
993
+ private void Draw24ClockFaceBackground ( double intervalMarkerCenterPositionRadius )
994
+ {
995
+ AddElementToClockFace (
996
+ new Ellipse ( )
997
+ {
998
+ Height = this . Diameter , Width = this . Diameter , Fill = this . Background
999
+ } ,
1000
+ new Point ( ) ,
1001
+ 0 ) ;
1002
+ }
1003
+
794
1004
private void DrawIntervalLabel (
795
1005
double intervalMarkerCenterPositionRadius ,
796
1006
double degreesOfCurrentStep ,
@@ -900,10 +1110,10 @@ private UIElement CreateIntervalLabel(int step)
900
1110
return intervalMarkerLabel ;
901
1111
}
902
1112
903
- private void InitializeRadiusOfIntervalMarkers ( out double intervalMarkerCenterPositionRadius , UIElement intervalMarker )
1113
+ private void InitializeRadiusOfIntervalMarkers ( out double intervalMarkerCenterPositionRadius , UIElement intervalMarker , double radius )
904
1114
{
905
1115
double radiusOffset = CalculateIntervalMarkerCenterRadiusOffset ( intervalMarker ) ;
906
- intervalMarkerCenterPositionRadius = this . Radius + radiusOffset ;
1116
+ intervalMarkerCenterPositionRadius = radius + radiusOffset ;
907
1117
}
908
1118
909
1119
private void AlignElementCenterPointToRadius ( ref Point cartesianPoint , UIElement element )
0 commit comments