WPF常备

Font Awesome字体使用

Step1: 下载地址为:https://fontawesome.dashgame.com/
在这里插入图片描述
Step2:复制 fontawesome-webfont.ttf 字体到项目中,并在字典中引用该字体
字典中引用字体

   <FontFamily x:Key="FontAwesome">pack://application:,,,/MafengWo;component/Fonts/#FontAwesome</FontFamily>

在这里插入图片描述

如取f110在这里插入图片描述

PropertyChanged.Fody

Nuget安装

安装 PropertyChanged.Fody NuGet 软件包并更新Fody NuGet包:

Install-Package Fody
Install-Package PropertyChanged.Fody

这个Install-Package Fody这是必需的,因为NuGet总是默认为任何依赖项的最古老和最错误的版本。

添加到FodyWeavers.xml

加到FodyWeavers.xml

<Weavers>
  <PropertyChanged/>
</Weavers> 

特别提醒:VS2017 安装2.61 版本

Costura.Fody

方法同 PropertyChanged.Fody

<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
  <Costura />
  <PropertyChanged/>
</Weavers>

BaseViewModel

 [AddINotifyPropertyChangedInterface]
public class BaseViewModel : INotifyPropertyChanged
{
   
    public event PropertyChangedEventHandler PropertyChanged = (sender, e) => {
    };
    public void OnPropertyChanged(string name)
    {
   
        PropertyChanged(this, new PropertyChangedEventArgs(name));
    }
}

所有 ViewModel 全部继承自 BaseViewModel

该基类实现了 [AddINotifyPropertyChangedInterface] 接口,这样在编译的时候将PropertyChanged方法植入到public属性的Set方法中,这样就不必为每个Set都写PropertyChanged了

BasePage

public class BasePage<VM> : Page
    where VM :BaseViewModel,new ()
{
   
    #region private Member

        /// <summary>
        /// The view Model associated with this page
        /// </summary>
        private VM mViewModel;

        #endregion


    #region Properties
        /// <summary>
        /// The animition the play when the page is first loaded
        /// </summary>
        public PageAnimation PageLoadAnimation {
    get; set; } = PageAnimation.SlideAndFadeInFromRight;

        /// <summary>
        /// The animition the play when the page is first unloaded
        /// </summary>
        public PageAnimation PageUnLoadAnimation {
    get; set; } = PageAnimation.SlideAndFadeInFromLeft;

        /// <summary>
        /// The time to Animation takes complete
        /// </summary>
        public float SlideSeconds {
    get; set; } = 0.8f;

        /// <summary>
        /// The view Model associated with this page
        /// </summary>
        public VM ViewModel
        {
   
            get
            {
   
                return mViewModel;
            }
            set
            {
   //if nothing has changed ,return
                if (mViewModel == value)
                    return;
                //Update the value
                mViewModel = value;

                //Set data contenxt for this page
                this.DataContext = mViewModel;
            }
        }
        #endregion

    #region Constructor
        public BasePage()
        {
   
            if (PageLoadAnimation != PageAnimation.None)
                Visibility = Visibility.Collapsed;


            //Listen out for page loading
            Loaded += BasePage_Loaded;

            //Create a default view model
            this.ViewModel = new VM();
        }
        #endregion

    #region Animation Load / Unload

        /// <summary>
        /// Once the page is loaded ,perform any requied animation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BasePage_Loaded(object sender, System.Windows.RoutedEventArgs e)// use void   
        {
   
            await AmimationIn();
        }

        public async Task AmimationIn()
        {
   
            if (PageLoadAnimation == PageAnimation.None)
                return;
            switch (PageLoadAnimation)
            {
   
                case PageAnimation.SlideAndFadeInFromRight:
                    var sb = new Storyboard();
                    var slideAnimation = new ThicknessAnimation
                    {
   
                        Duration = new Duration
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值