2016-10-04 28 views
0

我想将两个标签放在一行中,第一行对齐左边框,右边第二行。文本在一行中的左右对齐

喜欢这里:

enter image description here

这是我的XAML尝试:

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

而是我得到这个:

enter image description here

  1. 我在做什么DockPanel错了?
  2. 我该如何实现第一张图片的设计(不一定要用DockPanel)?

回答

2

您正确使用了dockpanel,但您需要将标签内容对齐到右侧。试试这个

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