Home > DeveloperSection > Forums > WPF Button with multiple text elements
Ashish Pandey

Total Post:128

Posted on    September-04-2013 1:47 AM


 1 Reply(s)
 1171  View(s)
Rate this:

I am trying to create buttons for a 10-foot GUI using WPF. Each button requires a little more data than just a single text string and an image, maybe 2-3 strings located in different positions and some imagery.

I have tried

 <Button Height="52" HorizontalAlignment="Stretch" Name="button1"  Width="407">


        <DockPanel LastChildFill="True" HorizontalAlignment="Stretch">

            <TextBlock Name="textBloczk2" Text="ABC" TextAlignment="Left"   DockPanel.Dock="Left"/>

            <TextBlock Name="textBlxock1" Text="CDE" TextAlignment="Right" DockPanel.Dock="Right"/>




But no matter which inner container I use, the button seems to disregard the layout from the DockPanel and the combined text ends up in the middle of the button. Am I doing something wrong or should I be using a different outer container ?

Sumit Kesarwani

Total Post:378

Posted on    September-04-2013 6:54 AM

Hi Ashish,

The problem seems to be that the DockPanel's width is so small that the Right and Left panels are the same width as your TextBlocks.

This seems to work as expected (setting the width of the DockPanel):

    <Button Height="52" HorizontalAlignment="Stretch" Name="button1"  Width="407">


            <DockPanel LastChildFill="True" Width="300">

                <TextBlock Name="textBloczk1" Text="Left" DockPanel.Dock="Left" />

                <TextBlock Name="textBlxock2" Text="Right" DockPanel.Dock="Right" />

                <TextBlock Name="textBlxock3" Text="Top" DockPanel.Dock="Top" />

                <TextBlock Name="textBlxock4" Text="Bottom" DockPanel.Dock="Bottom" />




Don't want to miss updates? Please click the below button!

Follow MindStick