Class Behavior<T>
- Namespace
- Tudormobile.Wpf.Behaviors
- Assembly
- Tudormobile.WpfControls.dll
Provides utility methods for managing attached properties and adorners for elements of type T.
public class Behavior<T> where T : FrameworkElement
Type Parameters
TThe type of the element to which the behavior applies. Must derive from FrameworkElement.
- Inheritance
-
Behavior<T>
- Derived
- Inherited Members
Remarks
This class includes methods to handle changes to attached properties, manage adorners, and ensure proper updates to the visual state of elements. It is designed to simplify the creation and management of behaviors that rely on attached properties and adorners.
Methods
AttachedPropertyChanged(DependencyObject, DependencyPropertyChangedEventArgs, Action<T, DependencyProperty, bool>)
Handles changes to an attached property on a DependencyObject and invokes a specified action when the property value changes.
protected static void AttachedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e, Action<T, DependencyProperty, bool> valueChanged)
Parameters
dDependencyObjectThe DependencyObject on which the attached property has changed.
eDependencyPropertyChangedEventArgsThe event data containing information about the property change, including the old and new values.
valueChangedAction<T, DependencyProperty, bool>An action to invoke when the property value changes. The action receives the following parameters: the element of type
T, the changed DependencyProperty, and a boolean indicating whether the action is triggered after the element is loaded (true) or immediately (false).
Remarks
If the d object is of type T and is already loaded,
the valueChanged action is invoked immediately. Otherwise, the action is deferred until the
element's Loaded event occurs.
AttachedPropertyChanged<TAdorner>(DependencyObject, DependencyPropertyChangedEventArgs, Action<T, TAdorner>)
Handles changes to an attached property and updates or creates an adorner for the associated element.
protected static void AttachedPropertyChanged<TAdorner>(DependencyObject d, DependencyPropertyChangedEventArgs e, Action<T, TAdorner> updateAdorner) where TAdorner : Adorner
Parameters
dDependencyObjectThe DependencyObject to which the attached property is applied. Must be of type
T.eDependencyPropertyChangedEventArgsThe event data for the property change, containing the old and new values of the attached property.
updateAdornerAction<T, TAdorner>A callback action that updates the adorner. The action receives the element of type
Tand the adorner of typeTAdorner.
Type Parameters
TAdornerThe type of the adorner to be created or updated. Must derive from Adorner.
Remarks
This method ensures that an adorner of type TAdorner is created or
updated when the attached property changes. If the element is already loaded, the adorner is updated
immediately. If the element is not yet loaded, the adorner is created and added to the AdornerLayer when the element's Loaded event is raised.
InvalidateAdorner<TAdorner>(UIElement)
Invalidates the visual representation of the first adorner of the specified type applied to the given UI element.
protected static void InvalidateAdorner<TAdorner>(UIElement v) where TAdorner : Adorner
Parameters
Type Parameters
TAdornerThe type of the adorner to invalidate. Must derive from Adorner.
Remarks
This method retrieves the adorner layer for the specified UIElement, locates the first adorner of the specified type, and invalidates its visual state. If no adorner of the specified type is found, the method has no effect.