두 항목이있는 TabControl이 있습니다.WPF SelectedIndex TabControl 설정 문제
<TabControl x:Name="tab" SelectionChanged="TabControl_SelectionChanged">
<TabItem Header="TabItem1">
<Grid />
</TabItem>
<TabItem Header="TabItem2">
<Grid />
</TabItem>
</TabControl>
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Debug.WriteLine("Selected Index: " + tab.SelectedIndex);
if (tab.SelectedIndex == 1)
{
tab.SelectedIndex = 0;
}
}
클릭하면 2 번 항목, 1 번 항목은 포커스가 있고 아래에 인쇄하십시오.
Selected Index: 1
Selected Index: 0
두 번째 항목을 클릭하면 다시 시도하지 않습니다! SelectionChanged 이벤트가 발생하지 않습니다.
무엇이 잘못 되었나요? 해결 방법이 있습니까?
도움 주셔서 감사합니다. 잘 작동한다. 하지만 아래 대화 상자가 있으면 작동하지 않습니다. if (tab.SelectedIndex == 1) { MessageBox.Show ("Hello"); ... } 무엇이 잘못 되었나요? – tree1891
MessageBox를 UI 발송자에 배치 했습니까 ?? –
예, 있습니다. 잘 작동한다. 이지만 탭 항목이 변경되었습니다. – tree1891