tabControl/tabitem 刷新困难 [英] Difficulty with tabControl/tabitem refresh

查看:71
本文介绍了tabControl/tabitem 刷新困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 maintabWindow 和几个 tabitems 的 WPF 窗口.它通常工作正常,布局是这样的:

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

但是当我之前添加以下窗口时:

but when I BEFORE add the following window:

结果如下:

所以问题与tabControl/tabItem刷新有关.这是相当明显的,但更重要的是,如果我移动窗口或在 tabItem 上用鼠标传递,它们会被一个一个地刷新.

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.

我搜索了一下,发现这里有一个解决方案:http://geekswithblogs.net/NewThingsILearned/archive/2008/08/25/refresh--update-wpf-controls.aspx

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

所以我补充说:

  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.

感谢您的帮助

推荐答案

好吧,最后它有一个相当奇怪的行为.如果我这样做

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();
  }

它有效.但是我必须设置第一个 tabitem 所以如果我添加

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;

但这一点都不优雅.如果有人有更好的解决方案,请告诉我.顺便说一句,添加 tbcMain.SelectedIndex = 0;在 mainWindow 的加载事件上是没有用的.

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.

这篇关于tabControl/tabitem 刷新困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆