2016-10-04 70 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>