SpeTextBlock.cs 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Windows.Controls;
  3. namespace HandyControl.Controls;
  4. /// <summary>
  5. /// 作为刻度使用的文字块
  6. /// </summary>
  7. internal class SpeTextBlock : TextBlock
  8. {
  9. public double X { get; set; }
  10. public SpeTextBlock() => Width = 60;
  11. public SpeTextBlock(double x) : this()
  12. {
  13. X = x;
  14. Canvas.SetLeft(this, X);
  15. }
  16. /// <summary>
  17. /// 时间
  18. /// </summary>
  19. private DateTime _time;
  20. /// <summary>
  21. /// 时间
  22. /// </summary>
  23. public DateTime Time
  24. {
  25. get => _time;
  26. set
  27. {
  28. _time = value;
  29. Text = $"{value.ToString(TimeFormat)}\r\n|";
  30. }
  31. }
  32. /// <summary>
  33. /// 时间格式
  34. /// </summary>
  35. public string TimeFormat { get; set; } = "HH:mm";
  36. /// <summary>
  37. /// 横向移动
  38. /// </summary>
  39. /// <param name="offsetX"></param>
  40. public void MoveX(double offsetX) => Canvas.SetLeft(this, X + offsetX);
  41. }