创建.NET 6 WPF应用程序
打开Visual Studio。
选择“创建新项目”。
在项目模板中选择“WPF应用程序”。
选择.NET 6作为目标框架。
命名你的项目并选择一个位置来保存它。
点击“创建”。
usingSystem.Windows;
namespaceYourNamespace
{
publicpartialclassMainWindow:Window
{
publicMainWindow()
{
InitializeComponent();
}
privatevoidButton_Click(object sender,RoutedEventArgs e)
{
MessageBox.Show("Hello, World!");
}
}
}
xml
<Windowx:Class="YourNamespace.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"Height="350"Width="525">
<Grid>
<ButtonContent="Click me"HorizontalAlignment="Center"VerticalAlignment="Center"Padding="10"Click="Button_Click"/>
</Grid>
</Window>
发布应用程序
在Visual Studio中,右键单击解决方案资源管理器中的项目并选择“发布”。
在“发布”选项卡中,选择“文件夹”作为目标位置。
在“配置”下拉菜单中,选择“独立”。
选择你想要支持的平台(例如,Windows)。
点击“发布”按钮。
结论
往期精品推荐:
在国内默默无闻的.NET,在国外火的超乎想象?
C#的膨胀之路:创新还是灭亡
介绍.NET 6款好看的winform开源UI库
介绍一款最受欢迎的.NET 开源UI库
WPF第三方开源UI框架:打造独特体验的魔法师
WPF与Winform,你的选择是?
WinForm的前世今生
.NET成年了,然后呢?——编程界的逆袭传奇