Page view counter
Bug? HorizontalAlignment not respected in Silverlight as in WPF
Last post 06-26-2008 12:45 PM by melshall. 3 replies.
Sort Posts:
03-25-2008 1:42 PM
Bug? HorizontalAlignment not respected in Silverlight as in WPF

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

 

MichaelGG

Loading...
Joined on 03-14-2008
Posts 25
03-27-2008 12:42 AM
Marked as Answer
Re: Bug? HorizontalAlignment not respected in Silverlight as in WPF

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.

<Path x:Name="CurvedBevel" Stretch="Fill" Margin="3,0,3,0" Data="F1 M 0,0.02 V 0.15 C 0.15,0.22 0.30,0.25 0.50,0.26 C 0.70,0.26 0.85,0.22 1,0.15 V 0.02 L 0.97,0 H 0.02 L 0,0.02 Z">

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...

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Yi-Lun Luo - MSFT

Loading...
Joined on 10-29-2007
Posts 2,688
03-27-2008 12:51 PM
Re: Bug? HorizontalAlignment not respected in Silverlight as in WPF

Awesome, thanks. So we'll just restyle and everything will be fine.

-Michael

MichaelGG

Loading...
Joined on 03-14-2008
Posts 25
06-26-2008 12:45 PM
Re: Re: Bug? HorizontalAlignment not respected in Silverlight as in WPF

Thanks everybody, That's a known bug in Button's default template, and should be fixed in RTM.

melshall

Loading...
Joined on 03-12-2008
Posts 2
Microsoft Communities