2011-01-31 29 views
0

My ideaは、サイズに応じてScatterViewItemのコンテンツを設定することでした。だから私は、コンテンツがScatterViewItemのサイズにdependeing設定されているように、ストーリーボードを呼び出すコードの一部を書いた: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); 
       } 
      }; 

     } 

残念ながら、私はこの例外を取得alawys:

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: 

私はしないでください本当に問題を理解する。何かヒント?

答えて

1

それはあなたがDetailChooser要素の中にSmallLayoutという名前の子を持っていないと言っています

関連する問題