views:

108

answers:

1

I have an Ellipse and a TextBlock that I want to be Centred relative to each other - ie the TextBlock shows in the Centre of the Ellipse no matter the content eg. its says 88 (like a Bingo Ball) and the Ellipse is the Ball itself - and the number shows in the centre of this ball.

How to I accomplish this in Silverlight, where the sizes are not fixed, as if possible I want the Ellipse and TextBlock to be the relative size of their parent - which I cannot seem to do in Silverlight either.

Related to this problem is I cannot find the code behind equivelent for "LimeGreen" the colour, which can be set in XAML but not in Code, where only a few Colours are available the in the Color class?

+1  A: 

The style of layout desired is provided by the Grid control. However I suspect you would also want the text to scale with the size of the ellipse, this can be acheived with the Silverlight Toolkit Viewbox control:-

<Grid>
 <Ellipse Fill="Blue" />
 <controlstk:Viewbox>
  <TextBlock Text="88" Margin="2" />  
 </controlstk:Viewbox>  
</Grid>

BTW, LimeGreen is #FF32CD32.

AnthonyWJones
Personally I'd drop the ViewBox unless everything has the same number of characters. Having buttons that are all supposed to look the same except for the font size usually ends up looking weird. Other than that it's what I was going to suggest.
Bryan Anderson
@Bryan: Its a good point perhaps I took the "Bingo Ball" too literally ;)
AnthonyWJones
Thanks for this - I'm used to WPF with elements just scaling correctly but viewbox will scale elements like this - I am using absolute positioning and this seems to work. Silverlight 4 supports ViewBox natively so I'll remember to use that in future for scaling issues (size)
RoguePlanetoid