Linux下极致体验WPF编程之旅(linuxwpf)

Linux是Unix系操作系统家族之一,也称为GNU/Linux,是属于自由软件,用户可以任意使用。今天要分享的是如何使用Linux编程体验WPF编程。

WPF( Windows Presentation Foundation),即窗口应用程序的面向开发者的框架,是Microsoft公司的商业软件开发平台。它结合了WinForms和DirectX,在应用程序的图形界面设计上更加出色。WPF作为一种新的可视化平台,可以帮助我们快速开发出更加漂亮的用户界面,同时用C#、VB.NET或其他.NET Framework语言实现功能。

首先,我们需要准备所需要的软件,包括MonoDevelop、WinForms+WPF组件、辅助工具和.NET Runtime等,安装它们最好采用统一的安装方式,例如.Net Framework安装只需使用命令:yum install dotnetcore-runtime

然后安装MonoDevelop,采用命令:sudo yum install monodevelop安装框架,接着安装扩展碎片WinForms和WPF,使用命令:su yum install mwb.ext 。当安装完成后,就可以开始编程和开发了。

接下来就是WPF编程体验之旅,一般来说,它分为四步:首先,通过MonoDevelop创建WPF应用程序,此时会自动生成程序的.NET代码,其结构为:

//文件App.xaml中

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">



//文件MainWindow.xaml中

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyAppName" Height="300" Width="300">



第二步就是开发实际的应用程序,可以使用特定的声明式编程语言XAML来定义应用程序的布局,将控件添加到页面,应用样式,响应事件等:

//文件MainWindow.xaml中

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyAppName" Height="300" Width="300">


VerticalAlignment="Center" />


第三步是实现C#/VB文件,使用代码编写业务逻辑,将添加控件响应事件:

//文件MainWindow.xaml.cs中
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.button.Click += Button_Click;
}

void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Hello World!");
}
}

最后一步,调试运行程序,采用命令:mono MyAppName.exe即可完成运行,Linux带来的WPF编程体验已经到位。

综上所述,Linux下可以方便的以极致体验WPF编程,以上步骤仅供参考,只要按照要求准备软件,就能体验得到它带来的快乐。


数据运维技术 » Linux下极致体验WPF编程之旅(linuxwpf)