0
如何检查窗口(主窗口)中有多少行ListView适合窗口大小。 我假设窗口是最大化的,只有系统设置决定了窗口的大小。 ListView通过选项FillLastChild停靠在DockPanel中。调整WPF控件大小以适应窗口大小
WPF是否提供了自动执行此操作的机制?
问候。
这是我的WPF。我想知道“lstBox”中有多少项适合使用“后退”和“下一步”按钮控制分页。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate x:Key="ListBoxTemplate">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Path=Name}" TextWrapping="Wrap" />
<TextBlock Grid.Column="1" Text="{Binding Path=Value}" TextWrapping="Wrap" />
</Grid>
</DataTemplate>
</Window.Resources>
<DockPanel x:Name="MainPanel" LastChildFill="True">
<Grid DockPanel.Dock="Bottom">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="15*"/>
<ColumnDefinition Width="75*"/>
<ColumnDefinition Width="15*"/>
</Grid.ColumnDefinitions>
<Button x:Name="btnNext" Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" Height="23" Content="Next" HorizontalAlignment="Right" Margin="0,6,0,0" Width="40" />
<Button x:Name="btnBack" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="23" Content="Back" Margin="0,6,0,0" />
</Grid>
<ItemsControl x:Name="lstBox" ItemsSource="{Binding}" ItemTemplate="{DynamicResource ListBoxTemplate}" BorderBrush="#FF000000"
BorderThickness="1,1,1,1" VerticalAlignment="Stretch" />
</DockPanel>
</Window>
您是否试图动态调整控件的高度和/或宽度?你把它放在一个网格内,并将高度调整为自动? – leigero
向我们展示您的XAML。构建一个可以尽可能少地展示您的问题的示例。 – Lorek
XAML可以在上面查看 – iljon