Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

UI Hangs after adding control to main window dynamically

$
0
0

Please find the code here added in Window_Loaded event to create a label in Grid control dynamically from different task thread. once the task is completed I am able to see the label added from this code and other controls declared in the markup in the window. However the UI hangs indefinitely, not able to manipulate any controls. my query is how to switch control to main UI thread and interact with this control later when needed. your help would be grateful.

 new Task(new Action(() =>{

                    this.mainGrid.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            Label lbl = new Label();
                            lbl.Content = "Srikar";
                            lbl.Name = "lbldesc";
                            this.mainGrid.Children.Add(lbl);
                        }),System.Windows.Threading.DispatcherPriority.Normal);                  
                })).Start();


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>