我有一个控件,它是一个网格,其中第一行包含一些按钮,具有固定的高度,第二行(也是最后一行)包含一个 ListView。然后我有一个主屏幕,它只包含一个菜单和上面的这个用户控件。我想将 ListView 的大小作为窗口的最大值,这意味着如果窗口最大化,ListView 会很大,以防窗口变小,ListView 也会变大(垂直滚动以帮助导航项目)。
这就是我的做法: 窗口:
<Window x:Class="TestUI.MainView"
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"
mc:Ignorable="d"
Width="auto" Height="auto"
MinHeight="300" MinWidth="300"
Title="Test"
DataContext="{Binding MainViewModel, Source={StaticResource Locator}}" >
<StackPanel Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<DockPanel>
<Menu DockPanel.Dock="Top" >
<MenuItem Header="Item 1" Command="{Binding Command1}"/>
<MenuItem Header="Item 2" Command="{Binding Command2}"/>
<MenuItem Header="Item 3" Command="{Binding Command3}"/>
</Menu>
</DockPanel>
<DockPanel LastChildFill="True">
<ScrollViewer Content="{Binding Content}" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled" DockPanel.Dock="Bottom" />
</DockPanel>
</StackPanel>
</Window>
用户控制:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="5, 5, 5, 5" Orientation="Horizontal">
<Button Content="New" Width="60" Command="{Binding NewCommand}"/>
<Button Content="Remove" Width="60" Margin="10, 0, 0, 0" Command="{Binding RemoveCommand}" />
</StackPanel>
<DockPanel Grid.Row="1" Margin="5,5,5,5" LastChildFill="True" HorizontalAlignment="Stretch">
<ListView x:Name="ListView" SelectionMode="Single" DockPanel.Dock="Top" ItemsSource="{Binding Entities}" SelectedItem="{Binding SelectedEntity}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" VerticalAlignment="Stretch">
<ListView.View>
<GridView>
<GridViewColumn Width="auto" Header="Product" DisplayMemberBinding="{Binding Description}"/>
</GridView>
</ListView.View>
</ListView>
</DockPanel>
</Grid>
请你帮助我好吗?
谢谢!