views:

8

answers:

0

Hey there, having trouble with this one...

I have 2 different types of usercontrols that I want to use one x:Name with.

Only one will be active/exist/on stage at a time.

Say for simplicity, one is of type MyCircle and the other is of type MyRectangle. And say there is a MyCircle instance declared in XAML at first with the x:Name = "MyShape". And there are functions that exist that do some action on "MyShape", like turn the Opacity on or off, rotate it, etc.

So now what I want to do is have a button that swaps in an instance of MyRectangle for the MyCircle control and still have the functions work on it, since it will now be called "MyShape".

I've tried Children.Remove(MyCircle), then create a new instace of MyRectangle, set it's name to "MyShape" and then Chidren.Add(MyRectangle) but I get an error:

"Value does not fall within the expected range."

Is there a proper way to do this type of swapping and still keeping the same x:Name reference?

Thanks.