Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4.  
  5. namespace Treeni
  6. {
  7. /// <summary>
  8. /// Interaction logic for TreeniControl.xaml
  9. /// </summary>
  10. public partial class TreeniControl : UserControl
  11. {
  12.  
  13. public TimeSpan Aika
  14. {
  15. get { return (TimeSpan)GetValue(AikaProperty); }
  16. set { SetValue(AikaProperty, value); }
  17. }
  18.  
  19. public static readonly DependencyProperty AikaProperty = DependencyProperty.Register("Aika", typeof(TimeSpan),
  20. typeof(TreeniControl), new FrameworkPropertyMetadata(TimeSpan.Zero, FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender,
  21. new PropertyChangedCallback(AikaOnValueChanged), // kutsutaan propertyn arvon muuttumisen jälkeen
  22. new CoerceValueCallback(MuutaAika))); // kutsutaan ennen propertyn arvon muutosta));
  23.  
  24. private static object MuutaAika(DependencyObject d, object baseValue)
  25. {
  26. TimeSpan luku = (TimeSpan)baseValue;
  27. return luku;
  28. }
  29.  
  30. private static void AikaOnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  31. {
  32. //
  33. }
  34.  
  35. public double Matka
  36. {
  37. get { return (double)GetValue(MatkaProperty); }
  38. set { SetValue(MatkaProperty, value); }
  39. }
  40.  
  41. public static readonly DependencyProperty MatkaProperty = DependencyProperty.Register("Matka", typeof(double),
  42. typeof(TreeniControl), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender,
  43. new PropertyChangedCallback(MatkaOnValueChanged), // kutsutaan propertyn arvon muuttumisen jälkeen
  44. new CoerceValueCallback(MuutaMatka))); // kutsutaan ennen propertyn arvon muutosta));
  45.  
  46. private static object MuutaMatka(DependencyObject d, object baseValue)
  47. {
  48. double luku = (double)baseValue;
  49. return luku;
  50. }
  51.  
  52. private static void MatkaOnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  53. {
  54.  
  55. }
  56.  
  57. public TreeniControl()
  58. {
  59. InitializeComponent();
  60. }
  61.  
  62. private void Laske_Click(object sender, RoutedEventArgs e)
  63. {
  64. double nopeus = Matka / Aika.TotalHours;
  65. NopeusBox.Text = nopeus.ToString("#0.0") + " km/h";
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement