Button Content behavior changes in Silverlight RC0
Recently I ran into an issue with my Silverlight application after I migrating it from Silverlight 2 Beta2 to RC0 version. Here is the sample code for sake of simple example purpose:
<Grid x:Name="LayoutRoot" Background="White">
<Button Width="200" Height="50">
<Button.Content>
<Grid>
<Rectangle Fill="Blue"/>
</Grid>
</Button.Content>
</Button>
</Grid>
Previously with Beta2 bits, it will show a button with blue rectangle inside, but the blue rectangle no longer appears when I compile it with RC0 SDK. Having got the answer from our Silverlight forums, apparently there is change from Beta2 to RC0, which the default value of Button.HorizontalContentAlignment and Button.VerticalContentAlignment have been changed from Stretch to Center (makes it compatible with WPF), hence changing the previous code to below will give us the same behavior as we seeing in Beta2 (the blue rectangle showing up this time). I hope this will help in case you run into similar issue.
<Grid x:Name="LayoutRoot" Background="White">
<Button Width="200" Height="50"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<Button.Content>
<Grid>
<Rectangle Fill="Blue"/>
</Grid>
</Button.Content>
</Button>
</Grid>
Comments
Anonymous
October 07, 2008
PingBack from http://www.easycoded.com/button-content-behavior-changes-in-silverlight-rc0/Anonymous
October 07, 2008
You've been kicked (a good thing) - Trackback from DotNetKicks.com