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条回答

    报告相同问题?

    悬赏问题

    • ¥100 有人会搭建GPT-J-6B框架吗?有偿
    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名