簡體   English   中英

WPF label 橫向內容 alignment 與柔性寬度

[英]WPF label horizontal content alignment with flexibel width

我有一個TabControl和一些TabItems

TabItems的 Header 由一個UserControl和一個label和一個button組成。 為此,我遵循了本教程

label 的水平label不起作用,因為寬度設置為自動。 這會導致文本居中,並且buttons不會一直位於它們應位於的右側。

但我需要寬度靈活,以免長文本被截斷。

這是寬度設置為自動,這是固定寬度。

在此處輸入圖像描述 在此處輸入圖像描述

我希望它看起來像具有固定寬度但具有靈活寬度的圖片,具體取決於標簽的長度。

編輯:我不使用評論中提出的建議中的主題。

這是我的 XAML 代碼:

<UserControl
    x:Class="CSM.UserControls.CloseableHeaderUserControl"
             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" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignWidth="81" Margin="0" Height="20.5" >
    <Grid Margin="0,4,0,0">
        <Button Content="X" Name="bClose" FontFamily="Courier" FontWeight="Bold" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" FontStretch="Normal" FontSize="14"  ToolTip="Close" Height="20" Width="20" HorizontalAlignment="Right" Margin="0,-4,0,0"/>
        <Label Content="TabItem" Name="lTabTitle" FontFamily="Courier" FontSize="12" HorizontalAlignment="Left" HorizontalContentAlignment="Left" Width="auto" Height="24" VerticalAlignment="Top" Margin="0,-4"  />
    </Grid>
</UserControl>

將 DockPanel 與 LastChildFill 一起使用:

<DockPanel LastChildFill="True">
  <Button DockPanel.Dock="Right" ... />
  <Label DockPanel.Dock="Left" ... />      
</DockPanel>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM