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

  • 2019 年 10 月 6 日
  • 笔记

官网

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

文档

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

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

第一个WPF桌面应用程序

安装Visual Studio

创建应用程序项目

工作区大概长这样子

写代码测试

  • 编辑MainWindow.xaml(类似安卓开发的xml语言)

在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"/>

(可进行拖拽,放大缩小的图形化操作)

  • 在MainWindow.xmal.ca添加按钮事件
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对应

  • 启动

小结

C# 开发的WPF对于非专业的开发者可以作为编写小工具的加持,毕竟现在PC桌面开发市场并不景气。

但是抛开市场经济的影响,C#加标记语言的开发模式和Android开发有着异曲同工之妙,殊途同归的设计除了适应场景上的不同,不知道是否会带来对于编程本身更加深刻的认知。

就像刚过中秋的月饼一样,如果摆在面前的有10种月饼,每种月饼有10个,但是只能吃十个,假设从来没有尝过月饼的你是否会每种都去尝试一下呢?