When you add things in the designer, they are forced to have unique names. This is a requirement. If those names are serialized, the names are unique, within that Picture. I think you are seeing the name that is serialized by default for a top-level Picture, not a sub Picture. If your sub Pictures is added dynamically, you have to generate a unique name when you add it. You can also set the Tag property if you wish, to a string or any other object.
If your Sensor is added to another Picture, as a sub-Picture, in the designer, it already has a unique name, as long as SerializeNames is set to true on the parent Picture. If not, it will continue to use its original name.
You can generate a unique name for dynamically added items by using a static integer field that is incremented for each new name, and converting that to a string, with some kind of prefix you would like for debugging.
By default the Fill value on an Element is null. Fill objects are never shared. If you want to share one, it is use a Style, and set the Style property on each Element. If you never want to share one, you must create one explicitly for each Shape. If they are only defined dynamically, it is best to do this at run-time. No point in creating them in the designer. I probably need more information to make a better recommendation.
If you are only setting the ImageFill in your event handler, you can check to see if the Fill property refers to an ImageFill. If not, create a new ImageFill. If so, modify the one you have.
Code: Select all
Shape shape = sender as Shape;
if (shape != null)
ImageFill imageFill = shape.Fill as ImageFill;
if (imageFill == null)
imageFill = new ImageFill();
// ... initialize imageFill ...
shape.Fill = imageFill;
// ... modify imageFill ...