Skip to main content
Home Forums Silverlight Design Designing with Silverlight Bug? HorizontalAlignment not respected in Silverlight as in WPF
3 replies. Latest Post by melshall on June 26, 2008.
(0)
MichaelGG
Member
86 points
25 Posts
03-25-2008 1:42 PM |
I ran into a bug doing some layout with nested controls. Here's a simplified repro:
In WPF setting HorizontalAlignment on a control will let it resize itself if it's inside a stretched element. For example:
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="Auto" Width="Auto"> <Grid> <StackPanel> <Button Content="asd" HorizontalAlignment="Center" /> </StackPanel> </Grid></Window>
This will show a button not much larger than it's content, centered in the Window. However, doing the same in Silverlight fails:
<UserControl x:Class="SilverlightApplication1.Page" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="Auto" Height="Auto"> <Grid> <StackPanel> <Button Content="asd" HorizontalAlignment="Center" /> </StackPanel> </Grid></UserControl>
The button is stretched across the entire window.
My WPF-layout-powers are not that strong, so it's quite possible that I'm missing something here. But it does appear as if SL isn't behaving how it should.
Thanks,Michael
Yi-Lun L...
All-Star
25052 points
2,747 Posts
03-27-2008 12:42 AM |
Hello, this is a known problem which is caused by Button's default template. As you've probably noticed, there's a curve in a Button.
Nice as it is, this will cause layout problems. Add this Path to a WPF's Button's template, and you'll get the same result. So you have to override the Button's template, and remove this Path or so...
03-27-2008 12:51 PM |
Awesome, thanks. So we'll just restyle and everything will be fine.
-Michael
melshall
4 points
2 Posts
06-26-2008 12:45 PM |
Thanks everybody, That's a known bug in Button's default template, and should be fixed in RTM.