gpt4 book ai didi

c# - 即使内容高于容器,WPF 控件也会底部对齐

转载 作者:行者123 更新时间:2023-11-30 20:48:46 25 4
gpt4 key购买 nike

我有一个需要显示的控件,以便它始终与其容器的底部对齐,即使该控件比其容器高。我已经设置了控件的 VerticalAlignment="Bottom",当容器较大时效果很好,但当容器缩小时,控件的顶部与容器的顶部和底部对齐被切断。我需要切掉顶部。

<Window x:Class="NestedListBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
x:Name="Root"
Title="MainWindow" Height="185" Width="525">
<Grid>
<ItemsControl VerticalAlignment="Bottom">
<system:String>Test 1</system:String>
<system:String>Test 2</system:String>
<system:String>Test 3</system:String>
<system:String>Test 4</system:String>
<system:String>Test 5</system:String>
<system:String>Test 6</system:String>
<system:String>Test 7</system:String>
<system:String>Test 8</system:String>
<system:String>Test 9</system:String>
<system:String>Test 10</system:String>
<system:String>Test 1</system:String>
<system:String>Test 2</system:String>
<system:String>Test 3</system:String>
<system:String>Test 4</system:String>
<system:String>Test 5</system:String>
<system:String>Test 6</system:String>
<system:String>Test 7</system:String>
<system:String>Test 8</system:String>
<system:String>Test 9</system:String>
<system:String>Test 10</system:String>
</ItemsControl>
</Grid>
</Window>

当您将窗口拖动到大于 ItemsControl 时,它会保持与底部对齐,但一旦窗口变小,顶部就会对齐。

代替 Grid,我还尝试将 DockPanel 设置为 ItemsControl DockPanel.Dock="Bottom",但这也不起作用。

最佳答案

您可以使用 Canvas 来达到您的预期效果

请注意,VerticalAlignment 已从 ItemsControl 中删除,并且 Canvas.Bottom 设置为 0 以使其固定在 Canvas 的底部。

<Grid>
<Canvas>
<ItemsControl Canvas.Bottom="0">
<system:String>Test 1</system:String>
<system:String>Test 2</system:String>
<system:String>Test 3</system:String>
<system:String>Test 4</system:String>
<system:String>Test 5</system:String>
<system:String>Test 6</system:String>
<system:String>Test 7</system:String>
<system:String>Test 8</system:String>
<system:String>Test 9</system:String>
<system:String>Test 10</system:String>
<system:String>Test 1</system:String>
<system:String>Test 2</system:String>
<system:String>Test 3</system:String>
<system:String>Test 4</system:String>
<system:String>Test 5</system:String>
<system:String>Test 6</system:String>
<system:String>Test 7</system:String>
<system:String>Test 8</system:String>
<system:String>Test 9</system:String>
<system:String>Test 10</system:String>
</ItemsControl>
</Canvas>
</Grid>

关于c# - 即使内容高于容器,WPF 控件也会底部对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24216342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com