1

im using blend 4 to make a wpf application

i have a wrapPanel defined in xaml:

<WrapPanel x:Name="WrapPanel_ShowMe">

when i enter a certain visual state, the code-behind the wrapPanel to a new location:

WrapPanel_ShowMe.RenderTransform = new TranslateTransform(0,-661.5);

im doing it this way because in this state different wrapPanels can appear in the state, (to save from duplicating the state)

after i exit the state, i move the panel back to its origional location.

I also have the same wrapPanel being moved by xaml in other states:

<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="WrapPanel_ShowMe">
    <EasingDoubleKeyFrame KeyTime="0" Value="-648"/>
</DoubleAnimationUsingKeyFrames>

so state A moves the wrapPanel in c#, and State B moves the panel using xaml.

When i use state B, the wrapPanel moves like it should with no problems. (xaml)

When i use state A, the wrapPanel moves like it should with no problems. (c#)

the problem occurs when i use state A to move the panel and THEN try to use state B afterwords. The program crashes, and I have no idea why. It seems that after using the code-behind to move the object, the xaml render transform is no longer valid?

can anyone tell me why this might be and how to fix/get around it?

Thanks in advance

EDIT

the stack results are as follows:

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
Domnick Sharkey
  • 65
  • 1
  • 2
  • 7

1 Answers1

0

Your XAML and code-behind are constructing two different RenderTransforms. I'm assuming from your XAML Storyboard that the WrapPanel.RenderTransform looks something like this:

<WrapPanel.RenderTransform>
    <TransformGroup>
        <ScaleTransform/>
        <SkewTransform/>
        <RotateTransform/>
        <TranslateTransform/>
    </TransformGroup>
</WrapPanel.RenderTransform>

And the RenderTransform that you are creating in code would look like this in XAML:

<WrapPanel.RenderTransform>
    <TranslateTransform/>
</WrapPanel.RenderTransform>

The easiest way to fix this would be to set the RenderTransform in XAML to how it is being set in code, that is, assuming you don't use the other transforms. If that doesn't work then in code, create a Storyboard that sets the TranslateTransform at time zero.

evanb
  • 3,061
  • 20
  • 32
  • i see what you mean. changing the code behind to reflect the xaml format didnt work, neither did changing the xaml, but i use transformations elsewhere so it doesnt matter. i think ill have to use the storyboards, thanks. – Domnick Sharkey Jun 26 '12 at 08:55
  • @DomnickSharkey Glad I could help. Please mark it as the answer if it if it answered your question. – evanb Jun 26 '12 at 21:43
  • i tried using a storyboard instead, it didnt work, still the same problem, any other ideas? thanks – Domnick Sharkey Jun 27 '12 at 08:12
  • @DomnickSharkey you get the same error? Unhandled Exception: System.InvalidOperationException: 'Children' property value in the path '(0).(1)[3].(2)' points to immutable instance of 'System.Windows.Media.TransformCollection'. – evanb Jun 27 '12 at 17:27
  • yeah exact same one. i think i found out why though. render transform is 'freezable' so i cant alter the content after its frozen by the render transform, same as with storyboards. – Domnick Sharkey Jun 28 '12 at 09:25