Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果ScatterViewItem更改其大小,则动画出现问题_C#_.net_Wpf_Animation_Pixelsense - Fatal编程技术网

C# 如果ScatterViewItem更改其大小,则动画出现问题

C# 如果ScatterViewItem更改其大小,则动画出现问题,c#,.net,wpf,animation,pixelsense,C#,.net,Wpf,Animation,Pixelsense,是根据其大小设置我的ScatterViewItem的内容。因此,我编写了一段调用情节提要的代码,以便根据ScatterViewItem的大小设置内容: private void Package_ContactDown(object sender, ContactEventArgs e) { ScatterViewItem svi = new ScatterViewItem(); svi.Orientation = 0;

是根据其大小设置我的ScatterViewItem的内容。因此,我编写了一段调用情节提要的代码,以便根据ScatterViewItem的大小设置内容:

 private void Package_ContactDown(object sender, ContactEventArgs e)
        {
            ScatterViewItem svi = new ScatterViewItem();
            svi.Orientation = 0;
            removeShadow(svi);
            svi.IsActive = true;
            PackageView view = new PackageView(sourceFile, this);
            view.setScatterViewItem(svi);
            svi.Width = 1024;
            svi.Height = 768;
            svi.Center = new Point(512, 384);
            Viewbox box = new Viewbox();
            box.Child = view;

            Viewbox boxSmall = new Viewbox();
            boxSmall.Name = "SmallLayout";
            TextBlock txt = new TextBlock();
            txt.Text = "Package of class";
            boxSmall.Child = txt;
            boxSmall.Visibility = System.Windows.Visibility.Collapsed;
            boxSmall.Opacity = 0;
            boxSmall.IsHitTestVisible = false;

            Grid g = new Grid();
            g.Children.Add(box);
            g.Children.Add(boxSmall);
            svi.Content = g;

            window.IconDisplay.Items.Add(svi);

            DoubleAnimation animation = new DoubleAnimation();
            animation.From = 0.0;
            animation.To = 1.0;
            animation.Duration = new Duration(TimeSpan.FromSeconds(3));
            animation.AutoReverse = false;

            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(animation);
            Storyboard.SetTargetName(animation, boxSmall.Name);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Viewbox.OpacityProperty));

            svi.SizeChanged += delegate(object s, SizeChangedEventArgs args)
            {
                if (args.NewSize.Width < 150 && args.NewSize.Height < 150)
                {
                    boxSmall.Visibility = System.Windows.Visibility.Visible;
                    box.Visibility = System.Windows.Visibility.Collapsed;
                    storyboard.Begin(this);
                }
            };

        }
private void Package\u ContactDown(对象发送方,ContactEventArgs e)
{
ScatterViewItem svi=新的ScatterViewItem();
svi.方向=0;
移除阴影(svi);
svi.IsActive=true;
PackageView视图=新PackageView(源文件,此文件);
view.SetCatterveItem(svi);
svi.宽度=1024;
svi.高度=768;
svi.Center=新点(512384);
Viewbox=新的Viewbox();
box.Child=视图;
Viewbox boxSmall=新的Viewbox();
boxsall.Name=“SmallLayout”;
TextBlock txt=新的TextBlock();
txt.Text=“类的包”;
boxsall.Child=txt;
boxsall.Visibility=System.Windows.Visibility.Collapsed;
不透明度=0;
boxsallow.ishitsetvisible=false;
网格g=新网格();
g、 添加(框);
g、 添加(小方框);
svi.Content=g;
window.IconDisplay.Items.Add(svi);
DoubleAnimation=新的DoubleAnimation();
动画.From=0.0;
动画.To=1.0;
animation.Duration=新的持续时间(TimeSpan.FromSeconds(3));
animation.AutoReverse=false;
情节提要情节提要=新情节提要();
故事板。儿童。添加(动画);
Storyboard.SetTargetName(动画,boxsall.Name);
Storyboard.SetTargetProperty(动画,新属性路径(Viewbox.OpacityProperty));
svi.SizeChanged+=委托(对象s、SizeChangedEventArgs args)
{
if(args.NewSize.Width<150&&args.NewSize.Height<150)
{
boxsall.Visibility=System.Windows.Visibility.Visible;
box.Visibility=System.Windows.Visibility.Collapsed;
故事板。开始(这个);
}
};
}
不幸的是,我经常遇到这样的异常:

System.InvalidOperationException was unhandled
  Message='SmallLayout' name cannot be found in the name scope of 'Prototype_Concept_2.views.DetailChooser'.
  Source=PresentationFramework
  StackTrace:
       at System.Windows.Media.Animation.Storyboard.ResolveTargetName(String targetName, INameScope nameScope, DependencyObject element)
       at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer)
       at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer)
       at System.Windows.Media.Animation.Storyboard.BeginCommon(DependencyObject containingObject, INameScope nameScope, HandoffBehavior handoffBehavior, Boolean isControllable, Int64 layer)
       at System.Windows.Media.Animation.Storyboard.Begin(FrameworkElement containingObject)
       at Prototype_Concept_2.views.DetailChooser.<>c__DisplayClass1.<Package_ContactDown>b__0(Object s, SizeChangedEventArgs args) in C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\Prototype_Concept_2\Prototype_Concept_2\views\DetailChooser.xaml.cs:line 244
       at System.Windows.SizeChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.FrameworkElement.OnRenderSizeChanged(SizeChangedInfo sizeInfo)
       at System.Windows.ContextLayoutManager.fireSizeChangedEvents()
       at System.Windows.ContextLayoutManager.UpdateLayout()
       at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
       at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at Prototype_Concept_2.App.Main() in C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\Prototype_Concept_2\Prototype_Concept_2\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
System.InvalidOperationException未处理
在“Prototype\u Concept\u 2.views.DetailChooser”的名称范围中找不到Message='SmallLayout'名称。
Source=PresentationFramework
堆栈跟踪:
位于System.Windows.Media.Animation.Storyboard.ResolveTargetName(字符串targetName、INameScope名称范围、DependencyObject元素)
在System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(时钟当前时钟、包含对象的DependencyObject、INameScope名称范围、DependencyObject父对象、字符串父对象名称、属性路径父属性路径、切换行为切换行为、混合字典时钟映射、Int64层)
在System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(时钟当前时钟、包含对象的DependencyObject、INameScope名称范围、DependencyObject父对象、字符串父对象名称、属性路径父属性路径、切换行为切换行为、混合字典时钟映射、Int64层)
位于System.Windows.Media.Animation.Storyboard.BeginCommon(DependencyObject包含对象、INameScope名称范围、切换行为切换行为、布尔值可控制、Int64层)
在System.Windows.Media.Animation.Storyboard.Begin(FrameworkElement包含对象)
在c:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\Prototype\u Concept\u 2\Prototype\u Concept\u 2\views\DetailChooser.xaml.cs第244行的Prototype\u Concept\u.views\DetailChooser
在System.Windows.SizeChangedEventArgs.InvokeeEventHandler(委托genericHandler,对象genericTarget)中
位于System.Windows.RouteDevenTargets.InvokeHandler(委托处理程序,对象目标)
位于System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,RoutedEventTargets RoutedEventTargets)
在System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs参数,布尔值重新调高)
位于System.Windows.UIElement.RaiseEventImpl(DependencyObject发送方,RoutedEventTargets参数)
在System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)处
位于System.Windows.FrameworkElement.OnRenderSizeChanged(SizeChangedInfo sizeInfo)
位于System.Windows.ContextLayoutManager.fireSizeChangedEvents()处
位于System.Windows.ContextLayoutManager.UpdateLayout()处
位于System.Windows.ContextLayoutManager.UpdateLayoutCallback(对象参数)
位于System.Windows.Media.MediaContext.InvokeRenderCallback.DoWork()处
在System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()中
位于System.Windows.Media.MediaContext.RenderMessageHandlerCore(对象大小调整的CompositionTarget)
位于System.Windows.Media.MediaContext.RenderMessageHandler(对象大小调整的CompositionTarget)
位于System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调、对象参数、布尔isSingleParameter)
位于System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源、委托回调、对象参数、布尔isSingleParameter、委托catchHandler)
位于System.Windows.Threading.Dispatcher.WrappedInvoke(委托回调、对象参数、布尔isSingleParameter、委托catchHandler)
在System.Windows.Threading.DispatcherOperation.InvokeImpl()中
位于System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(对象状态)
位于System.Threading.ExecutionContext.runTryCode(对象用户数据)
在System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode代码、CleanupCode backoutCode、Object userData)中运行
位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext,ContextCallback回调,对象状态)