내 Windows Phone 8 App에는 다음과 같은 Listbox 요소가 있습니다. AppBar에서 multiselect 아이콘을 누르면 DataTemplate에 체크 박스를 표시하려고합니다. 사용자는 항목에 대해 다중 선택을 할 수 있습니다.ListBox.ItemContainerGenerator.ContainerFromIndex Returns null
나는이 목록 상자에 바인딩 된 50 개의 요소를 가지고 있으며 항상 인덱스 11에 있습니다. ItemContainerGenerator.ContainerFromIndex은 나머지 목록에서 null을 비롯하여 일부 항목을 반환합니다. 따라서 50 개 중 10 개의 항목이 null로 반환됩니다.
Dispatcher.BeginInvoke 또는 UpdateLayout, ScrollIntoView를 적용하는 것과 같은 몇 가지 대답이 있지만 그 중 아무 것도 작동하지 않습니다.
반면에 목록을 스크롤 한 다음 AppBar 아이콘을 누르면 제대로 작동합니다. 그러나 사용자는 데이터 바운드 직후에 바로 아이콘을 누를 수 있으며 일부 체크 박스는 표시되지 않습니다.
Windows Phone 8에서이 문제를 해결할 수있는 방법이 있습니까? 직접적 그래서 ItemsSource 경우 ItemsSource
관련이 객체를 필요로 할 때
<ListBox Name="ResultListBox" ItemsSource="{Binding}"
SelectionChanged="ResultListBox_OnSelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,10" Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<CheckBox Name="CheckBox" Visibility="Collapsed">
</CheckBox>
<Image Source="{Binding url}"
Width="125"
Height="125"
VerticalAlignment="Top"
Margin="0,0,5,0"></Image>
</StackPanel>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding title}"
VerticalAlignment="Top"
FontFamily="Portable User Interface"></TextBlock>
</StackPanel>
<StackPanel>
<TextBlock Text="{Binding description}"
FontFamily="Portable User Interface"></TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
void appBarButtonSelect_Click(object sender, EventArgs e)
{
//Dispatcher.BeginInvoke(delegate
//{
//});
for (int i = 0; i < ResultListBox.Items.Count; i++)
{
//ResultListBox.UpdateLayout();
//ResultListBox.ScrollIntoView(i);
DependencyObject item = ResultListBox.ItemContainerGenerator.ContainerFromIndex(i);
if (item != null)
{
CheckBox checkBox = FindFirstElementInVisualTree<CheckBox>(item);
if (checkBox != null)
{
checkBox.Visibility = Visibility.Visible;
}
}
else
{
Debugger.Break();
}
}
}
문제가 발생합니다. 색인에서 사용하려는 항목이 아직 생성되지 않았기 때문에 가상화와 관련이 있다고 생각합니다. 귀하의 목록 상자 가상화가 활성화되어 있는지 확인하십시오 –
생성됩니다. 확실한. 대부분이 보여주기 때문입니다. 일부 특정 색인이 표시됩니다. 모든 요소를 반복 할 수 있지만 해당 함수 (ItemContainerGenerator.ContainerFromIndex)는 (11, 32, 45 등의 특정 배열에 대한 요소를 가져 오지 않습니다.) –