The solution then is
to limit the number of items you keep in the history or use a more intelligent (and more complex) routine that
stores information about only the changed data, rather than all the data.
The CommandHistoryItem also includes one method, an all-purpose Undo() method.
This method uses reflection to apply the previous value to the modified property. This works
for restoring the text in a TextBox, but in a more complex application you??™d need a hierarchy
of CommandHistoryItem classes, each of which is able to revert a different type of action in
a different way.
Here??™s the complete code for the CommandHistoryItem class:
Public Class CommandHistoryItem
Private _commandName As String
Public Property CommandName() As String
Get
Return _commandName
End Get
Set(ByVal value As String)
_commandName = value
End Set
End Property
Private _elementActedOn As UIElement
Public Property ElementActedOn() As UIElement
Get
Return _elementActedOn
End Get
Set(ByVal value As UIElement)
_elementActedOn = value
End Set
End Property
Private _propertyActedOn As String
Public Property PropertyActedOn() As String
Get
Return _propertyActedOn
End Get
Set(ByVal value As String)
_propertyActedOn = value
End Set
End Property
CHAPTER 10 n COMMANDS 316
Private _previousState As Object
Public Property PreviousState() As Object
Get
Return _previousState
End Get
Set(ByVal value As Object)
_previousState = value
End Set
End Property
Public Sub New(ByVal commandName As String)
Me.
Pages:
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573