I have the following C# code in a method of a class that inherits from Image. Basically I'm setting a random left margin (within some parameters) relative to its container (a Grid object).
int auxLeftMargin = rand.Next(Convert.ToInt32( ((Grid)Parent).ActualWidth / 4), Convert.ToInt32(((Grid)Parent).ActualWidth - ((Grid)Parent).ActualWidth / 6));
Margin = new Thickness(auxLeftMargin, Margin.Top, Margin.Right, Margin.Bottom);
I've changed the container type a couple of times already, so I would like to be able to not have it hardcoded. I've tried casting with "( Parent.GetType() )" but it doesn't work.
Is there a way to do this dynamically? Thanks.
View Complete Post