wpf教程-环境搭建

  1. 安装vs2022,安装的项目选择.net 桌面开发
    在这里插入图片描述

  2. 启动vs2022,选择新建项目
    在这里插入图片描述

  3. 搜索wpf模板选择wpf应用程序
    在这里插入图片描述

  4. 设置项目名称和存储路径
    在这里插入图片描述

  5. 选择.net版本,我这里选择了asp.net core3.1
    在这里插入图片描述

  6. 创建完成
    在这里插入图片描述

  7. 在MainWindow.xaml添加一个按钮控件

<Window x:Class="WpfApp01.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:WpfApp01"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button Width="200" Height="200" Content="Hello World" Click="Button_Click"></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 WpfApp01
{
    /// <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 World");
        }
    }
}

在这里插入图片描述

  1. 启动查看效果
    在这里插入图片描述
    在这里插入图片描述
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
WPF 01-BootstrapperShell是一种用于启动和初始化WPF应用程序的框架。它是指示WPF应用程序在启动时应执行的代码的入口点。通常情况下,我们可以在App.xaml.cs文件中找到它。 BootstrapperShell提供了一种将应用程序的各个部分组织在一起的方式,以便在启动时执行特定的操作。这些操作可以包括设置应用程序的默认样式、添加全局资源、注册服务和创建主窗口等。通过将所有这些相关的代码集中到一个地方,我们可以更好地管控应用程序的启动过程。 通常情况下,BootstrapperShell会执行以下几个步骤: 1. 创建应用程序的主窗口:这个步骤通常在App.xaml.cs文件的OnStartup方法中完成。我们可以在这里创建一个MainWindow实例,并将其设置为应用程序的主窗口。 2. 设置应用程序的默认样式:WPF应用程序通常使用样式来定义应用程序中各个控件的外观和行为。在BootstrapperShell中,我们可以通过添加资源字典来设置应用程序的默认样式。 3. 注册服务和初始化其他组件:在应用程序启动时,我们可能需要注册一些服务或初始化其他组件,以便在应用程序中的其他地方使用。在BootstrapperShell中,我们可以执行这些操作。 4. 处理未捕获的异常:在应用程序中可能会发生未捕获的异常,我们可以通过在BootstrapperShell中实现Application.DispatcherUnhandledException事件处理程序来捕获和处理这些异常。 总而言之,WPF 01-BootstrapperShell是一种用于组织和管理WPF应用程序启动过程的框架。它提供了一个入口点来集中所有与应用程序启动相关的代码和操作,从而更好地控制应用程序的行为和外观。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

假装我不帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值