internal void AnimateElementTopLeft(FrameworkElement el, double left, double top) { // Create a storyboard to contain the animation. Storyboard story = new Storyboard(); // Create a name scope for the page. NameScope.SetNameScope(el, new NameScope()); var ms = new MarginSurrogate(el); // Register the name with the page to which the element belongs. el.RegisterName("surrogate", ms); Duration dur = new Duration(TimeSpan.FromMilliseconds(500)); if (el.Margin.Top != top) { Anim2Point(story, dur, "surrogate", MarginSurrogate.TopProperty, el.Margin.Top, top); } if (el.Margin.Left != left) { Anim2Point(story, dur, "surrogate", MarginSurrogate.LeftProperty, el.Margin.Left, left); } story.Begin(el); }
internal void AnimateElementLocation(FrameworkElement el, Thickness newLocation) { // don't take updates until the change is committed, the animation lasts 500ms waitUpdates = DateTime.Now.AddMilliseconds(750); // Create a storyboard to contain the animation. Storyboard story = new Storyboard(); // Create a name scope for the page. NameScope.SetNameScope(el, new NameScope()); var ms = new MarginSurrogate(el); // Register the name with the page to which the element belongs. el.RegisterName("surrogate", ms); Duration dur = new Duration(TimeSpan.FromMilliseconds(500)); if (el.Margin.Top != newLocation.Top) { Anim2Point(story, dur, "surrogate", MarginSurrogate.TopProperty, el.Margin.Top, newLocation.Top); } if (el.Margin.Left != newLocation.Left) { Anim2Point(story, dur, "surrogate", MarginSurrogate.LeftProperty, el.Margin.Left, newLocation.Left); } story.Completed += new EventHandler( (object sender2, EventArgs e2) => { // the end is ragged, it's not accurate to get the bounding box in position at this time // I have to wait for at least one paint to settle so I just wait 100ms and then grab the stuff // this is really pretty terrible because Story should be done now... if I don't do this // then the bounding box doesn't match and worse yet the save can happen before it's really done! Main.DelayAction(100, () => { SaveFrameworkElement(el); if (selectedList == null) { selectedList = new List <FrameworkElement>(); } if (selectedListBoxes == null) { selectedListBoxes = new List <FrameworkElement>(); } selectedList.Add(el); selectedListBoxes.Add(AddBoundingRectangleForElement(el, animate: true)); }); }); story.Begin(el); }
static void OnLeftChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { MarginSurrogate control = (MarginSurrogate)obj; control.LeftChanged((double)args.NewValue); }