BoatDiagram.xaml.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. namespace UniversalControls.Controls;
  4. /// <summary>
  5. /// Interaction logic for BoatDiagram.xaml
  6. /// </summary>
  7. public partial class BoatDiagram : UserControl
  8. {
  9. public BoatDiagram()
  10. {
  11. InitializeComponent();
  12. }
  13. public int Position
  14. {
  15. get { return (int)GetValue(PositionProperty); }
  16. set { SetValue(PositionProperty, value); }
  17. }
  18. // Using a DependencyProperty as the backing store for Position. This enables animation, styling, binding, etc...
  19. public static readonly DependencyProperty PositionProperty =
  20. DependencyProperty.Register(nameof(Position), typeof(int), typeof(BoatDiagram), new PropertyMetadata(3, PropertyChangedCallback));
  21. static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  22. {
  23. if (d is not BoatDiagram boat)
  24. return;
  25. if (e.NewValue is not int pos)
  26. return;
  27. switch (pos)
  28. {
  29. case 1:
  30. boat.Core.SetValue(Canvas.TopProperty, 126d);
  31. break;
  32. case 2:
  33. boat.Core.SetValue(Canvas.TopProperty, 286d);
  34. break;
  35. case 3:
  36. boat.Core.SetValue(Canvas.TopProperty, 380d);
  37. break;
  38. default:
  39. break;
  40. }
  41. }
  42. }