Hi, I have a screen which has a palette and a normal model. The user can drag shapes from the palette onto the model to build up a flow chart etc (pretty standard stuff).
I used the example code in “Palette Example CS” to populate my palette and everything seemed to work ok. The palette was rendered, the items were arranged automatically, and if I resized the palette the items were automatically re-arranged.
Now initially I was populating the palette only once when the form was first initialized, as I had a static list of shapes to add to the palette.
I have now enhanced my application so that the list of items in the palette can change dynamically. There are two tabs in my application and changes in the first tab effect what shapes are available in the palette located in the second tab.
Therefore I have some code in the tab control changed tab event which clears the existing palette and repopulates it each time the user switches from the first to the second tab. In order to clear the existing items from the palette I call *palette.Clear()*. I then add the new list of shapes.
The first time I load the application and switch to the second tab (there are no shapes to remove yet) the palette is rendered correctly and the shapes are arranged as expected. However on every subsequent attempt to change tabs the existing shapes in the palette are removed and then repopulated and the palette is redrawn with all shapes at location 0,0 and no auto arranging is performed. Even if the palette is resized the shapes are not re-arranged.
The issue is in the *palette.Clear()* somehow. This seems to be putting the palette in some unknown state which is preventing auto-arranging of any shapes. I have tried calling *palette.Shapes.Clear()* instead and the same thing happened.
The only fix I have been able to come up with is to manually remove each shape from the palette by looping around the shapes collection and calling *palette.Shapes.Remove( shape.Key )*. When I then re-add the shapes the palette is auto-arranged as expected.
This is not a show-stopper anymore, since I found the solution above, but can someone explain to me what is happening inside *palette.Shapes.Clear()*?
NOTE: Version 3.8.2130.17732 of the Crainiate controls with .NET v1.1.