Solved

WPF - C# - Add Grid Panel to Window In Code Behind

Posted on 2010-11-26
2
1,189 Views
Last Modified: 2012-05-10
I am trying to dynamically create a window with a indeterminate progress bar in it. I can create a Grid panel and the progress bar. Then I add the progress bar as a child of the Grid panel. I just don'
t know how to add the Grid panel as a child of the Window.

Experts Can You Help???

Here is what I have so far:


private void btn_Click(object sender, RoutedEventArgs e)
        {
            Window window = new Window();
            window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            window.WindowStyle = System.Windows.WindowStyle.None;
            window.ResizeMode = System.Windows.ResizeMode.NoResize;
            window.Height = 50;
            window.Width = 150;
            window.Background = Brushes.AliceBlue;
            
            Grid grid = new Grid();

            // *** add grid as child to window *** //           

            ProgressBar pb = new ProgressBar();
            pb.IsIndeterminate = true;
            pb.Height = 30;
            pb.Width = 150;
            pb.Name = "pb";

            grid.Children.Add(pb);
            window.ShowDialog();
        }

Open in new window

0
Comment
Question by:bickes0724
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 34222026
Sometimes things are so simple that they can be hidden:

window.Content = grid;
0
 

Author Closing Comment

by:bickes0724
ID: 34267566
Sorry it took so long to give you the point. Something more pressing was happening at work. Thanks again!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question