CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Oct 2011

    beginner question

    Hi, I've been learning C# for a while now so I decided to finally tackle WPF, and I feel like a beginner again. Only a few pages into my studies I tried to replicate the code in my book but it just doesnt seem to produce the output that the book shows.

    Im trying to create a simple window with a button as its only content, however the button is not showing up at all, just the window.

    Also, the title of the window that pops up is "MainWindow" even though I called the constructor with the title argument "My First WPF Program"

    Can somebody please help me resolve those 2 issues.

    using System;
    using System.Windows;
    using System.Windows.Controls;
    namespace WPF_Practice
        class Program : Application
            int Main()
                Program app = new Program();
                app.Startup += AppStartup;   
                app.Exit += AppExit;         
                return 0;
            static void AppStartup(object sender, StartupEventArgs arg)
                MainWindow themain = new MainWindow("My First WPF Program", 400, 300);
            static void AppExit(object sender, ExitEventArgs arg)
                Console.WriteLine("Application is now exiting");
        class MainWindow : Window  
            private Button exitbutton = new Button();
            public MainWindow(string t, int h, int w)
                exitbutton.Click += exitbutton_Click;  
                exitbutton.Content = "Close Window";
                exitbutton.Height = 25;
                exitbutton.Width = 100;
                this.Content = exitbutton; // Setting content of the Window to a single button. 
                this.Title = t;
                this.Height = h;
                this.Width = w;
                this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            private void exitbutton_Click(object sender, RoutedEventArgs arg)

  2. #2
    Join Date
    Feb 2012

    Re: beginner question


    Why don't you create WPF window in XAML language? It's very simple .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.