<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                今天, 我給大家講解如何用C#動態改變grid容器的行寬或者列高.WPF的Storyboard真的很強大, 尤其是和blend 3配和后就更容易了, 但是呢仔細看下Grid的width/height的數據類型是GridLength, 也就是說不是普通的Int, Double, `Boolean`, `Char`, `Byte`, `Color`, `Point`類型, 而wpf也沒有給我們提供一個GridLength的動畫類.GridLength是一個struct. (一) 創建一個支持GridLength類型的動畫類 我們新建一個繼承AnimationTimeLine的類GridLengthAnimation, 我們簡單實現2個依賴屬性"From", "To".代碼如何: ~~~ internal class GridLengthAnimation : AnimationTimeline { static GridLengthAnimation() { FromProperty = DependencyProperty.Register("From", typeof(GridLength), typeof(GridLengthAnimation)); ToProperty = DependencyProperty.Register("To", typeof(GridLength), typeof(GridLengthAnimation)); } public static readonly DependencyProperty FromProperty; public GridLength From { get { return (GridLength)GetValue(GridLengthAnimation.FromProperty); } set { SetValue(GridLengthAnimation.FromProperty, value); } } public static readonly DependencyProperty ToProperty; public GridLength To { get { return (GridLength)GetValue(GridLengthAnimation.ToProperty); } set { SetValue(GridLengthAnimation.ToProperty, value); } } ~~~ 接下來我們就來依次重載或者實現AnimationTimeLine類的成員, 1. 重載[CreateInstanceCore](http://msdn.microsoft.com/zh-cn/library/system.windows.freezable.createinstancecore%28VS.90%29.aspx), 代碼如下: ~~~ protected override System.Windows.Freezable CreateInstanceCore() { return new GridLengthAnimation(); } ~~~ 2. 重載[GetCurrentValue](http://msdn.microsoft.com/zh-cn/library/system.windows.media.animation.animationtimeline.getcurrentvalue%28VS.90%29.aspx)以返回動畫的當前值, 代碼如下: ~~~ 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, ((GridLength)GetValue(GridLengthAnimation.FromProperty)).GridUnitType); } else return new GridLength(animationClock.CurrentProgress.Value * (toVal - fromVal) + fromVal, ((GridLength)GetValue(GridLengthAnimation.ToProperty)).GridUnitType); } ~~~ 3. 重寫[TargetPropertyType](http://msdn.microsoft.com/zh-cn/library/system.windows.media.animation.animationtimeline.targetpropertytype%28VS.90%29.aspx) 屬性以指示相應的動畫所生成輸出的[Type](http://msdn.microsoft.com/zh-cn/library/system.type%28VS.90%29.aspx), 代碼如何: ~~~ public override Type TargetPropertyType { get { return typeof(GridLength); } } ~~~ ok, 通過上面的步驟我們已經寫好了GridLengthAnimation類, 接下來就是如何使用此類. (二)xaml使用此類, 代碼如何: ~~~ <Window.Resources> <Storyboard x:Key="sbDock"> <common:GridLengthAnimation BeginTime="00:00:00" Storyboard.TargetName="_cellLeft" Storyboard.TargetProperty="Width"> </common:GridLengthAnimation> </Storyboard> </Window.Resources> <Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition x:Name="_cellLeft" Width="300"/> <ColumnDefinition x:Name="_cellRight" Width="*"/> </Grid.ColumnDefinitions> </Grid> ~~~ (三)c#使用此類, 代碼如下: ~~~ Storyboard sbDock = this.FindResource("sbDock") as Storyboard; if (sbDock != null) { SplineDoubleKeyFrame sdKeyFrame1 = new SplineDoubleKeyFrame(TransformRadius, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))); (sbDock.Children[0] as DoubleAnimationUsingKeyFrames).KeyFrames.Clear(); (sbDock.Children[0] as DoubleAnimationUsingKeyFrames).KeyFrames.Add(sdKeyFrame1); (sbDock.Children[1] as GridLengthAnimation).From = new GridLength(300, GridUnitType.Pixel); (sbDock.Children[1] as GridLengthAnimation).To = new GridLength(0, GridUnitType.Pixel); sbDock.Begin(); } ~~~ 工程代碼:?[GridLengthDemo.rar](http://dldx.csdn.net/fd.php?i=469722551228511&s=59ce5766f682bd855d87ec381d1c2945) (如果打不開, 請到我的csdn的資源里下載, 資源分是0)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看