【发布时间】:2011-10-03 02:44:05
【问题描述】:
我希望根据数据上下文的属性折叠某些 ListBoxItem。
我想出了以下内容(为简洁起见)
<ListBox ItemsSource="{Binding SourceColumns}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDeleted}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock VerticalAlignment="Center" Margin="5,0" Text="{Binding ColumnName}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这个“有效”是因为它确实折叠了标记为“IsDeleted”的列表框项,但是垂直滚动条不会针对“缺失”项进行调整。当我滚动时,栏突然变得越来越大(没有移动),直到我滚动到隐藏项目的点,然后终于开始移动。
我还尝试在数据触发器中将高度和宽度显式设置为 0,但无济于事。
有人知道是否有解决方法吗?
【问题讨论】:
标签: wpf scrollbar visibility listboxitem