My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
XAML CODE EXAMPLE created on Saturday, February 06, 2010 permalink
How to stop a XAML button from expanding to the size of its parent width
A trick to get a XAML button to expand only to the size of its text content is to wrap it with a StackPanel that has a HorizontalAlignment="Left".
Button expands to fill width:
    <DockPanel Style="{DynamicResource BasePageItemDockPanelStyle}">
        <Border
            DockPanel.Dock="Top">
            <StackPanel
                HorizontalAlignment="Left"
                VerticalAlignment="Top">
                <TextBlock Text="{Binding PageTitle}" Style="{DynamicResource PageTitleStyle}"/>
                <TextBlock Text="{Binding PageDescription}" Style="{DynamicResource PageDescriptionStyle}"/>
                <Button Content="Upload File" Click="Button_Click"/>
            </StackPanel>
        </Border>
    </DockPanel>

Button exands only to width of text:
    <DockPanel Style="{DynamicResource BasePageItemDockPanelStyle}">
        <Border
            DockPanel.Dock="Top">
            <StackPanel
                HorizontalAlignment="Left"
                VerticalAlignment="Top">
                <TextBlock Text="{Binding PageTitle}" Style="{DynamicResource PageTitleStyle}"/>
                <TextBlock Text="{Binding PageDescription}" Style="{DynamicResource PageDescriptionStyle}"/>
                <StackPanel HorizontalAlignment="Left">
                    <Button Content="Upload File" Click="Button_Click"/>
                </StackPanel>
            </StackPanel>
        </Border>
    </DockPanel>
need markup?