forum

Home / DeveloperSection / Forums / WPF SelectedIndex set issue of TabControl in WPF

WPF SelectedIndex set issue of TabControl in WPF

Andrew Deniel 5076 18-Jul-2013
Hi experts!

I have a TabControl with two items.

<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;

    }

}

when click 2nd item, 1st item have focus and print below.

Selected Index: 1

Selected Index: 0

but retry clicking 2nd item, no output! SelectionChanged event do not fire.

what's wrong? Is there work around?

thanks in advance 


wpf wpf 
Updated on 18-Jul-2013

Can you answer this question?


Answer

1 Answers

Liked By