更改列表中垂直ListItem的可见性 [英] Change Visiblity of a Perticular ListItem in a List

查看:77
本文介绍了更改列表中垂直ListItem的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How do I Change Visiblity of a Perticular ListItem in a List?

像这样的东西;

myList.ListItems.ElementAt(4).Visible = false;

推荐答案

项目通常是由于绑定到集合而生成的.

The items are usually generated as the result of a binding to a collection.

您可以将IsVisible属性添加到绑定并创建ListItem的对象上,并使用VisibilityConverter通过IsVisible属性显示或隐藏它.

You can add an IsVisible property to the object that is bound and created the ListItem, and use a VisibilityConverter to show or hide it, passing through the IsVisible property.

<ListBox ...>
  <ListBox.ItemContainerStyle>
     <Style TargetType="{x:Type ListBoxItem}">       
        <Setter Property="Visibility" Value="{Binding IsVisibile, Converter={StaticResource VisibilityConverter}}" />
     </Style>
  </ListBox.ItemContainerStyle>
</ListBox>

首选方法是将其简单地从列表中过滤出来,将其从绑定的集合中排除(请参阅充当中间人的CollectionView).

The preferred method is to simply filter it out of your list, excluding it from the bound collection (see CollectionView which acts as a middle man).

在WPF中,我们很少询问UI控件本身,我们使用绑定到控件的数据.这是WPF,UI/数据分离的一大优势.因此,您可以重新设置应用程序的外观,而不必担心实际的代码 查询列表框中的数据.

In WPF, we very rarely interrogate UI controls themselves, we work with the data that is bound to the controls. This is a big advantage of WPF, UI/data separation. So you can reskin your application without having to worry about that code that physically interrogates the ListBox for data.

此致,
佩德罗(Pedro)

Regards,
Pedro


这篇关于更改列表中垂直ListItem的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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