WPF入門1 -- Hello WPF

        一直很想學習C#,終於機會來了。現在要開始學寫界面,所以現在開始一邊學習一邊寫博客。

        首先學習了最基礎的Hello WPF,Titie屬性修改成WPF First Application,然後拖拽一個button,button的Content改成Hello WPF,雙擊button跳轉到後端代碼,加上響應的方法:Messagebox.show輸出。


        代碼如下:

<Window x:Class="WPF1.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:WPF1"
        mc:Ignorable="d"
        Title="WPF First Application" Height="350" Width="525">
    <Grid>
        <Button x:Name="btnHello" Content="Hello WPF" HorizontalAlignment="Left" Margin="175,120,0,0" VerticalAlignment="Top" Width="180" RenderTransformOrigin="0.5,0.5" Height="105" Click="button_Click">
            <Button.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="-0.413"/>
                    <TranslateTransform/>
                </TransformGroup>
            </Button.RenderTransform>
        </Button>

    </Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 WPF1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Hello WPF!");
        }
    }
}

實現效果如下:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章