0
새로운 리본 탭 및 새 자식 컨트롤을 Grid에 추가하는 작업 응용 프로그램이 있습니다.UI 컨트롤 업데이트 wpf 백그라운드 스레드
나는 등 데이터베이스에서 데이터를 수집하는 동안,
을 취할 수있는 자식 컨트롤로 백그라운드 스레드에이 작업을 넣어 싶습니다 내가 가지고 지금까지 다음 코드를
Ribbon Ribbon_Main = new Ribbon();
Grid Grid_Main = new Grid();
Thread newthread2 = new Thread(new ThreadStart(delegate { Graphing_Template.add_report(); }));
newthread2.SetApartmentState(ApartmentState.STA); //Is this required?
newthread2.Start();
Class Graphing_Template()
{
static void add_report()
{
RibbonTab rt1 = new RibbonTab();
MainWindow.Ribbon_Main.Items.Add(rt1);
// Create control with information from Database, etc.
// add control to MainWindow.Grid_Main
}
}
새 보고서 컨트롤을 백그라운드에서 만든 다음 준비가되면 기본 UI에 추가하고 싶습니다.
는내가 갔다 솔루션은 다음과 같습니다 당신이 UI 스레드에서가 아니라면
일반적으로 BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += delegate(object s, DoWorkEventArgs args)
{
DataTable dt1 = new DataTable();
---- Fill DataTable with
args.Result = datagrid_adventureworks_DT();
};
worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
DataTable dt1 = (DataTable)args.Result;
Datagrid_Main.ItemsSource = dt1.AsDataView();
};
은 UI 객체를 만지지 마십시오. 백그라운드 스레드에서 제대로 작동하지만 UI 디스패처를 통해 UI 업데이트를 마샬링합니다. – Cameron
두 개의 자식 개체를 생성하고 UI 스레드로 다시 전달할 수 있습니까? – user3329538
확실한 답변을 드릴만큼 충분한 WPF를 모르겠습니다. 죄송합니다. Win32 UI 객체는 버튼을 생성하는 스레드 (예 : WPF는 버튼과 같은 단순한 것들에는 Win32 UI 객체를 사용하지 않기 때문에 Winform UI 객체는 UI 객체를 만져야하기 때문에 winforms에서는 작동하지 않을 것이라고 생각합니다. 기타.). – Cameron