最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

WPF中自定義GridLengthAnimation

 更新時間:2017年05月20日 16:10:38   作者:HelyCheng  
這篇文章主要為大家詳細(xì)介紹了WPF中自定義GridLengthAnimation的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下

需求

我們想在編輯一個列表中某一個條目時,將編輯的詳情內(nèi)容也放置當(dāng)前面,比如右側(cè)。

可以通過將一個Grid,分成兩個Cloumn,動態(tài)調(diào)整兩個Cloumn的Width,就可以實現(xiàn)這個需求。

我們知道,Clomun的Width是個,而默認(rèn)的動畫沒有這樣子的。我們就需要自己實現(xiàn)這樣一人動畫。

設(shè)計
我們從Animation的類圖上看到

我們可以從需求

我們想在編輯一個列表中某一個條目時,將編輯的詳情內(nèi)容也放置當(dāng)前面,比如右側(cè)。

可以通過將一個Grid,分成兩個Cloumn,動態(tài)調(diào)整兩個Cloumn的Width,就可以實現(xiàn)這個需求。

我們知道,Clomun的Width是個GridLength,而默認(rèn)的動畫沒有這樣子的。我們就需要自己實現(xiàn)這樣一人動畫。

設(shè)計

我們從Animation的類圖上看到AnimationTimeline繼承,重寫其GetCurrentValue

public class GridLengthAnimation : AnimationTimeline
  {
    /// <summary>
    /// Returns the type of object to animate
    /// </summary>
    public override Type TargetPropertyType => typeof(GridLength);
 
    /// <summary>
    /// Creates an instance of the animation object
    /// </summary>
    /// <returns>Returns the instance of the GridLengthAnimation</returns>
    protected override System.Windows.Freezable CreateInstanceCore()
    {
      return new GridLengthAnimation();
    }
 
    /// <summary>
    /// Dependency property for the From property
    /// </summary>
    public static readonly DependencyProperty FromProperty = DependencyProperty.Register("From", typeof(GridLength),
      typeof(GridLengthAnimation));
 
    /// <summary>
    /// CLR Wrapper for the From depenendency property
    /// </summary>
    public GridLength From
    {
      get
      {
        return (GridLength)GetValue(GridLengthAnimation.FromProperty);
      }
      set
      {
        SetValue(GridLengthAnimation.FromProperty, value);
      }
    }
 
    /// <summary>
    /// Dependency property for the To property
    /// </summary>
    public static readonly DependencyProperty ToProperty = DependencyProperty.Register("To", typeof(GridLength),
      typeof(GridLengthAnimation));
 
    /// <summary>
    /// CLR Wrapper for the To property
    /// </summary>
    public GridLength To
    {
      get
      {
        return (GridLength)GetValue(GridLengthAnimation.ToProperty);
      }
      set
      {
        SetValue(GridLengthAnimation.ToProperty, value);
      }
    }
 
    /// <summary>
    /// Animates the grid let set
    /// </summary>
    /// <param name="defaultOriginValue">The original value to animate</param>
    /// <param name="defaultDestinationValue">The final value</param>
    /// <param name="animationClock">The animation clock (timer)</param>
    /// <returns>Returns the new grid length to set</returns>
    public override object GetCurrentValue(object defaultOriginValue,
      object defaultDestinationValue, AnimationClock animationClock)
    {
      double fromVal = ((GridLength)GetValue(GridLengthAnimation.FromProperty)).Value;
 
      double toVal = ((GridLength)GetValue(GridLengthAnimation.ToProperty)).Value;
 
      if (fromVal > toVal)
        return new GridLength((1 - animationClock.CurrentProgress.Value) * (fromVal - toVal) + toVal, GridUnitType.Star);
      else
        return new GridLength(animationClock.CurrentProgress.Value * (toVal - fromVal) + fromVal, GridUnitType.Star);
    }

如上所示,我們仿著默認(rèn)動畫實現(xiàn)了From,To,同時將其屬性定義為GridLength,當(dāng)動畫執(zhí)行時,我們重寫了GetCurrentValue,使其根據(jù)From/To屬性相關(guān)聯(lián)。

優(yōu)化

通過以上代碼,我們實現(xiàn)了在GridLength變化時,實現(xiàn)動畫。但是,試用后我們發(fā)現(xiàn),動畫,有點太線性。這個時候,怎么辦?

可以通過引入EasingFunction來實現(xiàn)。我們知道EasingFunction其實就是一個與時間t有關(guān)的時間函數(shù)f(t).通過時間函數(shù)的處理,我們使動畫過渡不要那么線性。

 /// <summary>
    /// The <see cref="EasingFunction" /> dependency property's name.
    /// </summary>
    public const string EasingFunctionPropertyName = "EasingFunction";
 
    /// <summary>
    /// Gets or sets the value of the <see cref="EasingFunction" />
    /// property. This is a dependency property.
    /// </summary>
    public IEasingFunction EasingFunction
    {
      get
      {
        return (IEasingFunction)GetValue(EasingFunctionProperty);
      }
      set
      {
        SetValue(EasingFunctionProperty, value);
      }
    }
 
    /// <summary>
    /// Identifies the <see cref="EasingFunction" /> dependency property.
    /// </summary>
    public static readonly DependencyProperty EasingFunctionProperty = DependencyProperty.Register(
      EasingFunctionPropertyName,
      typeof(IEasingFunction),
      typeof(GridLengthAnimation),
      new UIPropertyMetadata(null));

對應(yīng)的,還要重寫GetCurrentValue函數(shù)。

public override object GetCurrentValue(object defaultOriginValue,
      object defaultDestinationValue, AnimationClock animationClock)
    {
      double fromVal = ((GridLength)GetValue(FromProperty)).Value;
 
      double toVal = ((GridLength)GetValue(ToProperty)).Value;
 
      //check that from was set from the caller
      //if (fromVal == 1)
      //  //set the from as the actual value
      //  fromVal = ((GridLength)defaultDestinationValue).Value;
 
      double progress = animationClock.CurrentProgress.Value;
 
      IEasingFunction easingFunction = EasingFunction;
      if (easingFunction != null)
      {
        progress = easingFunction.Ease(progress);
      }
 
 
      if (fromVal > toVal)
        return new GridLength((1 - progress) * (fromVal - toVal) + toVal, GridUnitType.Star);
 
        return new GridLength(progress * (toVal - fromVal) + fromVal, GridUnitType.Star);
    }

使用

 <anim:GridLengthAnimation Storyboard.TargetProperty="Width" From="0" To="*" Duration="0:0:0.5"/>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • ASP.NET中實現(xiàn)文件的保護(hù)性下載基礎(chǔ)篇

    ASP.NET中實現(xiàn)文件的保護(hù)性下載基礎(chǔ)篇

    許多時候,我們需要在因特網(wǎng)上提供文件下載服務(wù),但是又要防止未經(jīng)授權(quán)的下載,這時該怎么辦?本文將為讀者詳細(xì)介紹一種使用ASP.NET實現(xiàn)的HTTP處理程序的解決方案。
    2011-02-02
  • 解析.netcore項目中IStartupFilter使用教程

    解析.netcore項目中IStartupFilter使用教程

    netcore項目中有些服務(wù)是在通過中間件來通信的,比如orleans組件,今天通過實例代碼給大家介紹下netcore項目中IStartupFilter使用教程,感興趣的朋友一起看看吧
    2021-11-11
  • .net?6項目實現(xiàn)壓縮發(fā)布

    .net?6項目實現(xiàn)壓縮發(fā)布

    這篇文章介紹了.net?6項目實現(xiàn)壓縮發(fā)布的方式,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-12-12
  • asp.net中控制反轉(zhuǎn)的理解(文字+代碼)

    asp.net中控制反轉(zhuǎn)的理解(文字+代碼)

    控制反轉(zhuǎn),從字面意思來看, 就是控制權(quán)由被動變主動又變?yōu)楸粍樱虮粍幼冎鲃佑肿優(yōu)楸粍?。從這個角度來說,IOC就變得非常容易理解
    2014-09-09
  • .NET獲取當(dāng)前路徑的方法匯總

    .NET獲取當(dāng)前路徑的方法匯總

    本文匯總了.NET(包括ASP.NET/WinForm等)獲取當(dāng)前路徑的各種方法,具有一定的參考價值,下面跟著小編一起來看下吧
    2016-12-12
  • 壓縮aspx頁面刪除多余空格的兩種方法

    壓縮aspx頁面刪除多余空格的兩種方法

    這篇文章主要介紹了壓縮aspx頁面移除多余空格的兩種方法,可以在發(fā)布頁面之前壓縮aspx,無須浪費web server的cpu,需要的朋友可以參考下
    2014-02-02
  • 比較完整的 asp.net 學(xué)習(xí)流程

    比較完整的 asp.net 學(xué)習(xí)流程

    好多朋友想學(xué)習(xí)后臺編程語言,但請注意的事,學(xué)習(xí)后臺是個循序漸進(jìn)的過程,不可能一下就到位,其實不只是asp.net其它的編程語言都需要下面的一些知識。
    2009-06-06
  • .Net?Core?3.1?Web?API基礎(chǔ)知識詳解(收藏)

    .Net?Core?3.1?Web?API基礎(chǔ)知識詳解(收藏)

    這篇文章主要介紹了.Net?Core?3.1?Web?API基礎(chǔ)知識,本文內(nèi)容篇幅有點長,大家耐心閱讀,此文結(jié)合示例代碼給大家講解的非常詳細(xì),需要的朋友可以參考下
    2022-04-04
  • IIS部署asp.net mvc網(wǎng)站的方法

    IIS部署asp.net mvc網(wǎng)站的方法

    這篇文章主要為大家詳細(xì)介紹了IIS部署asp.net mvc網(wǎng)站的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • ADO.NET實用經(jīng)驗匯總

    ADO.NET實用經(jīng)驗匯總

    這篇文章主要介紹了ADO.NET實用經(jīng)驗匯總,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12

最新評論

吉隆县| 泸溪县| 长春市| 革吉县| 洱源县| 连城县| 沙河市| 禹城市| 乌拉特前旗| 红桥区| 乐亭县| 雅江县| 福贡县| 会同县| 阳西县| 图木舒克市| 轮台县| 新竹县| 大安市| 江永县| 芮城县| 新民市| 家居| 广德县| 永清县| 石河子市| 黑山县| 如皋市| 石渠县| 屯留县| 无锡市| 桂平市| 中西区| 曲松县| 武清区| 卢龙县| 长顺县| 巴塘县| 泸溪县| 开化县| 长兴县|