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.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Tango.Core.Commands;
namespace Tango.Editors
{
///
/// Represents abstract user control with some additional features.
///
///
///
public class HybridControl : UserControl, INotifyPropertyChanged
{
///
/// Raises the property changed event.
///
/// Name of the property.
protected virtual void RaisePropertyChanged(String propName)
{
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
///
/// Raises all relay commands CanExecute methods in the current instance.
///
public virtual void InvalidateRelayCommands()
{
this.Dispatcher.BeginInvoke(new Action(() =>
{
foreach (var prop in this.GetType().GetProperties().Where(x => x.PropertyType == typeof(RelayCommand)))
{
var value = prop.GetValue(this) as RelayCommand;
if (value != null)
{
value.RaiseCanExecuteChanged();
}
}
}));
}
///
///
/// Cast the instance of a dependency object to type T.
///
///
/// The d.
///
public static T GetInstance(DependencyObject d) where T : DependencyObject
{
return d as T;
}
///
/// Occurs when a property value has changed.
///
public event PropertyChangedEventHandler PropertyChanged;
}
}