【发布时间】:2016-02-02 09:26:00
【问题描述】:
我正在尝试将子控件 (UserControl) 添加到 Grid 并且更改未反映。但是,如果将另一个子控件 (UserControl) 添加到同一个网格中,则布局会更新并且两个子控件都可见。此操作在按钮单击时执行。
/*this Operation is perform in Backgroud Worker */
void func()
{
/*adding first User Control*/
addRemoveChild(true,FirstChild);//even tried to run this fuc with Dispatcher
FixButton();
addRemoveChild(false,FirstChild);
}
void addRemoveChild(bool isAdd,UserControl uc)
{
if (isAdd)
{
parentGrid.Children.Add(uc); /*parentGrid is Parent Grid*/
parentGrid.UpdateLayout();
return;
}
else
{
parentGrid.Children.Remove(uc);
parentGrid.UpdateLayout();
}
}
void FixButton()
{
/* here some operation is perform which takes 5 min to complete till then FirstChild is not visible*/
addRemoveChild(true,secondChild); /*When this Func run the first Child is visible*/
}
【问题讨论】:
-
确保您的 UI 线程不会因为 FixButton() 方法中的 5 分钟操作而被阻塞
-
并尝试评论那 5 分钟的操作并检查会发生什么?
-
你最好更新你的整个代码,包括 5 分钟的操作..
标签: c# wpf asynchronous