WPF Button with 2 textblock or label inside with different alignment

Lukino2000
Lukino2000 used Ask the Experts™
on
Hi,

is it possible create a button with 2 label or textblock with different alignment?

i tried with stackpanel, dockpanel

in attach the wanted layout

the best is using xaml
button.jpg
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You would probably get the result you are after using a grid control within the button. Then set the grid columns and horizontal alignment to get this layout.

Here is an example to help you get started:
<Button Name="B1" Width="200" Height="40" >
            <Grid Width="{Binding ElementName=B1, Path=ActualWidth}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0">Piatto</Label>
                <Label Grid.Column="1" HorizontalAlignment="Right">£23.00</Label>
            </Grid>
</Button>

Open in new window

Jaime OlivaresSoftware Architect
Top Expert 2008

Commented:
I would use a DockPanel, I don't know why it is not working for you, maybe you missed something:

<Button  Width="200" Height="40" >
            <DockPanel LastChildFill="True">
                <TextBlock DockPanel.Dock="Right" TextlAlignment="Right"> 23.00</TextBlock>
                <TextBlock>Piatto</TextBlock>
            </DockPanel>
</Button>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial