• 大小: 575KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-28
  • 语言: C#
  • 标签: WPF  

资源简介

WPF对比WinForm简单实例,这个例子主要展示同一个需求用WinForm和WPF分别进行实现,通过这个例子,我们可以看到两者之间的区别和联系,同时也可以对我们的项目选型带来一定的参考作用

资源截图

代码片段和文件信息

using System;
using System.ComponentModel;
using System.IO;
using System.Reflection;

namespace Businessobjects
{
public class Company : INotifyPropertyChanged
{
    #region 创建数据方法

    public static Company[] GetCompanys()
    {
        // 在真正的应用程序中,这可能会调用数据访问层,从数据库中获取记录。
        return new Company[]
        {
            new Company(1 “博客园“ “CNBlogs“ GetPictureFile(1) new DateTime(2004 1 12))
            new Company(2 “51CTO“ “51CTO“ GetPictureFile(2) new DateTime(2005 3 1))
            new Company(3 “CSDN“ “CSDN“ GetPictureFile(3) new DateTime(2000 1 20))
            new Company(4 “开源中国“ “开源中国“ GetPictureFile(4) new DateTime(2008 8 1))
            new Company(5 “ITEYE“ “ItEye“ GetPictureFile(5) new DateTime(2011 4 1))
        };
    }

    private static string GetPictureFile(int CompanyID)
    {
        string fileName = String.Format(“emp{0}.jpg“ CompanyID);
        string folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
        folder = Path.Combine(folder “Images“);
        return Path.Combine(folder fileName);
    }

    private Company(int id string chineseName string EnglishName string pictureFile DateTime startDate)
    {
        this.ID = id;
        this.chineseName = chineseName;
        this.EnglishName = EnglishName;
        this.PictureFile = pictureFile;
        this.StartDate = startDate;
    }

    #endregion // 创建数据方法

    #region 实体属性

    public int ID { get; private set; }

    string _chineseName;
    public string chineseName//中文名称
    {
        get { return _chineseName; }
        set
        {
            if (value == _chineseName)
                return;

            _chineseName = value;

            this.onpropertychanged(“chineseName“);
            this.onpropertychanged(“FullName“);
        }
    }

    string _EnglishName;
    public string EnglishName//英文名称
    {
        get { return _EnglishName; }
        set
        {
            if (value == _EnglishName)
                return;

            _EnglishName = value;

            this.onpropertychanged(“EnglishName“);
            this.onpropertychanged(“FullName“);
        }
    }

    public string FullName 
    { 
        get { return String.Format(“{0} {1}“ this.EnglishName this.chineseName); } 
    }

    public string PictureFile { get; private set; }//图片文件地址
    public DateTime StartDate { get; private set; }//开始时间

    #endregion // 实体属性

    #region INotifyPropertyChanged 接口

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void onpropertychanged(string propertyName)//属性变更通知
        {
        PropertyChangedEventHandler handler = this.PropertyChanged;
        if (handler != null)
            handler(this new PropertyChangedEventArgs(propertyName));
    }

    #endregion
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.    113152  2018-12-28 08:53  WinFormsAndWPFCompare\WinFormsAndWPFCompare\.vs\WinFormsAndWPFCompare\v15\.suo

     文件          0  2018-12-25 11:46  WinFormsAndWPFCompare\WinFormsAndWPFCompare\.vs\WinFormsAndWPFCompare\v15\Server\sqlite3\db.lock

     文件     733184  2018-12-28 08:53  WinFormsAndWPFCompare\WinFormsAndWPFCompare\.vs\WinFormsAndWPFCompare\v15\Server\sqlite3\storage.ide

     文件       6656  2018-12-27 10:26  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\bin\Debug\Businessobjects.dll

     文件      15872  2018-12-27 10:26  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\bin\Debug\Businessobjects.pdb

     文件       5793  2010-07-07 21:50  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\bin\Debug\Images\emp1.jpg

     文件       4318  2010-07-07 21:51  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\bin\Debug\Images\emp2.jpg

     文件       4500  2010-07-07 21:51  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\bin\Debug\Images\emp3.jpg

     文件       3962  2018-12-26 11:12  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\bin\Debug\Images\emp4.jpg

     文件       9221  2018-12-26 11:20  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\bin\Debug\Images\emp5.jpg

     文件       3321  2018-12-26 11:35  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\Businessobjects.csproj

     文件        228  2018-12-26 11:25  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\Businessobjects.csproj.user

     文件       3104  2018-12-27 08:55  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\Company.cs

     文件       5793  2010-07-07 21:50  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\Images\emp1.jpg

     文件       4318  2010-07-07 21:51  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\Images\emp2.jpg

     文件       4500  2010-07-07 21:51  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\Images\emp3.jpg

     文件       3962  2018-12-26 11:12  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\Images\emp4.jpg

     文件       9221  2018-12-26 11:20  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\Images\emp5.jpg

    ..A.SH.     22016  2010-07-07 21:52  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\Images\Thumbs.db

     文件         42  2018-12-26 11:33  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\obj\Debug\Businessobjects.csproj.CoreCompileInputs.cache

     文件       3197  2018-12-26 11:35  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\obj\Debug\Businessobjects.csproj.FileListAbsolute.txt

     文件       7660  2018-12-26 15:14  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\obj\Debug\Businessobjects.csprojResolveAssemblyReference.cache

     文件       6656  2018-12-27 10:26  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\obj\Debug\Businessobjects.dll

     文件      15872  2018-12-27 10:26  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\obj\Debug\Businessobjects.pdb

     文件        674  2018-12-26 15:14  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7077  2018-12-26 11:31  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1442  2008-05-03 15:32  WinFormsAndWPFCompare\WinFormsAndWPFCompare\Businessobjects\Properties\AssemblyInfo.cs

     文件       2103  2018-12-25 11:46  WinFormsAndWPFCompare\WinFormsAndWPFCompare\WinFormsAndWPFCompare.sln

    ..A..H.     52224  2010-07-09 02:07  WinFormsAndWPFCompare\WinFormsAndWPFCompare\WinFormsAndWPFCompare.suo

     文件       6656  2018-12-27 10:26  WinFormsAndWPFCompare\WinFormsAndWPFCompare\WinFormsApp\bin\Debug\Businessobjects.dll

............此处省略123个文件信息

评论

共有 条评论