[中秋]宇宙第一 IDE Visual Studio 了解一下


官網

https://visualstudio.microsoft.com/zh-hans/vs/

1568433673990

文檔

https://docs.microsoft.com/zh-cn/visualstudio/designers/getting-started-with-wpf?view=vs-2019

1568433803725

https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/getting-started/walkthrough-my-first-wpf-desktop-application

1568433863402

第一個WPF桌面應用程序

安裝Visual Studio

1568433946342

創建應用程序項目

1568434008402

1568434033424

工作區大概長這樣子

1568434106232

寫代碼測試

  • 編輯MainWindow.xaml(類似安卓開發的xml語言)

    1568434222809

在Grid布局中添加

<TextBlock HorizontalAlignment="Left" Margin="252,47,0,0" TextWrapping="Wrap" Text="Select a message option and then choose the Display button." VerticalAlignment="Top"/>
        <RadioButton x:Name="HelloButton" Content="Hello" IsChecked="True" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top" Height="30.24" Width="78.107"/>
        <RadioButton x:Name="GoodbyeButton" Content="Goodbye" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
        <Button Content="Display" Click="Button_Click_1" HorizontalAlignment="Left" Height="40.061" Margin="346.107,245.449,0,0" VerticalAlignment="Top" Width="201.689"/>

1568434306402

(可進行拖拽,放大縮小的圖形化操作)

  • 在MainWindow.xmal.ca添加按鈕事件

    1568434363795

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 WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互邏輯
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
                            if (HelloButton.IsChecked == true)
                                {
                               MessageBox.Show("Hello.","提示");
                                }
                           else if (GoodbyeButton.IsChecked == true)
                            {
                                MessageBox.Show("Goodbye.","提示");
                            }
         }
    }
}

其中Button_Click_1與之前xaml中Click對應

1568434433888

  • 啟動

    1568434520979

1568434541345

1568434549292


小結

C# 開發的WPF對於非專業的開發者可以作為編寫小工具的加持,畢竟現在PC桌面開發市場並不景氣。

但是拋開市場經濟的影響,C#加標記語言的開發模式和Android開發有着異曲同工之妙,殊途同歸的設計除了適應場景上的不同,不知道是否會帶來對於編程本身更加深刻的認知。

就像剛過中秋的月餅一樣,如果擺在面前的有10種月餅,每種月餅有10個,但是只能吃十個,假設從來沒有嘗過月餅的你是否會每種都去嘗試一下呢?


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM