Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Invalid Cast Exception On Undo (Read 1674 times)
integragreg
YaBB Newbies
*
Offline



Posts: 40
Location: Tennessee
Joined: Jan 26th, 2009
Invalid Cast Exception On Undo
Jun 29th, 2010 at 4:09pm
Print Post  
We have some custom shapes that we are assigning to the UIElement of a node whenever a user drops one of our shapes onto a diagram.

We are trying to implement an Undo when the user rotates the node, but when we begin recording the action as part of a composite command, we get the following exception:

Unable to cast object of type 'MindFusion.Diagramming.Wpf.DiagramItemProperties' to type 'MindFusion.Diagramming.Wpf.DiagramNodeProperties'

The exception is being thrown in the DiagramNode.SaveProperties().

We are at a loss as to why the cast cannot take place in the SaveProperties() method. Is there anything special that needs to be done to make our node's DiagramItemProperties castable to a DiagramNodeProperties instance? Our code is shown below.

Code
Select All
CompositeCmd composite = new CompositeCmd(CurrentDiagram, "RotateObject");






double selectionCount = CurrentDiagram.Selection.Items.Count;



bool unRotatableItems = false;



double unrotatedCount = 0;



foreach (DiagramNode node in CurrentDiagram.Selection.Nodes)



{




if (node.UIElement is IRotatable)




{





ChangeItemCmd c = null ;





try





{






c = new ChangeItemCmd(node as DiagramItem, "Change");





}





catch (Exception ex)





{






Trace.WriteLine(ex);






if (ex.InnerException != null)






{







Trace.WriteLine(ex.InnerException);






}





}





node.RotationAngle = node.RotationAngle + degrees;





(node.UIElement as IRotatable).Angle = node.RotationAngle;






if (c != null)





{






c.Execute();






composite.AddSubCmd(c);





}




}




else




{





unRotatableItems = true;





unrotatedCount++;




}



}



composite.Execute();
 

  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Invalid Cast Exception On Undo
Reply #1 - Jun 29th, 2010 at 4:30pm
Print Post  
Are you overriding the DiagramNode.CreateProperties() method? If yes, does the returned object inherit from DiagramNodeProperties, or from the more general DiagramItemProperties?
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint