gpt4 book ai didi

WPF - 当我调整窗口大小时按钮不移动

转载 作者:行者123 更新时间:2023-12-04 19:38:00 25 4
gpt4 key购买 nike

这是 XAML。两个问题。首先,当窗口打开时,底部的 2 个按钮都被切掉了,右侧的“Save_Search”按钮也被切掉了。第二个问题是,当我调整窗口大小时, ListView 会按照我的预期变长,但按钮都位于 ListView 的中间,而不是相对于窗口边框移动。当我搜索这个时,没有太多。

    Title="Queries" Height="274" Width="540">



<DockPanel Height="Auto" HorizontalAlignment="Stretch" Name="dockPanel1" VerticalAlignment="Stretch" Width="Auto">
<Grid Height="Auto" Width="Auto" Margin="0,0,0,0">

<TextBox Height="27" HorizontalAlignment="Left" Margin="256,6,0,0" Name="SearchTermsTextBox" VerticalAlignment="Top" Width="227"
Text="Enter search terms separated by `;`"/>

<ListView Name="ResultsListView" Margin="6,41,13,48" ItemsSource="{Binding}" Width="auto">
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock FontSize="15" FontWeight="Bold" Text="{Binding Name}"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>

<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Width" Value="Auto" />
<Setter Property="FontSize" Value="10.4" />
</Style>
</ListView.ItemContainerStyle>
</ListView>


<Button Content="Save Search" Margin="425,203,12.6,17.6" Name="Save_Search" Width="96" Height="25" />
<Button Name="Query_Button" Content="Ports" Margin="310,203,127.6,0" Height="25" Width="96" VerticalAlignment="Top"></Button>
</Grid>


</DockPanel>

最佳答案

默认情况下,Horizo​​ntalAlignmentVerticalAlignment 都设置为根据给定的边距拉伸(stretch)控件。这会导致您的情况出现错误行为,因为尽管调整了网格大小,控件仍绑定(bind)到边距中指定的位置。

为了修复它,将 Horizo​​ntalAlignment 设置为 Right 并将 VerticalAlignment 设置为 Bottom。这将使按钮粘在右边框和底边框上。

您还应该将边距值修改为左边距和上边距的值为 0,这样即使 Grid 大小小于 按钮也可以显示425、203。否则,可能只有部分按钮可见或没有按钮可见。

尝试对按钮使用以下代码:

<Button Content="Save Search" Margin="0,0,12.6,17.6"  Name="Save_Search"  Width="96" Height="25" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
<Button Name="Query_Button" Content="Ports" Margin="0,0,127.6,0" Height="25" Width="96" HorizontalAlignment="Right" VerticalAlignment="Bottom"></Button>

关于WPF - 当我调整窗口大小时按钮不移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12716413/

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