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

Total Post:128

Points:898
Posted on    September-04-2013 1:47 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 822  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">

        <Button.Content>

        <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"/>

        </DockPanel>

        </Button.Content>

    </Button>

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

Points:2694
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">

        <Button.Content>

            <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" />

            </DockPanel>

        </Button.Content>

    </Button>


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

Follow MindStick