WPF 跨线程修改前台控件

mac2022-07-05  31

场景:

Public Class A{  Thread thd;  public A()  {     thd=new Thread(new ThreadStart(Demo));     thd.IsBackground=true;     thd.Start(); }

  public Static void Demo()  {   UI _UI=new UI();   _UI.tb.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,new Action()=>{   _UI.tb.Text="我是描述控件!";   }); }

项目中的UI控件:

public Class UI:UserControl{  Public TextBlock tb=new TextBlock();  public UI()     {   InitializeComponent();       this.AddChild(tb);     }} 

转载于:https://www.cnblogs.com/GeneralKING/archive/2012/11/15/2771965.html

最新回复(0)