如何访问ListBoxItems的Visibility属性

时间:2015-11-05 19:22:46

标签: c# wpf xaml listboxitem

在我的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>

如何访问Visibility的{​​{1}}属性?我的代码不起作用:

ListBoxItems

1 个答案:

答案 0 :(得分:3)

像这样:

==

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

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