PercivalMcGullicuddy
PercivalMcGullicuddy

Reputation: 5533

Silverlight - Creating a rectangle that grows/shrinks to accommodate the text of a label within it

Pretty straight forward. I have a rectangle with a label over top of it. I'f like to know how to get the rectangle to scale to fit the text.

my XAML:

 <Grid x:Name="LayoutRoot" Background="White" Height="158" Width="264">
    <Rectangle Height="22" HorizontalAlignment="Left" Name="rectangle1" Stroke="Black" MinWidth="40"  StrokeThickness="1" VerticalAlignment="Top"  RadiusX="6" RadiusY="6" Fill="#1b6487" Width="64"></Rectangle>
    <sdk:Label Margin="9,3,209,0" Name="label1" VerticalAlignment="Top"  Content="$999.99" />
</Grid>

Upvotes: 0

Views: 457

Answers (1)

Joe White
Joe White

Reputation: 97696

Remove your explicit widths and heights.

You've got the Rectangle and the Label in the same cell of the Grid, so by default they will be the same size. You're overriding that and telling them not to be.

Alternatively, you could wrap a Border around your Label. This is the sort of thing that Border is meant for.

Upvotes: 4

Related Questions