RadWindow Top Animation

3 posts, 0 answers
  1. mg
    mg avatar
    4 posts
    Member since:
    Oct 2012

    Posted 10 May 2013 Link to this post

    Hello,

    I am trying to animate the position of a RadWindow using a DataTrigger.

    The following demonstrates what I am trying to achieve:

    <telerik:RadWindow x:Class="TelerikRadWindow.MainWindow"
            Height="350"
            Width="525"
            WindowStartupLocation="CenterScreen">
        <telerik:RadWindow.Style>
            <Style TargetType="telerik:RadWindow">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ShouldMoveWindow}" Value="True">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="(Window.Top)" To="+200" BeginTime="0:0:0" Duration="0:0:5" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </telerik:RadWindow.Style>
    </telerik:RadWindow>

    namespace TelerikRadWindow
    {
        public partial class MainWindow
        {
            public MainWindow()
            {
                InitializeComponent();
                ShouldMoveWindow = true;
                DataContext = this;
            }
     
            public bool ShouldMoveWindow { get; set; }
        }
    }

    When loaded, an exception is thrown:

    System.Windows.Media.Animation.AnimationException was unhandled
      HResult=-2146233087
      Message=Cannot animate the 'Top' property on a 'TelerikRadWindow.MainWindow' using a 'System.Windows.Media.Animation.DoubleAnimation'. For details see the inner exception.
      Source=PresentationCore
      StackTrace:
           at System.Windows.Media.Animation.AnimationStorage.OnCurrentTimeInvalidated(Object sender, EventArgs args)
           at System.Windows.Media.Animation.Clock.FireEvent(EventPrivateKey key)
           at System.Windows.Media.Animation.Clock.RaiseAccumulatedEvents()
           at System.Windows.Media.Animation.TimeManager.RaiseEnqueuedEvents()
           at System.Windows.Media.Animation.TimeManager.Tick()
           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, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.DispatcherOperation.InvokeImpl()
           at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           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, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(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.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 TelerikRadWindow.App.Main() in c:\Users\martin.galpin\Documents\Visual Studio 2012\Projects\TelerikRadWindow\TelerikRadWindow\obj\Debug\App.g.cs:line 0
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.InvalidOperationException
           HResult=-2146233079
           Message='System.Windows.Media.Animation.DoubleAnimation' cannot use default origin value of 'NaN'.
           Source=PresentationCore
           StackTrace:
                at System.Windows.Media.Animation.DoubleAnimation.GetCurrentValueCore(Double defaultOriginValue, Double defaultDestinationValue, AnimationClock animationClock)
                at System.Windows.Media.Animation.DoubleAnimationBase.GetCurrentValue(Double defaultOriginValue, Double defaultDestinationValue, AnimationClock animationClock)
                at System.Windows.Media.Animation.DoubleAnimationBase.GetCurrentValue(Object defaultOriginValue, Object defaultDestinationValue, AnimationClock animationClock)
                at System.Windows.Media.Animation.AnimationClock.GetCurrentValue(Object defaultOriginValue, Object defaultDestinationValue)
                at System.Windows.Media.Animation.AnimationLayer.GetCurrentValue(Object defaultDestinationValue)
                at System.Windows.Media.Animation.AnimationStorage.GetCurrentPropertyValue(AnimationStorage storage, DependencyObject d, DependencyProperty dp, PropertyMetadata metadata, Object baseValue)
                at System.Windows.Media.Animation.AnimationStorage.OnCurrentTimeInvalidated(Object sender, EventArgs args)
           InnerException:

    This exact same sample works when using a Window rather than a RadWindow.

    Does anybody have any idea why this is or what I can do to resolve it?

    Many thanks.




  2. mg
    mg avatar
    4 posts
    Member since:
    Oct 2012

    Posted 13 May 2013 Link to this post

    Setting the target property to (telerik:RadWindow.Top) allows you to animate the window position.
  3. UI for WPF is Visual Studio 2017 Ready
  4. MobiusStrip
    MobiusStrip avatar
    5 posts
    Member since:
    Dec 2010

    Posted 26 Jul 2013 Link to this post

    For anyone else who comes here and wants to animate the position of the radWindow....

    Note that you must also supply a Storyboard.TargetName.


    So, in the <telerik.RadWindow section, supply a name
    <telerik.RadWindow 
       x:Name="This"
       x:Class="...

    and in the Storyboard point to "This" as the TargetName

    <DoubleAnimation x:Name="MoveWIndowTop" Storyboard.TargetProperty="(telerik.RadWindow.Top)"
                                  Storyboard.TargetName="This" To="100"...

    (Giving the DoubleAnimation a x:Name value allows you to move the window around programatically in the code behind.)

        Me.MoveWindowTop.To = "500"
        Me.MoveWIndow.Begin()      

    (That worked for me, somebody else may know how to avoid code behind to achieve the same, but without the TargetName I was crashing when I tried to fire the storyboard script.)

    -dave
Back to Top