Skip to content

Instantly share code, notes, and snippets.

@atzimler
Created May 3, 2017 08:49
Show Gist options
  • Select an option

  • Save atzimler/e7f92f909d74fe9de933bf3c90101858 to your computer and use it in GitHub Desktop.

Select an option

Save atzimler/e7f92f909d74fe9de933bf3c90101858 to your computer and use it in GitHub Desktop.
public class MultiplyByTwo : DependencyObject
{
private static readonly DependencyPropertyKey ResultPropertyKey =
DependencyProperty.RegisterReadOnly(nameof(Result), typeof(int), typeof(MultiplyByTwo),
new PropertyMetadata(0));
public static readonly DependencyProperty NumberProperty =
DependencyProperty.Register(nameof(Number), typeof(int), typeof(MultiplyByTwo),
new PropertyMetadata(0, CalculateResult));
public static readonly DependencyProperty ResultProperty = ResultPropertyKey.DependencyProperty;
public int Number
{
get { return (int)GetValue(NumberProperty); }
set { SetValue(NumberProperty, value); }
}
public int Result
{
get { return (int)GetValue(ResultProperty); }
}
private static void CalculateResult(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
d.SetValue(ResultPropertyKey, (int)e.NewValue * 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment