WPF之HelloWorld

作者:追风剑情 发布于:2019-3-11 13:09 分类:C#

一、创建WPF工程

111.png

二、拖一个界面

4444.png

三、给UI元件取名称

555.png6666.png

四、绑定事件

777.png

MainWindow.xaml

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="128.029" Width="207.036">
    <Grid Margin="0,0,-1.036,6" HorizontalAlignment="Left" Width="200.036" Height="82" VerticalAlignment="Bottom">
        <Button x:Name="btn" Content="Button" Margin="66.482,50,60.806,0" VerticalAlignment="Top" Click="btn_Click"/>
        <Label x:Name="lbl" Content="" HorizontalAlignment="Center" Margin="53.13,10,42.899,0" VerticalAlignment="Top" Width="104.007"/>

    </Grid>
</Window>

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btn_Click(object sender, RoutedEventArgs e)
        {
            lbl.Content = "Hello World!";
        }
    }
}

运行测试

2222.png

点击Button

3333.png


标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号