방법: ListBoxItem 가져오기
ListBox의 특정 인덱스에서 특정 ListBoxItem을 가져와야 하는 경우 ItemContainerGenerator를 사용할 수 있습니다.
예제
다음 예제에서는 ListBox 및 해당 항목을 보여 줍니다.
<ListBox Margin="10,0,0,5" Name="lb" VerticalAlignment="Top" Grid.Column="0" Grid.Row="2">
<ListBoxItem>Item 0</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 2</ListBoxItem>
<ListBoxItem>Item 3</ListBoxItem>
</ListBox>
다음 예제에서는 ItemContainerGenerator의 ContainerFromIndex 속성에서 항목의 인덱스를 지정하여 항목을 검색하는 방법을 보여 줍니다.
private void GetIndex0(object sender, RoutedEventArgs e)
{
ListBoxItem lbi = (ListBoxItem)
(lb.ItemContainerGenerator.ContainerFromIndex(0));
Item.Content = "The contents of the item at index 0 are: " +
(lbi.Content.ToString()) + ".";
}
Private Sub GetIndex0(ByVal Sender As Object, ByVal e As RoutedEventArgs)
Dim lbi As ListBoxItem = CType( _
lb.ItemContainerGenerator.ContainerFromIndex(0), ListBoxItem)
Item.Content = "The contents of the item at index 0 are: " + _
(lbi.Content.ToString()) + "."
End Sub
목록 상자 항목을 검색한 후 다음 예제와 같이 항목의 콘텐츠를 표시할 수 있습니다.
Item.Content = "The contents of the item at index 0 are: " +
(lbi.Content.ToString()) + ".";
Item.Content = "The contents of the item at index 0 are: " + _
(lbi.Content.ToString()) + "."
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET Desktop feedback
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기