论坛凯发推荐首页 编程语言技术论坛

wpf框架系列课程(小白进阶选择) -欧洲杯足彩官网

浏览 588 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2023-11-30  
wpf框架系列课程(小白进阶选择)
参考资料下载地址1:https://pan.baidu.com/s/1rzebxgirpbsajcscf8xvvq 提取码:rbp8
参考资料下载地址2:https://share.weiyun.com/vau3sfu2 密码:9cqtcj

本文将从零基础开始讲解wpf控件、数据绑定、模板样式、资源字典、命令系统、依赖属性、路由事件、动画行为等一系列的知识,内容包含wpf的数据绑定、mvvm概念与实操、样式、模板、命令、依赖属性、路由事件、行为、自定义控件、3d、动画等高级知识,想学习wpf的小伙伴可以认真阅读本文,希望我的文章对大家有所帮助。

首先,我们先来认识wpf,那么什么是wpf呢?
wpf(windows presentation foundation)是微软推出的基于windows 的用户界面框架,属于.net framework 3.0的一部分。它提供了统一的编程模型、语言和框架,真正做到了分离界面设计人员与开发人员的工作;同时它提供了全新的多媒体交互用户图形界面。

谈到wpf的开发,就不能不说到mvvm,一说到mvvm,就会提及mvc、mvp等概念,那么这样一关联下来就会产生很多概念,到最后就很容易变成以概念来阐述概念,最终的结果可想而知,大家可能会一头雾水、不知所云,所以我用“漫谈wpf开发”这个小标题来阐述一下我对wpf开发的理解,当然只是自己对这些技术的总结和经验,错误之处在所难免,也希望大家能够谅解!

从2007年接触wpf和silverlight以来,也做过一些项目了,对他们也有一些自己的理解,当然在开发这些项目的过程中也在使用其他的一些技术做项目,比如winform、asp.net(asp.net mvc一个项目没做完就被终止)等等,感觉不论是采用什么技术,最基本的东西都不会变,比如对数据库和文件的访问、对日志和异常的处理、对报表的展现、对打印的实现、对性能的提升、对用户的友好等等。

windows presentation foundation (wpf) 是一个演示框架,可用于开发以下类型的应用程序:
独立应用程序(传统风格的 windows 应用程序,这些应用程序作为要安装到客户端计算机并从客户端计算机运行的可执行程序集来生成)。
xaml 浏览器应用程序 (xbap)(由导航页组成的应用程序,这些应用程序作为可执行程序集生成并由 microsoft internet explorer 或 mozilla firefox 等 web 浏览器托管)。
自定义控件库(包含可重用控件的非可执行程序集)。
类库(包含可重用类的非可执行程序集)。

窗口和对话框
用户通过窗口与 wpf 独立应用程序交互。 窗口旨在托管应用程序内容并提供通常允许用户与内容交互的应用程序功能。 在 wpf 中,通过 window 类封装窗口,该类支持:
创建和显示窗口。
建立所有者/所拥有窗口关系。
配置窗口外观(例如,大小、位置、图标、标题栏文本、边框)。
对窗口的生存期进行跟踪并与之进行交互。

添加module类,并实现prism.modularity.imodule接口,实现接口的模块,视为可以被prism发现并加载的模块。以defectlistmodule模块为例:
namespace demoprism.first{ public class firstmodule : imodule { public void oninitialized(icontainerprovider containerprovider) { iregionmanager regionmanager = containerprovider.resolve(); regionmanager.registerviewwithregion("firstregion", typeof(views.firstview)); } public void registertypes(icontainerregistry containerregistry) { containerregistry.registerfornavigation(); } }}

新建用户。同样,给用户定义一个主键,然后我们在本地创建这个用户
// 3. 添加用户
var adminuserid = "90184155-dee0-40c9-bb1e-b5ed07afc04e";
applicationuser adminuser = new applicationuser
{
    id = adminuserid,
    username = "admin@fakexiecheng.com",
    normalizedusername = "admin@fakexiecheng.com".toupper(),
    email = "admin@fakexiecheng.com",
    normalizedemail = "admin@fakexiecheng.com".toupper(),
    twofactorenabled = false,
    emailconfirmed = true,
    phonenumber = "123456789",
    phonenumberconfirmed = false
};
首先,去数据库获得旅游路线的详细数据。这里做一个判断,如果touristroute 不存在,touristroute ==null, 我们需要返回响应404
接下来,给购物车创建lineitem
最后,把旅游路线当前的价格复制出来,
// 3 创建lineitem
var touristroute = await _touristrouterepository
    .gettouristrouteasync(addshoppingcartitemdto.touristrouteid);
if(touristroute == null)
{
    return notfound("旅游路线不存在");
}

var lineitem = new lineitem()
{
    touristrouteid = addshoppingcartitemdto.touristrouteid,
    shoppingcartid = shoppingcart.id,
    originalprice = touristroute.originalprice,
    discountpresent = touristroute.discountpresent
};
接下来,我们还需要使用automapper处理model与dto的自动映射。在profile文件夹创建一个新profile文件,文件命名orderprofile。class继承automapper的profile,然后在构建函数中加入model到dto的映射关系。
[httppost("checkout")]
[authorize(authenticationschemes = "bearer")]
public async task checkout()
{
    // 1 获得当前用户
    var userid = _httpcontextaccessor
        .httpcontext.user.findfirst(claimtypes.nameidentifier).value;

    // 2 使用userid获得购物车
    var shoppingcart = await _touristrouterepository.getshoppingcartbyuserid(userid);

    // 3 创建订单
    var order = new order()
    {
        id = guid.newguid(),
        userid = userid,
        state = orderstateenum.pending,
        orderitems = shoppingcart.shoppingcartitems,
        createdateutc = datetime.utcnow,
    };

    shoppingcart.shoppingcartitems = null;

    // 4 保存数据
    await _touristrouterepository.addorderasync(order);
    await _touristrouterepository.saveasync();

    // 5 return
    return ok(_mapper.map(order));
}
全部链接添加完毕,我们就要可以返回响应了,响应数据就是links列表。现在,用户就可以通过访问这个api的根目录获得api的使用方法了。
[route("api")]
[apicontroller]
public class rootcontroller: controllerbase
{
    [httpget(name = "getroot")]
    public iactionresult getroot()
    {
        var links = new list();

        // 自我链接
        links.add(
            new linkdto(
                url.link("getroot", null),
                "self",
                "get"
            ));

        // 一级链接 旅游路线 “get api/touristroutes”
        links.add(
            new linkdto(
                url.link("gettouristroutes", null),
                "get_tourist_routes",
                "get"
            ));

        // 一级链接 旅游路线 “post api/touristroutes”
        links.add(
            new linkdto(
                url.link("createtouristroute", null),
                "create_tourist_route",
                "post"
            ));

        // 一级链接 购物车 “get api/orders”
        links.add(
            new linkdto(
                url.link("getshoppingcart", null),
                "get_shopping_cart",
                "get"
            ));

        // 一级链接 订单 “get api/shoppingcart”
        links.add(
            new linkdto(
                url.link("getorders", null),
                "get_orders",
                "get"
            ));

        return ok(links);
    }
}

 
global site tag (gtag.js) - google analytics
网站地图