WPF常备

阅读: 评论:0

WPF常备

WPF常备

WPF常备

  • Font Awesome字体使用
  • PropertyChanged.Fody
    • Nuget安装
    • 添加到l
  • Costura.Fody
  • BaseViewModel
  • BasePage
  • BaseAttachedProperty
  • BaseValueConverter
  • BooleanToVisiblityConverter
  • Storyboard
  • AttachedProperty实现逆时针顺时针旋转功能
  • 几种动画注意事项

Font Awesome字体使用

Step1: 下载地址为:/

Step2:复制 f 字体到项目中,并在字典中引用该字体
字典中引用字体

   <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总是默认为任何依赖项的最古老和最错误的版本。

添加到l

加到l

<Weavers><PropertyChanged/>
</Weavers> 

特别提醒:VS2017 安装2.61 版本

Costura.Fody

方法同 PropertyChanged.Fody

<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="" 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> : Pagewhere 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 ,returnif (mViewModel == value)return;//Update the valuemViewModel = value;//Set data contenxt for this pagethis.DataContext = mViewModel;}}#endregion#region Constructorpublic BasePage(){if (PageLoadAnimation != PageAnimation.None)Visibility = Visibility.Collapsed;//Listen out for page loadingLoaded += BasePage_Loaded;//Create a default view modelthis.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

本文发布于:2024-01-31 20:04:15,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170670265531027.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:WPF
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23