저녁 결국라고, 나는 인 selectionchanged (을 TabControl)를 LostFocus (텍스트 상자) 이벤트 이전 이벤트 인 호출에 문제로 실행했습니다.이벤트 우선 순위 : LostFocus이를 SelectionChange
TabChanged가 Tab 변경 중에 트리거되었으므로 해당 인턴이 ListView.SelectedIndex (TabControl> TabItem> ListView)을 -1로 재설정하기 때문에 문제가 발생합니다.
텍스트 상자는 LostFocus를 사용하여 SelectedIndex에 의존하는 textbox.text를 업데이트/유효성을 검사합니다. 텍스트 상자의 텍스트는 List<string>
에서 저장/검색되며 인덱스가 변경 되었기 때문에 List가 범위를 벗어납니다.
나는 주변을 둘러 보았고, 실제로 도움이되지 않은 "해킹 - y"접근법에 몇 가지 피곤했다.
<TabControl SelectionChanged="SelectionChanged_Tab"
<TabItem .../>
<TabItem .../>
</TabControl>
<Grid>
<Label .../>
<TextBox Name="Name" LostFocus="Lost_Focus" .../>
</Grid>
코드 :
private void SelectionChanged_Tab(object sender, SelectionChangedEventArgs e)
{
if (e.Source is TabControl)
{
ListView1.SelectedIndex = -1;
ListView2.SelectedIndex = -1;
}
}
private void Lost_Focus(object sender, RoutedEventArgs e)
{
TextBox textbox = sender as TextBox;
int Index = ListView.SelectedIndex;
if (string.IsNullOrEmpty(textbox.Text) || textbox.Text == "0")
{
textbox.Text = "0";
}
switch (textbox.Name)
{
case "Name":
SomeList[Index].AProperty = textbox.Text;
break;
}
}