// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993] for details.
// All other rights reserved.
using System;
using System.Windows;
namespace System.Windows.Controls
{
///
/// Provides event data for various routed events that track property values
/// changing. Typically the events denote a cancellable action.
///
///
/// The type of the value for the dependency property that is changing.
///
/// Preview
public class RoutedPropertyChangingEventArgs : RoutedEventArgs
{
///
/// Gets the
/// identifier for the property that is changing.
///
///
/// The identifier
/// for the property that is changing.
///
public DependencyProperty Property { get; private set; }
///
/// Gets a value that reports the previous value of the changing
/// property.
///
///
/// The previous value of the changing property.
///
public T OldValue { get; private set; }
///
/// Gets or sets a value that reports the new value of the changing
/// property, assuming that the property change is not cancelled.
///
///
/// The new value of the changing property.
///
public T NewValue { get; set; }
///
/// Gets a value indicating whether the property change that originated
/// the RoutedPropertyChanging event is cancellable.
///
///
/// True if the property change is cancellable. false if the property
/// change is not cancellable.
///
public bool IsCancelable { get; private set; }
///
/// Gets or sets a value indicating whether the property change that
/// originated the RoutedPropertyChanging event should be cancelled.
///
///
/// True to cancel the property change; this resets the property to
/// .
/// false to not cancel the property change; the value changes to
/// .
///
///
/// Attempted to cancel in an instance where
///
/// is false.
///
public bool Cancel
{
get { return _cancel; }
set
{
if (IsCancelable)
{
_cancel = value;
}
else if (value)
{
throw new InvalidOperationException(Muchinfo.WPF.Controls.Properties.Resources.RoutedPropertyChangingEventArgs_CancelSet_InvalidOperation);
}
}
}
///
/// Private member variable for Cancel property.
///
private bool _cancel;
///
/// Gets or sets a value indicating whether internal value coercion is
/// acting on the property change that originated the
/// RoutedPropertyChanging event.
///
///
/// True if coercion is active. false if coercion is not active.
///
///
/// This is a total hack to work around the class hierarchy for Value
/// coercion in NumericUpDown.
///
public bool InCoercion { get; set; }
///
/// Initializes a new instance of the
///
/// class.
///
///
/// The identifier
/// for the property that is changing.
///
/// The previous value of the property.
///
/// The new value of the property, assuming that the property change is
/// not cancelled.
///
///
/// True if the property change is cancellable by setting
///
/// to true in event handling. false if the property change is not
/// cancellable.
///
public RoutedPropertyChangingEventArgs(
DependencyProperty property,
T oldValue,
T newValue,
bool isCancelable)
{
Property = property;
OldValue = oldValue;
NewValue = newValue;
IsCancelable = isCancelable;
Cancel = false;
}
#if !SILVERLIGHT
///
/// Initializes a new instance of the
///
/// class.
///
///
/// The identifier
/// for the property that is changing.
///
/// The previous value of the property.
///
/// The new value of the property, assuming that the property change is
/// not cancelled.
///
///
/// True if the property change is cancellable by setting
///
/// to true in event handling. false if the property change is not
/// cancellable.
///
/// The routed event identifier for this instance.
public RoutedPropertyChangingEventArgs(DependencyProperty property,
T oldValue, T newValue, bool isCancelable, RoutedEvent routedEvent)
: base(routedEvent)
{
Property = property;
OldValue = oldValue;
NewValue = newValue;
IsCancelable = isCancelable;
Cancel = false;
}
#endif
}
}