XAML windows wpf内标签的垂直对齐

zc0qhyus  于 2022-12-16  发布在  Windows
关注(0)|答案(1)|浏览(157)

我希望标签中的文本底部对齐。该标签位于视图框内。我尝试将标签上的VerticalAlignement和VerticalContentAlignement设置为底部对齐,但似乎不起作用。我还尝试将标签上的宽度和高度设置为底部对齐,但没有任何内容符合我的需要。
下面是带有视图框的xaml。

<Viewbox x:Name="vbCodeOnline" Grid.Column="0" HorizontalAlignment="Right" >
    <Label d:Content="Test" x:Name="lblCodeOnline" Content="{Binding CodeOnline}" Foreground="{Binding CouleurAffichage, Converter={StaticResource ColorToBrushConverter}}" FontSize="36" MouseDown="lblCodeOnline_MouseDown" MouseEnter="lblCodeOnline_MouseEnter" MouseLeave="lblCodeOnline_MouseLeave" Cursor="Help"/>
</Viewbox>

下面是完整的用户控件xaml:

<UserControl x:Class="QuizzDllWpf.UserControl.OnlineView"
             x:Name="MyUserControl"
             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"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:converters="clr-namespace:QuizzDllWpf.Converters"
             mc:Ignorable="d" d:DesignHeight="40" d:DesignWidth="140"
             SizeChanged="OnlineView_SizeChanged"
             DataContext="{Binding RelativeSource={RelativeSource Self}}"
             HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch">

    <UserControl.Resources>
        <telerik:ColorToBrushConverter x:Key="ColorToBrushConverter"/>
        <telerik:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <converters:BooleanHoverToCursorConverter x:Key="BooleanHoverToCursorConverter" />
        <converters:TraductionConverter x:Key="TraductionConverter" />
        <converters:CoefValueConverter x:Key="CoefValueConverter" />
        <!--Images SVG-->
        <PathGeometry x:Key="ImageSVGOnlineInactif" Figures="M55.08 96.53H15.22a3.86 3.86 0 0 0-3.73 4V170a3.86 3.86 0 0 0 3.73 4H55.08a3.87 3.87 0 0 0 3.74-4V100.5A3.87 3.87 0 0 0 55.08 96.53Zm-19.93 69a6 6 0 0 1 0-11.92 6 6 0 0 1 0 11.92Zm16.19-16.39H19V104.47H51.34Zm53.25-58.3V78.93a12.89 12.89 0 0 0-.5-4.3H46.16c-2.77 0-3.6.3-3.83.42 0 0-.07.37-.07 1.07v8.25H32.91V76.13c0-10.84 10-10.84 13.25-10.84h57a9.57 9.57 0 0 1 7.45 2.44c2.3 2.26 3.37 5.82 3.37 11.2v4.48A51.31 51.31 0 0 0 104.59 90.85Zm7.64 78.06c-1.74 2.7-5.19 5.07-11.93 5.07H67.19V168.9h0v-2.52a6.23 6.23 0 1 0 0-12.46v-6H94.41A51.28 51.28 0 0 0 112.23 168.91Zm77.67-55.42A50.66 50.66 0 0 0 180.55 95V50.49c0-8.72 0-15-1.17-17.27-.36-.69-1.29-1.43-7.79-1.43l-102-.49c-8.28 0-8.35 2.45-8.45 5.83L61 50.56l-9.35-.14.19-13.49c.29-10.1 6.12-15 17.83-15l102 .49c18.28 0 18.28 7.64 18.28 28.05ZM139.24 87.57A40.41 40.41 0 1 0 179.65 128 40.45 40.45 0 0 0 139.24 87.57Zm0 73.77a33.35 33.35 0 0 1-24.86-55.59L159 154.82A33.16 33.16 0 0 1 139.24 161.34ZM164.1 150.2l-44.64-49.07A33.34 33.34 0 0 1 164.1 150.2Z" FillRule="NonZero"/>
        <PathGeometry x:Key="ImageSVGOnlineActif" Figures="M54.65 98.26H14.8a3.85 3.85 0 0 0-3.73 4v69.3a3.85 3.85 0 0 0 3.73 4H54.65a3.85 3.85 0 0 0 3.73-4v-69.3A3.85 3.85 0 0 0 54.65 98.26ZM34.72 167.07a5.95 5.95 0 1 1 5.61-5.94A5.78 5.78 0 0 1 34.72 167.07Zm16.19-16.34H18.54V106.18H50.91Zm62.57-70v83.51c0 3.38-1.33 11.26-13.63 11.26H66.75v-5.06h0v-2.51a6.22 6.22 0 1 0 0-12.43v-6h37.39V80.71a12.65 12.65 0 0 0-.51-4.28c-.24 0-.55 0-.79 0H45.73c-2.76 0-3.6.3-3.83.42 0 0-.07.37-.07 1.06v8.23H32.49V77.92c0-10.8 10-10.8 13.24-10.8h56.94a9.64 9.64 0 0 1 7.44 2.44C112.41 71.81 113.48 75.35 113.48 80.71Zm57.65-56.32L69.19 23.91c-11.7 0-17.53 4.86-17.82 14.93l-.19 13.45 9.34.14L60.72 39c.09-3.37.16-5.81 8.44-5.81l102 .49c6.49 0 7.42.73 7.79 1.42 1.17 2.24 1.17 8.53 1.17 17.22V111H123.56v47.77l0 9.13a6.81 6.81 0 0 0 6.81 6.8h21.81a6.81 6.81 0 0 0 6.81-6.8v-9.32a6.8 6.8 0 0 0-6.81-6.8h-4.09V133.12h20.64c13.69 0 20.63-5.35 20.63-15.9V52.36C189.41 32 189.41 24.39 171.13 24.39Zm-1.19 103.22a5.83 5.83 0 1 1 5.84-5.82A5.84 5.84 0 0 1 169.94 127.61Z" FillRule="NonZero"/>

    </UserControl.Resources>

    <Grid x:Name="myGrid" ToolTip="{Binding ToolTipOnline}" HorizontalAlignment="Stretch" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <!--Affichage du code online-->
        <Viewbox x:Name="vbCodeOnline" Grid.Column="0" HorizontalAlignment="Right" >
            <Label d:Content="Test" x:Name="lblCodeOnline" Content="{Binding CodeOnline}" Foreground="{Binding CouleurAffichage, Converter={StaticResource ColorToBrushConverter}}" FontSize="36" MouseDown="lblCodeOnline_MouseDown" MouseEnter="lblCodeOnline_MouseEnter" MouseLeave="lblCodeOnline_MouseLeave" Cursor="Help"/>
        </Viewbox>

        <!--Affichage du bouton  Online -->
        <DockPanel x:Name="imageDockPanel" Width="{Binding ActualHeight, ElementName=MyUserControl, Converter={StaticResource CoefValueConverter}, ConverterParameter=1}" HorizontalAlignment="Right" Grid.Column="1" MouseDown="ImageDockPanel_MouseDown" Cursor="{Binding CursorHandOnline, Converter={StaticResource BooleanHoverToCursorConverter}}" Background="#01000000">
            <Viewbox x:Name="vbImageOnline" Stretch="Uniform">
                <!--Utilisation d'une image SVG (forme géométrique) dont on modifie la couleur de remplissage-->
                <Path Fill="{Binding CouleurAffichage, Converter={StaticResource ColorToBrushConverter}}" Data="{Binding DataImageSVGOnline}" />
            </Viewbox>
        </DockPanel>
    </Grid>
</UserControl>

以下是当前结果:

预期结果:

使用以下代码,它也不起作用

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="100" />
    <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<!--Affichage du code online-->
<Viewbox x:Name="vbCodeOnline" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Bottom"  >
    <Label d:Content="Test" x:Name="lblCodeOnline" Background="Yellow" VerticalContentAlignment="Bottom" Content="{Binding CodeOnline}" Foreground="{Binding CouleurAffichage, Converter={StaticResource ColorToBrushConverter}}" FontSize="36" MouseDown="lblCodeOnline_MouseDown" MouseEnter="lblCodeOnline_MouseEnter" MouseLeave="lblCodeOnline_MouseLeave" Cursor="Help"/>
</Viewbox>
a1o7rhls

a1o7rhls1#

在第一个<ColumnDefinition />中显式定义Width,并为ViewBox设置VerticalAlignment="Bottom"(设置其背景色仅用于调试,然后删除它)。您也可以为Label设置VerticalContentAlignment="Bottom"(也为它着色,仅用于调试)。

相关问题