2012-04-04 57 views
0

我有一個自定義(並且越來越複雜)TabControl。這是許多來源的聚會,加上我自己想要的功能。在自定義Panel中顯示TabControl的標題。其功能是壓縮TabItems的大小,直到達到最小值,然後激活滾動功能(再次在面板中)。還有另一個自定義面板可容納一個按鈕,該按鈕呈現在TabItems右側(這是一個「新選項卡」按鈕)。自定義面板佈局在預設動畫時無法正常工作(WPF)

這一切都很好,直到我嘗試製作動畫滾動。

下面是一些有關的片段:

在CustomTabPanel(C#,覆蓋Panel和實施IScrollInfo):

private readonly TranslateTransform _translateTransform = new TranslateTransform(); 

public void LineLeft() 
{ 
    FirstVisibleIndex++; 

    var offset = HorizontalOffset + _childRects[0].Width; 
    if (offset < 0 || _viewPort.Width >= _extent.Width) 
     offset = 0; 
    else 
    { 
     if (offset + _viewPort.Width > _extent.Width) 
      offset = _extent.Width - _viewPort.Width; 
    } 

    _offset.X = offset; 
    if (_scrollOwner != null) 
     _scrollOwner.InvalidateScrollInfo(); 

    //Animate the new offset 
    var aScrollAnimation = new DoubleAnimation(_translateTransform.X, -offset, 
              new Duration(this.AnimationTimeSpan), FillBehavior.HoldEnd) { AccelerationRatio = 0.5, DecelerationRatio = 0.5 }; 
    aScrollAnimation.Completed += ScrollAnimationCompleted; 

    _translateTransform.BeginAnimation(TranslateTransform.XProperty, aScrollAnimation , HandoffBehavior.SnapshotAndReplace); 

    //End of animation 

    // These lines are the only ones needed if we remove the animation 
    //_translateTransform.X = -offset; 
    //InvalidateMeasure(); 
} 


void ScrollAnimationCompleted(object sender, EventArgs e) 
{ 
    InvalidateMeasure(); 
} 

_translateTransform被初始化在構造:

base.RenderTransform = _translateTransform; 

再次,如果我刪除了動畫部分,並將其替換爲註釋掉的行,那麼一切都很好結束。

我還必須指出,問題不在於動畫本身。這部分工作得很好。問題是關於何時刪除一些標籤項目:所有佈局然後擰緊。 TranslateTransformation似乎存在一些錯誤的價值,或什麼。

在此先感謝。

回答

0

好吧。往往是這樣,我一直在努力工作,並且...自己回答。

對其他人仍然有用,所以這裏是抓住。在行:

var aScrollAnimation = new DoubleAnimation(_translateTransform.X, -offset, new Duration(this.AnimationTimeSpan), FillBehavior.HoldEnd) 
    { AccelerationRatio = 0.5, DecelerationRatio = 0.5 }; 

FillBehavior應該已經FillBehavior.Stop

就這麼簡單!