【问题标题】:Left and right alignment of text in one row一行中的文本左右对齐
【发布时间】:2023-03-15 06:30:01
【问题描述】:

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

喜欢这里:

这是我的 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>

但是我得到了这个:

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

【问题讨论】:

    标签: wpf xaml alignment dockpanel


    【解决方案1】:

    您正确使用了停靠面板,但您需要将标签内容向右对齐。试试这个

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      • 2023-03-31
      • 2015-04-24
      • 1970-01-01
      • 1970-01-01
      • 2014-01-02
      相关资源
      最近更新 更多