c#의 wpf는 코드로만 wpf 응용 프로그램을 만듭니다

1424 단어 c#
window1.cs
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
namespace WpfApp3
{
    class window1:Window
    {
        private Button button1;
        public window1() {
            InitializeComponent();
        }
        private void InitializeComponent() {
            //    
            this.Width = 285;
            this.Height = 250;
            this.Left = this.Top = 100;
            this.Title = "code-Only window";

            //        
            DockPanel panal = new DockPanel();
            button1 = new Button();
            button1.Content = "please click me";
            button1.Margin = new Thickness(30);
            button1.Click += button1_click;
            IAddChild container = panal;
            container.AddChild(button1);

            //        
            container = this;
            container.AddChild(panal);//  panal  

        }
        private void button1_click(object sender,RoutedEventArgs e) {
            button1.Content = "thank you";

        }
    }
}

program.cs
using System;
using System.Windows;

namespace WpfApp3
{
    class program:Application
    {
        [STAThread()]     //   
        static void Main() {
            program app = new program();
            app.MainWindow = new window1();
            app.MainWindow.ShowDialog();

        }
    }
}

좋은 웹페이지 즐겨찾기