@@ -48,9 +48,20 @@ public override Type ComponentType {
4848 get { return _xamlObject . ElementType ; }
4949 }
5050
51+ void SetNameInternal ( string newName )
52+ {
53+ _xamlObject . Name = newName ;
54+ }
55+
5156 public override string Name {
5257 get { return _xamlObject . Name ; }
53- set { _xamlObject . Name = value ; }
58+ set {
59+ UndoService undoService = this . Services . GetService < UndoService > ( ) ;
60+ if ( undoService != null )
61+ undoService . Execute ( new SetNameAction ( this , value ) ) ;
62+ else
63+ SetNameInternal ( value ) ;
64+ }
5465 }
5566
5667 public override string Key {
@@ -174,5 +185,52 @@ public override DesignItem Clone()
174185 }
175186 return item ;
176187 }
188+
189+ sealed class SetNameAction : ITransactionItem
190+ {
191+ XamlDesignItem designItem ;
192+ string oldName ;
193+ string newName ;
194+
195+ public SetNameAction ( XamlDesignItem designItem , string newName )
196+ {
197+ this . designItem = designItem ;
198+ this . newName = newName ;
199+
200+ oldName = designItem . Name ;
201+ }
202+
203+ public string Title {
204+ get {
205+ return "Set name" ;
206+ }
207+ }
208+
209+ public void Do ( )
210+ {
211+ designItem . SetNameInternal ( newName ) ;
212+ }
213+
214+ public void Undo ( )
215+ {
216+ designItem . SetNameInternal ( oldName ) ;
217+ }
218+
219+ public System . Collections . Generic . ICollection < DesignItem > AffectedElements {
220+ get {
221+ return new DesignItem [ ] { designItem } ;
222+ }
223+ }
224+
225+ public bool MergeWith ( ITransactionItem other )
226+ {
227+ SetNameAction o = other as SetNameAction ;
228+ if ( o != null && designItem == o . designItem ) {
229+ newName = o . newName ;
230+ return true ;
231+ }
232+ return false ;
233+ }
234+ }
177235 }
178236}
0 commit comments