Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6224405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:39:59+00:00 2026-05-24T08:39:59+00:00

I’m a newbie in WPF. I implemented fullscreen app with grids that could be

  • 0

I’m a newbie in WPF. I implemented fullscreen app with grids that could be moved over by mouse (drag’n’drop style). If the grid control arrears out of the screen bounds it returns to its default state with simple animation. The problem is when grid returns it could be moved any more! Some code snippets provided:

public partial class MenuCard : UserControl, ITouchObject, INotifyPropertyChanged
{
    ...
    public static readonly DependencyProperty XProperty =
        DependencyProperty.Register("X", typeof(double), typeof(MenuCard), new UIPropertyMetadata(0.0, OnPosXChanged, CourceXValue));
    ...
    private static void OnPosXChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var owner = (MenuCard) d;
        Grid rootGrid = (Grid)Application.Current.MainWindow.FindName("rootGrid");
        Point actual = owner.TransformToAncestor(rootGrid).Transform(new Point(owner.X, owner.Y));
        Point topLeft = owner.TransformToAncestor(rootGrid).Transform(new Point(0, 0));
        Point bottomRight = owner.TransformToAncestor(rootGrid).Transform(new Point(owner.ActualWidth, owner.ActualHeight));

        if (actual.X + (bottomRight.X - topLeft.X) <= border || actual.X >= SystemParameters.PrimaryScreenWidth - border)
        {
            ReturnToDefault(owner);
        }
    }
    ...
    private static void ReturnToDefault(MenuCard owner)
    {
        DoubleAnimation yAnimation = new DoubleAnimation();
        yAnimation.From = owner.Y;
        yAnimation.DecelerationRatio = 0.5;
        yAnimation.To = (double)YProperty.DefaultMetadata.DefaultValue;
        owner.BeginAnimation(MenuCard.YProperty, yAnimation);

        DoubleAnimation xAnimation = new DoubleAnimation();
        xAnimation.From = owner.X;
        xAnimation.DecelerationRatio = 0.5;
        xAnimation.To = (double)XProperty.DefaultMetadata.DefaultValue;
        owner.BeginAnimation(MenuCard.XProperty, xAnimation);
    }
}

Main class:

public partial class MainWindow : Window
{

    private void CanvasManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        var p = GetSender(e.ManipulationContainer as FrameworkElement);     
        if (p != null)
        {
            ManipulationDelta md = e.DeltaManipulation;
            p.X += md.Translation.X;
            p.Y += md.Translation.Y;
            p.Angle += md.Rotation;
            p.ScaleX *= md.Scale.X;
            p.ScaleY *= md.Scale.Y;
        }
        e.Handled = true;
    }

    private ITouchObject GetSender(FrameworkElement element)
    {
        while (true)
        {
            if (element.Parent == null)
            {
                return null;
            }
            if (element is ITouchObject)
            {
                return element as ITouchObject;
            }
            element = element.Parent as FrameworkElement;
        }
    }
}

I have no ideas. Any help would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:40:00+00:00Added an answer on May 24, 2026 at 8:40 am

    make sure to add the FillBehavior property to all animations…

    xAnimation.FillBehavior = FillBehavior.Stop;

    This may result you the grid taken back to the same position where it is before animation…

    You can handle this at the end of animation be setting the property manually..

    some thing like this

    Here you are giving To value to animation…

    yAnimation.To = (double)YProperty.DefaultMetadata.DefaultValue;

    at the end of the animation you set the same value directly…

    MenuCard.YProperty = (double)YProperty.DefaultMetadata.DefaultValue;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.