-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generated change-handlers can use routed events (#14)
If we find a routed event that appears to match the dependency property, then it may be used as the property-changed handler. In the case of multiple candidates, the priority is - static methods - instance methods - routed events
- Loading branch information
Showing
8 changed files
with
192 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright © Ian Good | ||
|
||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace Bpz.Test | ||
{ | ||
public abstract partial class NumericUpDownBase<TValue> : Control | ||
{ | ||
public static readonly DependencyProperty ValueProperty = Gen.Value<TValue>(FrameworkPropertyMetadataOptions.BindsTwoWayByDefault); | ||
|
||
public static readonly RoutedEvent ValueChangedEvent = Gen.ValueChanged<TValue>(); | ||
} | ||
|
||
public class DoubleUpDown : NumericUpDownBase<double> { } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright © Ian Good | ||
|
||
using NUnit.Framework; | ||
using System.Threading; | ||
using System.Windows; | ||
|
||
namespace Bpz.Test | ||
{ | ||
/// <summary> | ||
/// Checks behavior of generic base types and raising routed events from generated change-handlers. | ||
/// </summary> | ||
public class NumericUpDownsTests | ||
{ | ||
[Test] | ||
public void ExpectMetadata() | ||
{ | ||
RoutedEventAssert.Matches(new() | ||
{ | ||
OwnerType = typeof(NumericUpDownBase<double>), | ||
Name = "ValueChanged", | ||
HandlerType = typeof(RoutedPropertyChangedEventHandler<double>), | ||
}); | ||
|
||
DependencyPropertyAssert.Matches(new() | ||
{ | ||
OwnerType = typeof(NumericUpDownBase<double>), | ||
Name = "Value", | ||
PropertyType = typeof(double), | ||
}); | ||
} | ||
|
||
[Test] | ||
[Apartment(ApartmentState.STA)] | ||
public void ExpectEventHandlers() | ||
{ | ||
var dud = new DoubleUpDown(); | ||
|
||
bool eventWasRaised; | ||
dud.ValueChanged += (s, e) => | ||
{ | ||
Assert.AreSame(dud, s); | ||
eventWasRaised = true; | ||
e.Handled = true; | ||
}; | ||
|
||
{ | ||
eventWasRaised = false; | ||
dud.Value = 867.5309; | ||
Assert.IsTrue(eventWasRaised); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Windows; | ||
using Butt = System.Windows.Controls.Button; | ||
|
||
namespace PropChangedEvents | ||
{ | ||
public partial class TestMe : Butt | ||
{ | ||
public static readonly DependencyProperty AProperty = Gen.A<int>(); | ||
public static readonly RoutedEvent AChangedEvent = Gen.AChanged<int>(); | ||
|
||
public static readonly DependencyProperty BProperty = Gen.B<object>(); | ||
public static readonly RoutedEvent BChangedEvent = Gen.BChanged<object>(); | ||
} | ||
} |
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
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
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