后面代码中的DataTemplate的NameScope [英] NameScope for DataTemplate in code behind

查看:66
本文介绍了后面代码中的DataTemplate的NameScope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在后面的代码中创建ListView的ItemTemplate.我创建了一个Storyboard,并尝试使用DataTrigger启动Storyboard.一切正常,直到DataTriggers调用BeginStoryboard().比我得到的例外

I try to create the ItemTemplate of a ListView in code behind. The I create a Storyboard and with an DataTrigger I try to start my Storyboard. Everything is fine until the DataTriggers calls BeginStoryboard(). Than I get The Exception

在"System.Windows.DataTemplate"的名称范围中找不到"AnimatedRotateTransform"名称.

'AnimatedRotateTransform' name cannot be found in the name scope of 'System.Windows.DataTemplate'.

所以我的问题是如何获取DataTemplate的NameScope.我认为我的Storyboard ist在我的控件的NameScope中.这是我的代码的一部分:

So my question ist how to get the NameScope for the DataTemplate. I think my Storyboard ist in the NameScope of my Control. Here is a part of my code:

       private DataTemplate CreateDataTemplate()
        {
            NameScope.SetNameScope(thisnew NameScope());
 
            DataTemplate workPieceTemplate = new DataTemplate();
            FrameworkElementFactory baseGrid = new FrameworkElementFactory(typeof(Grid));
 
            baseGrid.SetBinding(Grid.WidthProperty, new Binding("width"));
            baseGrid.SetBinding(Grid.HeightProperty, new Binding("length"));
            baseGrid.SetValue(Grid.MarginProperty, new Thickness(2));
            baseGrid.SetValue(Grid.RenderTransformOriginProperty, new Point(0.5, 0.5));
 
            TransformGroup tg = new TransformGroup();
            RotateTransform rt = new RotateTransform();
            workPieceTemplate.RegisterName("AnimatedRotateTransform", rt);
            tg.Children.Add(rt);
            baseGrid.SetValue(Grid.RenderTransformProperty, tg);
 
            FrameworkElementFactory rect = new FrameworkElementFactory(typeof(Rectangle));
            rect.SetValue(Rectangle.FillProperty, Brushes.Wheat);
            rect.SetValue(Rectangle.StrokeThicknessProperty, 1.0);
            rect.SetValue(Rectangle.StrokeProperty, Brushes.Black);
 
            baseGrid.AppendChild(rect);
 
            Storyboard pathAnimation = new Storyboard();
            pathAnimation.AutoReverse = false;
 
            // Pfad für Transformation winkel
            DoubleAnimationUsingPath rotateAnimation = new DoubleAnimationUsingPath();
            rotateAnimation.Duration = TimeSpan.FromSeconds(20);
            rotateAnimation.Source = PathAnimationSource.Angle;
            rotateAnimation.PathGeometry = _PathGeometry;
 
            Storyboard.SetTargetName(rotateAnimation, "AnimatedRotateTransform");
 
            Storyboard.SetTargetProperty(rotateAnimation, new PropertyPath(RotateTransform.AngleProperty));
 
            pathAnimation.Children.Add(rotateAnimation);
 
            #region Trigger für IsInMachine
 
            DataTrigger triggerIsInMachine = new DataTrigger();
            Binding isInMachineBinding = new Binding("IsInMachine");
            triggerIsInMachine.Binding = isInMachineBinding;
            triggerIsInMachine.Value = true;
 
            triggerIsInMachine.EnterActions.Add(new BeginStoryboard() { Storyboard = pathAnimation });
 
            workPieceTemplate.Triggers.Add(triggerIsInMachine);
 
            #endregion
            return workPieceTemplate;
        }

推荐答案

 

我花了一些时间尝试用代码片段编写演示,但未能解决您的问题

 

I spent some time on trying to compose a demo with your code snippets but failed to repro your problem.

我们在这里需要一些其他信息来确定正在发生的事情.您能否提供有关您的问题的更多详细信息?如果您可以提供一个简单的现成的运行方式,将不胜感激. 为我们提供样品.您可以将其上传到SkyDrive空间并在此处发布链接.

We need some additional information here to be able to determine what is going on. Could you kindly offer more details about your issue? It would be appreciated if you could offer a simple ready-to-run sample for us. You could upload it to SkyDrive space and post a link here.

 

谢谢!愿意帮助您!

 

最好的问候


这篇关于后面代码中的DataTemplate的NameScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆