hanlixuan 2014-09-18 09:21
浏览 1070

wpf 中 timeline和附加属性奇怪的死循环

具体是这样的,我想建一个自定义list然后里面放timeline,在自定义的list中,我增加了两个附加属性,一个是 previous一个是next,用来给timeline项增加前一个后一个双向链接附加属性,
但增加的时候,会进行死循环,不知道为什么,如果给这个集合增加别的dependencyObj对象就一点问题也没有,如果增加timeline就进入死循环,代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Collections.ObjectModel;

namespace WpfApplication21
{
///
/// MainWindow.xaml 的交互逻辑
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private List subs = new List();

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        //问题:增加control没问题,但增加doubleanimation就出错,进入死循环
        DependencyObject t;
       // t = new DoubleAnimation();
       t = new Control();

        subs.Add(t);
        int index = subs.IndexOf(t);
        if (subs.Count > 1)
        {

            DependencyObject previous = subs[index - 1];

            //建立集合元素中的链接
            SetNext(previous, t);
            SetPrevious(t, previous);
        }
    }

    public static object GetPrevious(DependencyObject obj)
    {
        return (object)obj.GetValue(PreviousProperty);
    }

    public static void SetPrevious(DependencyObject obj, object value)
    {
        obj.SetValue(PreviousProperty, value);
    }

    //上一个元素附加属性
    public static readonly DependencyProperty PreviousProperty =
        DependencyProperty.RegisterAttached("Previous", typeof(object), typeof(MainWindow), new UIPropertyMetadata(null));


    public static object GetNext(DependencyObject obj)
    {
        return (object)obj.GetValue(NextProperty);
    }
    public static void SetNext(DependencyObject obj, object value)
    {
        obj.SetValue(NextProperty, value);
    }
    //下一个元素附加属性
    public static readonly DependencyProperty NextProperty =
        DependencyProperty.RegisterAttached("Next", typeof(object), typeof(MainWindow), new UIPropertyMetadata(null));

}

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!