CodeGo.net>如何访问ListBoxItems的可见性属性

在我的WPF程序中,我有一个ListBox控件:

<ListBox x:Name="mailsListBox" SelectionChanged="mailsListBox_SelectionChanged" >
    <ListBoxItem Content="..." Background="#FFF3F3F3" Margin="0,0,0,1" />
    <ListBoxItem Content="...." Margin="0,0,0,1" Visibility="Hidden"/>
</ListBox>

如何访问ListBoxItems的Visibility属性?我的代码不起作用:

mailsListBox.Items[1].Visibility = Visible;

解决方法:

像这样:

(mailsListBox.Items[1] as ListBoxItem).Visibility = Visibility.Visible;

或者您可以使用ItemContainerGenerator.ContainerFromItem方法:

((ListBoxItem)(mailsListBox.ItemContainerGenerator.ContainerFromItem(mailsListBox.Items[1]))).Visibility = Visibility.Visible;
上一篇:DevExpress_GridControl添加按钮列并添加按钮事件


下一篇:WinForm应用界面开发 - 什么是DevExpress WinForm打印控件?