ListView
フィールドのリストを表示するために使用される in wpf があります。プロパティ値に基づいて、一部のフィールドを実行時に折りたたむことができます。実行時に折りたたまれた ListViewItem 用に予約されたスペースを ListViewew が折りたたまないことを除いて、正常に動作します。
Snoop で追加の ListViewItems を確認できます (Visibility は Collapsed です)。ListView もアイテムを上に移動しますが、高さを調整して空のスペースを削除しません!
VirtualizedStackPanel
ItemsPanel を StackPanel に変更すると問題が解決するため、これが発生していると確信できます。関連するListView
XAML は次のとおりです。
<ListView
x:Class="Wizards.FieldBinderModelListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Margin="0"
VerticalAlignment="Top"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Top"
Background="White"
BorderThickness="0"
Grid.IsSharedSizeScope="True"
KeyboardNavigation.DirectionalNavigation="Continue"
Padding="1"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectionChanged="ListViewSelectionChanged"
SelectionMode="Single">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<!--Works fine with StackPanel but not with VirtualizingStackPanel
Explicitly added this PanelTemplate to show that it works with
StackPanel;ListView uses VirtualizingStackPanel as default panel
and causes same problem-->
<!--<StackPanel Orientation="Vertical" VerticalAlignment="Top"/>-->
<VirtualizingStackPanel Orientation="Vertical"
VerticalAlignment="Top"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Black" />
</Trigger>
<DataTrigger Binding="{Binding Status}"
Value="{x:Static local:Status.NotExisting}">
<!--Hide the fields which are in NotExisting state;
Need a trigger here as Status can be different -->
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate DataType="{x:Type View:FieldViewModel}">
<local:FieldEditor
Margin="0,2,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Top"
Padding="0">
<!--<local:FieldEditor.Style>
<Style TargetType="{x:Type local:FieldEditor}">
<Style.Triggers>
<DataTrigger
Binding="{Binding Status}"
Value="{x:Static local:Status.NotExisting}">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</local:FieldEditor.Style>-->
</local:FieldEditor>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
これは のバグVirtualizingStackPanel
ですか? 他の誰かが同様の問題に直面しましたか? 回避策はありますか?
アップデート:
接続時にこのバグを MS に報告しました - https://connect.microsoft.com/VisualStudio/feedback/details/734113/virtualizingstackpanel-not-handling-collapsed-items-correctly