Skip to main content

Microsoft Silverlight

Answered Question Bug? HorizontalAlignment not respected in Silverlight as in WPFRSS Feed

(0)

MichaelGG
MichaelGG

Member

Member

86 points

25 Posts

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

 

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

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.

MichaelGG
MichaelGG

Member

Member

86 points

25 Posts

Re: Bug? HorizontalAlignment not respected in Silverlight as in WPF

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

-Michael

melshall
melshall

Member

Member

4 points

2 Posts

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities