ActionExtension.NullTarget and .ActionNotFound are no longer nullable, leading to clearer XAML

This commit is contained in:
Antony Male 2014-07-25 12:36:15 +01:00
parent 60aca05dd2
commit 7147f4cb43
1 changed files with 13 additions and 4 deletions

View File

@ -11,6 +11,11 @@ namespace Stylet.Xaml
/// </summary> /// </summary>
public enum ActionUnavailableBehaviour public enum ActionUnavailableBehaviour
{ {
/// <summary>
/// The default behaviour. What this is depends on whether this applies to an action or target, and an event or ICommand
/// </summary>
Default,
/// <summary> /// <summary>
/// Enable the control anyway. Clicking/etc the control won't do anything /// Enable the control anyway. Clicking/etc the control won't do anything
/// </summary> /// </summary>
@ -40,12 +45,12 @@ namespace Stylet.Xaml
/// <summary> /// <summary>
/// Behaviour if the View.ActionTarget is nulil /// Behaviour if the View.ActionTarget is nulil
/// </summary> /// </summary>
public ActionUnavailableBehaviour? NullTarget { get; set; } public ActionUnavailableBehaviour NullTarget { get; set; }
/// <summary> /// <summary>
/// Behaviour if the action itself isn't found on the View.ActionTarget /// Behaviour if the action itself isn't found on the View.ActionTarget
/// </summary> /// </summary>
public ActionUnavailableBehaviour? ActionNotFound { get; set; } public ActionUnavailableBehaviour ActionNotFound { get; set; }
/// <summary> /// <summary>
/// Create a new ActionExtension /// Create a new ActionExtension
@ -73,13 +78,17 @@ namespace Stylet.Xaml
var propertyAsDependencyProperty = valueService.TargetProperty as DependencyProperty; var propertyAsDependencyProperty = valueService.TargetProperty as DependencyProperty;
if (propertyAsDependencyProperty != null && propertyAsDependencyProperty.PropertyType == typeof(ICommand)) if (propertyAsDependencyProperty != null && propertyAsDependencyProperty.PropertyType == typeof(ICommand))
{ {
return new CommandAction((DependencyObject)valueService.TargetObject, this.Method, this.NullTarget.GetValueOrDefault(ActionUnavailableBehaviour.Disable), this.ActionNotFound.GetValueOrDefault(ActionUnavailableBehaviour.Throw)); var nullTarget = this.NullTarget == ActionUnavailableBehaviour.Default ? ActionUnavailableBehaviour.Disable : this.NullTarget;
var actionNotFound = this.ActionNotFound == ActionUnavailableBehaviour.Default ? ActionUnavailableBehaviour.Throw : this.ActionNotFound;
return new CommandAction((DependencyObject)valueService.TargetObject, this.Method, nullTarget, actionNotFound);
} }
var propertyAsEventInfo = valueService.TargetProperty as EventInfo; var propertyAsEventInfo = valueService.TargetProperty as EventInfo;
if (propertyAsEventInfo != null) if (propertyAsEventInfo != null)
{ {
var ec = new EventAction((DependencyObject)valueService.TargetObject, propertyAsEventInfo, this.Method, this.NullTarget.GetValueOrDefault(ActionUnavailableBehaviour.Enable), this.ActionNotFound.GetValueOrDefault(ActionUnavailableBehaviour.Throw)); var nullTarget = this.NullTarget == ActionUnavailableBehaviour.Default ? ActionUnavailableBehaviour.Enable : this.NullTarget;
var actionNotFound = this.ActionNotFound == ActionUnavailableBehaviour.Default ? ActionUnavailableBehaviour.Throw : this.ActionNotFound;
var ec = new EventAction((DependencyObject)valueService.TargetObject, propertyAsEventInfo, this.Method, nullTarget, actionNotFound);
return ec.GetDelegate(); return ec.GetDelegate();
} }