WPF - 隐藏列表框项目 [英] WPF - hiding listbox items

查看:21
本文介绍了WPF - 隐藏列表框项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框,其中 itemtemplate 使用了一种样式.样式使用数据触发器指定边框,根据属性将边框的可见性设置为折叠.这工作正常,除了我仍然可以看到列表中每个项目的折叠线非常窄.我希望有人可以帮助如何设置可见性,以便没有可见的痕迹,因为这在连续项目折叠时非常明显.

I have a listbox where the itemtemplate is using a style. The styles specifies a border with a datatrigger setting the visibility of the border to collapsed depending on a property. This works fine except I can still see a very narrow line for each item, in the list, that is collapsed. I was hoping someone could help with how to set the visibility so that there are no visible traces as this is quite apparent when consecutive items have been collapsed.

数据模板指定了一个外部边框,其中有一个停靠面板 - 然后堆栈面板停靠在此.

The datatemplate specifies an outer border with a dockpanel inside of this - there are then stackpanels docked to this.

感谢任何帮助.

这是一个简化的模板:

<DataTemplate x:Key="myTemplate">
    <Border BorderThickness="0">
        <Border.Style>
            <Style>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=IsActive}" Value="False">
                        <Setter Property="Border.Visibility" Value="Collapsed" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Border.Style>
        <DockPanel LastChildFill="True" HorizontalAlignment="Stretch">
            <StackPanel DockPanel.Dock="Right" HorizontalAlignment="Right"  >
                <TextBlock Text="{Binding Path=SeqNo, Converter={StaticResource SeqToTextConv}}"/>
                <Label Content="..." />
            </StackPanel>
        </DockPanel>
    </Border>
</DataTemplate>

推荐答案

您已成功隐藏您的项目,但是,ListBox 将您的每个项目包装在一个 ListBoxItem 中,这为您的项目添加了诸如选择之类的概念.我怀疑在您的项目被隐藏的情况下,您仍然会看到 ListBoxItem.您可以使用 ItemContainerStyle 来隐藏 ListBoxItems ...

You are succesfully hiding your item, however, the ListBox wraps each of your items within a ListBoxItem, this adds concepts such as selection to your item. I suspect you are still seeing the ListBoxItem in the case where your items are hidden. You can use the ItemContainerStyle to hide ListBoxItems ...

<ListBox>
  <ListBox.ItemContainerStyle>
    <Style TargetType="{x:Type ListBoxItem}">
      <Style.Triggers>
        <DataTrigger Binding="{Binding IsActive}" Value="False">
          <Setter Property="Visibility" Value="Collapsed"/>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </ListBox.ItemContainerStyle>
</ListBox>

这篇关于WPF - 隐藏列表框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆