WrapPanel不会重绘最大化

时间:2014-07-12 16:35:32

标签: c# .net wpf wpf-4.5

我在ListView(itemspanel模板)中使用了wrappanel(WPF 4.5)。 当我调整窗口大小时,wrappanel会正确地重绘。

当我最大化它时,它不会重绘自己。

以下是代码(XAML)

 <ListView ItemsSource="{Binding Items}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Margin="3" Width="200" Height="200">
                        <TextBlock Text="{Binding}"></TextBlock>
                        <Image Source="{Binding}"></Image>
                    </StackPanel>
                </DataTemplate>

            </ListView.ItemTemplate>
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel HorizontalAlignment="Left" VerticalAlignment="Top" Width="{Binding Path=Width, RelativeSource={RelativeSource  AncestorType=Window}}" ></WrapPanel>   
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>    
        </ListView>

以下是截图 普通
enter image description here

调整大小(外翻可以) enter image description here

最大化(问题,看看红色曲线点,listview / wrappanel应该重绘并用随后的样本图像填充) enter image description here

1 个答案:

答案 0 :(得分:2)

问题是您已将Wrap面板的 Width 绑定到窗口宽度,该窗口的宽度始终保持为您在XAML中指定的值。

使用ActualWidth替换宽度 ,它始终使用当前窗口宽度更新。

<WrapPanel HorizontalAlignment="Left" VerticalAlignment="Top" 
           Width="{Binding Path=ActualWidth,
                   RelativeSource={RelativeSource  AncestorType=Window}}"/>
相关问题