这是XAML.两个问题.当窗口打开时,两个按钮都在底部被切断,"Save_Search"按钮在右侧被切断.第二个问题是,当我调整窗口大小时,列表视图会像我预期的那样变长,但按钮都会在列表视图的中间结束,而不是相对于窗口边框移动.我搜索的时间并不多.
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>
Run Code Online (Sandbox Code Playgroud)
默认情况下HorizontalAlignment,VerticalAlignment它们都设置为根据给定的边距拉伸控件.这会导致您的情况不正确,因为尽管调整了网格大小,但控件仍绑定到边距中指定的位置.
为了解决这个问题,设置HorizontalAlignment到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>
Run Code Online (Sandbox Code Playgroud)