using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
///
///
/// Contains a collection of DependencyObject extension methods.
///
public static class DependencyObjectExtensions
{
///
/// Invokes the current dependency object dispatcher.
///
/// The dependency object.
/// The action.
internal static void BeginInvoke(this DependencyObject dependencyObject, Action action)
{
dependencyObject.Dispatcher.BeginInvoke(action);
}
///
/// Invokes the specified action.
///
/// The dependency object.
/// The action.
internal static void Invoke(this DependencyObject dependencyObject, Action action)
{
dependencyObject.Dispatcher.Invoke(action);
}
///
/// Determines whether this object is currently in design time mode.
///
/// The object.
///
internal static bool IsInDesignMode(this DependencyObject obj)
{
return (DesignerProperties.GetIsInDesignMode(obj));
}
///
/// Binds the specified dependency property to a another object property.
///
/// The target dependency object.
/// The target dependency property.
/// The source object.
/// The source dependency property.
/// Binding mode.
/// Binding converter.
///
public static Binding Bind(this DependencyObject target, DependencyProperty targetDP, DependencyObject source, DependencyProperty sourceDP, BindingMode mode, IValueConverter converter = null)
{
Binding binding = new Binding();
binding.Mode = mode;
binding.Source = source;
binding.Path = new PropertyPath(sourceDP);
binding.Converter = converter;
BindingOperations.SetBinding(target, targetDP, binding);
return binding;
}
///
/// Binds the specified dependency property to a another object property.
///
/// The target dependency object.
/// The target dependency property.
/// The source object.
/// The source dependency property.
/// Binding mode.
///
public static Binding Bind(this DependencyObject target, DependencyProperty targetDP, DependencyObject source, DependencyProperty sourceDP, BindingMode mode = BindingMode.Default)
{
Binding binding = new Binding();
binding.Mode = mode;
binding.Source = source;
binding.Path = new PropertyPath(sourceDP);
BindingOperations.SetBinding(target, targetDP, binding);
return binding;
}
///
/// Create asynchronous binding between target and source.
///
/// The target dependency object.
/// The target dependency property.
/// The source object.
/// The source dependency property.
/// Binding mode.
///
public static Binding BindAsync(this DependencyObject target, DependencyProperty targetDP, DependencyObject source, DependencyProperty sourceDP, BindingMode mode = BindingMode.Default)
{
Binding binding = new Binding();
binding.Mode = mode;
binding.Source = source;
binding.Path = new PropertyPath(sourceDP);
binding.IsAsync = true;
binding.BindsDirectlyToSource = true;
BindingOperations.SetBinding(target, targetDP, binding);
return binding;
}
///
/// Binds the specified dependency property to a another object property.
///
/// The target dependency object.
/// The target dependency property.
/// The source object.
/// The source dependency property name.
/// Binding mode.
///
public static Binding Bind(this DependencyObject target, DependencyProperty targetDP, DependencyObject source, String sourceDP, BindingMode mode = BindingMode.Default)
{
Binding binding = new Binding();
binding.Mode = mode;
binding.Source = source;
binding.Path = new PropertyPath(sourceDP);
BindingOperations.SetBinding(target, targetDP, binding);
return binding;
}
///
/// Clears bindings from the specified dependency property.
///
/// The target dependency object.
/// The dependency property.
public static void Unbind(this DependencyObject target, DependencyProperty dependencyProperty)
{
BindingOperations.ClearBinding(target, dependencyProperty);
}
}