Style setting for the first and last visible TabItem TabControl

I want to set the style for the first and last TabItems in TabControl and update them when the visibility of TabItems changes. I see no way to do this with triggers.

What we do is as follows:

| >>> |

And the visibility of TabItems is determined by the binding.

I have it working in code. When changing the visibility of a TabItem, list through TabItems until you find the first visible one. Set the style on this. For all other visible TabItems, set them to a pointy style (so that the previous first visible is now pointy). Then start from the end until you find the visible TabItem and set the last style on it. (This also allows us to solve the problem with TabControl, where the contents of the invisible TabItem will be displayed if none of the visible TabItems is selected.)

Without a doubt, I could improve my methods, but I'm not sure if this is the right approach.

How do you approach this?

+5
source share
3 answers

, , :

, - , , ?

, TabItems ( wpf) IsVisibleChanged TabItems, (.. ?)

    public Window1()
    {
        InitializeComponent();

        this.myTabItem.IsVisibleChanged += new DependencyPropertyChangedEventHandler(myTabItem_IsVisibleChanged);
    }

    private void myTabItem_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        myTabControl.Items[0].Style = FindResource("MyTabItemStyle") as Style;
    }

, ...:)

+1

, TabItems , TabControl, TabControl.

private void Breadcrumb_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
        if ((bool)e.NewValue)
        {
            if (sender is TabControl)
            {
                TabControl tabControl = (TabControl)sender;
                int firstVisible = -1;

                for (int i = 0; i  -1) //if is -1, they're all invisible
                    {

                        for (int i = tabControl.Items.Count - 1; i > firstVisible; i--)
                        {
                            TabItem tabItem = (TabItem)tabControl.Items[i];
                            if (tabItem.Visibility == Visibility.Visible)
                            {

                                tabItem.Style = (Style)FindResource("LastBreadcrumbTabItem");
                                break;

                            }
                        }
                    }
                }
            }
        }
+1

I took the silverlight tabcontrol tab and made the tabitems scrollable. here is the link to the post. I think this is what you are looking for.

http://www.dansoltesz.com/post/2010/07/20/Silverlight-tabcontrol-with-scrollable-tabItems.aspx

0
source

All Articles