2010-05-20 59 views
1

我想繪製一個酒吧系列以「反彈」時,我假設BounceEase TransitionEasingFunction會做到這一點,但線條只是淡入,我已經將xaml和代碼貼在下面,沒有人知道我在哪裏出了問題或者是比我更復雜的,雖然,我是相當新的Silverlight的BounceEase和silverlight 4 BarSeries

XAML

<Grid x:Name="LayoutRoot" Background="White"> 
    <chartingToolkit:Chart x:Name="MyChart"> 
     <chartingToolkit:BarSeries Title="Sales" ItemsSource="{Binding}" IndependentValuePath="Name" DependentValuePath="Value" AnimationSequence="FirstToLast" TransitionDuration="00:00:3"> 
      <chartingToolkit:BarSeries.TransitionEasingFunction> 
       <BounceEase EasingMode="EaseInOut" Bounciness="5" /> 
      </chartingToolkit:BarSeries.TransitionEasingFunction> 
      <chartingToolkit:BarSeries.DataPointStyle> 
       <Style TargetType="Control"> 
        <Setter Property="Background" Value="Red"/> 
       </Style> 
      </chartingToolkit:BarSeries.DataPointStyle> 
     </chartingToolkit:BarSeries> 
     <chartingToolkit:Chart.Axes> 
      <chartingToolkit:LinearAxis Title="Types owned" Orientation="X" Minimum="0" Maximum="300" 
       Interval="10" ShowGridLines="True" FontStyle='Italic'/> 
     </chartingToolkit:Chart.Axes> 
    </chartingToolkit:Chart> 

</Grid> 

代碼背後

public class MyClass : DependencyObject 
    { 
     public string Name { get; set; } 
     public Double Value { 
      get { return (Double)GetValue(myValueProperty); } 
      set{SetValue(myValueProperty,value);} 
     } 
     public static readonly DependencyProperty myValueProperty = 
      DependencyProperty.Register("Value", typeof(Double), typeof(MyClass), null); 
    } 

public MainPage() 
     { 
      InitializeComponent(); 
      //Get the data 
      IList<MyClass> l = this.GetData(); 
      //Get a reference to the SL Chart 

     MyChart.DataContext = l.OrderBy(e => e.Value); 
     //Find the highest number and round it up to the next digit 
     DispatcherTimer myDispatcherTimer = new DispatcherTimer(); 
     myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 5, 0); // 100 Milliseconds 
     myDispatcherTimer.Tick += new EventHandler(Each_Tick); 
     myDispatcherTimer.Start(); 

    } 
    public void Each_Tick(object o, EventArgs sender) 
    { 
     ((BarSeries)MyChart.Series[0]).DataContext = GetData(); 
    } 

    private IList<MyClass> GetData() 
    { 
     Random random = new Random(); 

     return new List<MyClass>() 
     { 
      new MyClass() {Name="Bob Zero",Value=(random.NextDouble() * 100.0)}, 
      new MyClass() {Name="Bob One",Value=(random.NextDouble() * 100.0)}, 
       new MyClass() {Name="Bob Two",Value=(random.NextDouble() * 100.0)}, 
       new MyClass() {Name="Bob Three",Value=(random.NextDouble() * 100.0)} 
     }; 
    } 

回答

0

名稱BounceEas e指的是在動畫時間動畫的值是如何變化的。 BounceEase根據您可能想像的球彈跳而變化。文檔中的圖形描述了它。

關鍵是最終動畫只是​​改變一個值,他們並不真正瞭解變化值的視覺效果。在這種情況下,動畫的值是DataPoint不透明度。因此,隨着反彈的緩解,它似乎淡入一點,然後淡出,然後淡化一小塊,直到它完全淡入。

這將需要相當多的工作,爲DataPoint創建一個新模板得到你以後的效果。

+0

謝謝,這個解釋完美,也解釋了我看到的一些例子。它非常有意義 – Pharabus 2010-05-20 23:01:23