Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows;
- using System.Windows.Controls;
- namespace Treeni
- {
- /// <summary>
- /// Interaction logic for TreeniControl.xaml
- /// </summary>
- public partial class TreeniControl : UserControl
- {
- public TimeSpan Aika
- {
- get { return (TimeSpan)GetValue(AikaProperty); }
- set { SetValue(AikaProperty, value); }
- }
- public static readonly DependencyProperty AikaProperty = DependencyProperty.Register("Aika", typeof(TimeSpan),
- typeof(TreeniControl), new FrameworkPropertyMetadata(TimeSpan.Zero, FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender,
- new PropertyChangedCallback(AikaOnValueChanged), // kutsutaan propertyn arvon muuttumisen jälkeen
- new CoerceValueCallback(MuutaAika))); // kutsutaan ennen propertyn arvon muutosta));
- private static object MuutaAika(DependencyObject d, object baseValue)
- {
- TimeSpan luku = (TimeSpan)baseValue;
- return luku;
- }
- private static void AikaOnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- //
- }
- public double Matka
- {
- get { return (double)GetValue(MatkaProperty); }
- set { SetValue(MatkaProperty, value); }
- }
- public static readonly DependencyProperty MatkaProperty = DependencyProperty.Register("Matka", typeof(double),
- typeof(TreeniControl), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender,
- new PropertyChangedCallback(MatkaOnValueChanged), // kutsutaan propertyn arvon muuttumisen jälkeen
- new CoerceValueCallback(MuutaMatka))); // kutsutaan ennen propertyn arvon muutosta));
- private static object MuutaMatka(DependencyObject d, object baseValue)
- {
- double luku = (double)baseValue;
- return luku;
- }
- private static void MatkaOnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- }
- public TreeniControl()
- {
- InitializeComponent();
- }
- private void Laske_Click(object sender, RoutedEventArgs e)
- {
- double nopeus = Matka / Aika.TotalHours;
- NopeusBox.Text = nopeus.ToString("#0.0") + " km/h";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement