This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestFixture] | |
public class LetsCheckTheEventHandlers | |
{ | |
[Test] | |
public void ChainedEventHandlers() | |
{ | |
var m = new MultiplyByTwo(); | |
var s = new CreateResultStars(m); | |
Assert.AreEqual(string.Empty, s.Stars); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dpd.AddValueChanged(_multiplier, (o, e) => RecalculateStars()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dpd = DependencyPropertyDescriptor.FromProperty(MultiplyByTwo.ResultProperty, typeof(MultiplyByTwo)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CreateResultStars | |
{ | |
private readonly MultiplyByTwo _multiplier; | |
public string Stars { get; private set; } | |
public CreateResultStars(MultiplyByTwo multiplier) | |
{ | |
_multiplier = multiplier; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static readonly DependencyProperty NumberProperty = | |
DependencyProperty.Register(nameof(Number), | |
typeof(int), | |
typeof(MultiplyByTwo), | |
new PropertyMetadata(0, CalculateResult)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static readonly DependencyProperty AProperty = | |
DependencyProperty.Register(nameof(A), | |
typeof(int), | |
typeof(AddCalculation), | |
new PropertyMetadata(0, AddNumbers)); | |
private static void AddNumbers(DependencyObject d, DependencyPropertyChangedEventArgs e) | |
{ | |
var ac = (AddCalculation)d; | |
ac.SetValue(ResultPropertyKey, ac.A + ac.B); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestFixture] | |
public class ReadOnlyDependencyPropertiesShould | |
{ | |
[Test] | |
public void BeReadableByAnyone() | |
{ | |
var ac = new AddCalculation | |
{ | |
A = 42 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int Result | |
{ | |
get { return (int)GetValue(ResultProperty); } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static readonly DependencyProperty ResultProperty = | |
ResultPropertyKey.DependencyProperty; |