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

查看:103
本文介绍了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天全站免登陆