0

I have many TabItem in my TabControl. I'm binding my TabControl with SelectedIndex property :

<TabControl SelectedIndex="{Binding SelectedIndex}">
    <TabItem Header="TabItem1">
        ...
    </TabItem>
    ...
</TabControl>

I want to come back on first TabItem when I select the third TabItem. So I'm trying to change the setter of property :

private int _selectedIndex;
public int SelectedIndex
{
    get { return _selectedIndex; }

    set
    {
        if (value == 2)
            value = 0;

        Set(ref _selectedIndex, value);
    }
}

But the TabItem remains on the third TabItem.

Speed Neo
  • 57
  • 6

1 Answers1

2

I can honestly say I don't know why this works. But adding "IsAsync=True" fixed this for me.

I guess it could be that the binding is taking too long. As this MSDN article suggests https://msdn.microsoft.com/en-us/library/system.windows.data.binding.isasync(v=vs.110).aspx

<TabControl SelectedIndex="{Binding SelectedIndex, IsAsync=True}">
Marsh
  • 188
  • 2
  • 10