我正在使用 blend 4 制作 wpf 应用程序
我在 xaml 中定义了一个 wrapPanel:
<WrapPanel x:Name="WrapPanel_ShowMe">
当我进入某种视觉状态时,wrapPanel 后面的代码到一个新位置:
WrapPanel_ShowMe.RenderTransform = new TranslateTransform(0,-661.5);
我这样做是因为在这种状态下,不同的 wrapPanels 可以出现在状态中,(为了避免复制状态)
退出该状态后,我将面板移回其原始位置。
我在其他州也有相同的 wrapPanel 被 xaml 移动:
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="WrapPanel_ShowMe">
<EasingDoubleKeyFrame KeyTime="0" Value="-648"/>
</DoubleAnimationUsingKeyFrames>
所以状态 A 在 c# 中移动 wrapPanel,状态 B 使用 xaml 移动面板。
当我使用状态 B 时,wrapPanel 会毫无问题地移动。(xml)
当我使用状态 A 时,wrapPanel 会毫无问题地移动。(C#)
当我使用状态 A 移动面板然后尝试使用状态 B 后记时,就会出现问题。程序崩溃了,我不知道为什么。似乎在使用代码隐藏移动对象后,xaml 渲染转换不再有效?
谁能告诉我为什么会这样以及如何解决/解决它?
提前致谢
编辑
堆栈结果如下:
Unhandled Exception: System.InvalidOperationException: 'Children' property value in the path '(0).(1)[3].(2)' points to immutable instance of 'System.Windows.Media.TransformCollection'.
at System.Windows.Media.Animation.Storyboard.VerifyPathIsAnimatable(PropertyPath path)
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.VisualStateGroup.StartNewThenStopOld(FrameworkElement element, Storyboard[] newStoryboards)
at System.Windows.VisualStateManager.GoToStateInternal(FrameworkElement control, FrameworkElement stateGroupsRoot, VisualStateGroup group, VisualState state, Boolean useTransitions)
at Microsoft.Expression.Interactivity.Core.ExtendedVisualStateManager.TransitionEffectAwareGoToStateCore(FrameworkElement control, FrameworkElement stateGroupsRoot, String stateName, VisualStateGroup group, VisualState state, Boolean useTransitions, VisualTransition transition, Boolean animateWithTransitionEffect, VisualState previousState)
at Microsoft.Expression.Interactivity.Core.ExtendedVisualStateManager.GoToStateCore(FrameworkElement control, FrameworkElement stateGroupsRoot, String stateName, VisualStateGroup group, VisualState state, Boolean useTransitions)
at System.Windows.VisualStateManager.GoToStateCommon(FrameworkElement control, FrameworkElement stateGroupsRoot, String stateName, Boolean useTransitions)
at Microsoft.Expression.Interactivity.VisualStateUtilities.GoToState(FrameworkElement element, String stateName, Boolean useTransitions)
at System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(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, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
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.Application.RunInternal(Window window)
at System.Windows.Application.Run()
at TrailerUnitNewTutor_1.App.Main() in c:\Users\Domnick\Documents\Expression\Blend 4\Projects\TrailerUnitNewTutor_1\TrailerUnitNewTutor_1\obj\Debug\App.g.cs:line 0