Kjara
Kjara

Reputation: 2912

Left and right alignment of text in one row

I want to put two labels in one row, the first being aligned to the left border, the second to the right.

Like here:

enter image description here

Here is my XAML try:

<Window x:Class="MyTestNamespace.MyXAML"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <DockPanel>
        <Label Content="left text" DockPanel.Dock="Left"></Label>
        <Label Content="right text" DockPanel.Dock="Right"></Label>
    </DockPanel>
</Window>

But instead I get this:

enter image description here

  1. What I am doing wrong with the DockPanel?
  2. How can I achieve the design of the first picture (not necessarily with DockPanel)?

Upvotes: 0

Views: 1494

Answers (1)

Ayyappan Subramanian
Ayyappan Subramanian

Reputation: 5366

You used the dockpanel correct but you need align the the label content to right. Try this

<DockPanel>
        <Label Content="left text" DockPanel.Dock="Left"></Label>
        <Label Content="right text" DockPanel.Dock="Right" HorizontalContentAlignment="Right"></Label>
    </DockPanel>

Upvotes: 2

Related Questions