Undo/Redo

If you use GanttChartDataGrid (or another) control from DlhSoft Gantt Chart Light Library (available for both Silverlight™ and WPF) and you need built-in Undo/Redo support to enable an action queue in your application:

  • set IsUndoEnabled property of the control instance to true;
  • determine whether undoing or redoing actions is possible at any moment by calling CanUndo and CanRedo methods of the control;
  • call Undo and Redo methods whenever needed (e.g. when the end user clicks one of the the Undo and Redo buttons or menu items in your own toolbar or menu).

If you want to customize the feature further, these properties will probably help you:

  • UndoLimit – allows you to specify a limit for the internal Undo queue (to limit internal memory usage);
  • UndoLinkingTimeLimit – allows you to specify a time interval value to consider when linking separate actions as action groups to be undone and redone together (very useful for recording partially continuous drag and drop operations as unitary actions);
  • UndoQueueCount – retreives how many unitary actions are currently recorded within the Undo queue (you can clear the queue by calling ClearUndoQueue method, if needed).

Finally, if you inherit from GanttChartItem type to provide custom properties for your data items and need them to be handled by the internal Undo/Redo mechanism, you just need to make sure your properties are set up as dependency properties and to call the protected OnManagedDependencyPropertyChanged method of the component, passing the event arguments you receive upon your DependencyPropertyChanged callbacks. Here is an example for a property named MyValue:

public class CustomGanttChartItem : GanttChartItem
{

  public static readonly DependencyProperty MyValueProperty =
    DependencyProperty.Register(“MyValue“, typeof(string),
      typeof(CustomGanttChartItem), new PropertyMetadata(null,
        new PropertyChangedCallback(OnMyValueChanged)));

  public string MyValue
  {
   
get { return (string)GetValue(MyValueProperty); }
    set { SetValue(MyValueProperty, value); }
  }

  private static void OnMyValueChanged(
    DependencyObject d, DependencyPropertyChangedEventArgs e)
  {
   
var item = d as CustomGanttChartItem;
   
if (item == null)
     
return;
   
item.OnPropertyChanged(“MyValue“);
   
item.OnManagedDependencyPropertyChanged(e);
  }

  […]

}

Advertisements

About DlhSoft Team

DlhSoft is a software development company focused on building high quality and innovative solutions using state-of-the-art technologies for customers worldwide. Our activity includes designing and developing general purpose software applications, components and tools, and customized software solutions upon request. DlhSoft team is highly experienced and fully dedicated to software development. Additionally, one of the most important things we rely on is the continuous communication with the customer.
This entry was posted in Development Components and tagged , . Bookmark the permalink.

Add a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s