Wpf / Silverlight gridview删除行模糊效果

时间:2014-08-08 10:51:08

标签: c# wpf silverlight gridview

删除第一行并再次添加。 那么,当你从GridView中删除一行时,如何将效果应用到该行?

ObservableCollection<Work> perWorks = new ObservableCollection<Work>();
void Timer2_Click(object sender, EventArgs e)
    {
        #region ListBox Remove And Effect / in Process
        if (works.Count > 1)
        {
            Work workTemp = works[0];

            works.RemoveAt(0); 
            works.Add(workTemp);
            DataContext = this; // BindGrid
        }
    }

1 个答案:

答案 0 :(得分:0)

很难设定效果,你需要这样做。我认为在您的情况下,GridView行是自动生成的。因此,当您修改数据源时,行将相应地更改。

删除数据源中的项目,快速退出。在行删除或卸载时设置动画是不可能的,因为它几乎可以立即从列表中消失。 我建议做的是:

1-暂停行以删除。 (在这种情况下更容易,因为没有循环)。

2-在xaml或后面的代码中调用故事板,如你所愿...

3-等待Storyboard.Completed事件,然后调用works.RemoveAt(...)。

所以你会:

void Timer2_Click(object sender, EventArgs e)
{
    #region ListBox Remove And Effect / in Process
    if (works.Count > 1)
    {
        //Work workTemp = works[0];  //Don't know if really needed
          var fade = new DoubleAnimation()
          {
             From = 1,
             To = 0,
             Duration = TimeSpan.FromSeconds(5),
          };
       var item = //TheListBox.Items[];
       Storyboard.SetTarget(fade, item);
       Storyboard.SetTargetProperty(fade,
                                    new PropertyPath(ListBoxItem.OpacityProperty));

       var sb = new Storyboard();
       sb.Children.Add(fade);
       sb.Completed += sb_Completed;
       sb.Begin(); 

    }
}


    void sb_Completed(object sender, EventArgs e)
    {
         works.RemoveAt(0); 
         //works.Add(workTemp);  //Don't know if really needed
         DataContext = this; // BindGrid --Is that correct to define the context each time you click ? :(
    }

让我知道它是否适合你。