我把一个ListView放在视图的中间一行。该视图包含在SizeToContent设置为WidthAndHeight的窗口中。 ListView最初是空的,但底层的ViewModel在这个过程中填充了这个列表视图。如何防止ListView扩大窗口尺寸?
中间Grid.Row高度设置为*以填充窗口的可用大小。当ListView接收到新项目时,它会在某个时候扩大窗口大小,而不是在ListView中显示ScrollViewer。我怎样才能防止这种行为有SizeToContent设置为WidthAndHeight,Grid.Row高度*,但没有ListView展开窗口尺寸?
下面是窗口(工作空间属性将包含视图模型)的代码:
<Window x:Class="Views.ContainerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding Title}"
SizeToContent="WidthAndHeight">
<ContentControl Content="{Binding Workspace}"/>
</Window>
为提供视图模型的视图看起来是这样的:
<UserControl x:Class="Views.SomeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
MinHeight="450">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
TextWrapping="Wrap"
Margin="5"
Text="Some description text"/>
<ListView Grid.Row="1"
ItemsSource="{Binding ItemsList}"
Margin="5">
<ListView.View>
<GridView>
...
</GridView>
</ListView.View>
</ListView>
<Button Grid.Row="2"
HorizontalAlignment="Right"
Command" Value="{Binding CloseCommand}"/>
</Grid>
</UserControl>
谢谢。这实际上是我使用的解决方案。你可以看到,如果你扩展上面的评论。 :) – 2010-10-08 13:34:15
@Ninfendo:+1这是邪恶的,谢谢。我浪费了一个下午试图弄清楚。 – TarkaDaal 2013-02-07 18:13:53