Solved

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

Posted on 2010-11-26
2
1,194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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