Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difficulty with tabControl/tabitem refresh

I have a WPF window with a maintabWindow and several tabitems. It normally works fine and the layout is this:

enter image description here

but when I BEFORE add the following window:

enter image description here

the result is this:

enter image description here

So the problem is related with the tabControl/tabItem refresh. This is fairly obvious but even more because if I move the window or pass with the mouse on the a tabItem they get refreshed one by one.

I searched and found that here is a solution: http://geekswithblogs.net/NewThingsILearned/archive/2008/08/25/refresh--update-wpf-controls.aspx

so I added:

  this.MainTab.Refresh();
  this.tabItem1.Refresh();
  this.tabItem2.Refresh();
  this.tabItem3.Refresh();
  this.tabItem4.Refresh();
  this.tabItem5.Refresh();

but that didn't change a thing.

Thanx for any help

like image 554
Patrick Avatar asked Nov 19 '25 00:11

Patrick


1 Answers

Ok so in the end it has a quite a weird behavious. If I do

for (int i = 0; i < tbcMain.Items.Count; i++)
  {
    tbcMain.SelectedIndex = i;
    tbcMain.UpdateLayout();
  }

it works. But I have to set the 1st tabitem so if I add

 tbcMain.SelectedIndex = 0;

it doesn't. So the solution was put a sleep and it works again.

for (int i = 0; i < tbcMain.Items.Count; i++)
  {
    tbcMain.SelectedIndex = i;
    tbcMain.UpdateLayout();
  }

  System.Threading.Thread.Sleep(250);
  tbcMain.SelectedIndex = 0;

But that is not elegant at all. If anyone has a better solution pls let me know it. Btw adding the tbcMain.SelectedIndex = 0; on the loaded event of the mainWindow is of no use.

like image 165
Patrick Avatar answered Nov 21 '25 14:11

Patrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!