views:

31

answers:

2

Can you give me an example how to create custom composite control (in Silverlight 4) which derives directly from the FrameworkElement. Here is a mockup:

public sealed class CompositeImage : FrameworkElement
{
    private readonly List<Image> images;

    public CompositeImage()
    {
        images = new List<Image>();
        images.Add(new Image { Source = "..." });
        images.Add(new Image { Source = "..." });
    }

    protected override Size MeasureOverride(Size availableSize)
    {
        throw new NotImplementedException();
    }
    protected override Size ArrangeOverride(Size finalSize)
    {
        throw new NotImplementedException();
    }
}
+1  A: 

I'm having trouble imagining any scenerio where doing such thing would be desirable.

Use a UserControl or a templated control. Its difficult even providing any more of an answer than that without a better understanding of what you want to acheive.

AnthonyWJones
A: 

I guess it could make sense to inherit from FrameworkElement if you wish to create some sort of "Image-only" panel. It looks from your code example that the list of images would be fixed? Then you could write code in MeasureOverride and ArrangeOverride to lay them out. But as AnthonyWJones said, more details on what you're trying to accomplish would help determine the best way to go.

Alex