private void ActivateModule(ActivateModuleMessage obj) { var currentModule = _moduleContainer.Content as IModule; if (currentModule != null) { currentModule.IsActive = false; } RunTransitionAnimation(obj); obj.Module.IsActive = true; _bus.SendMessage(new ModuleActivatedMessage(obj.Module, obj.ParentModule)); }
private void RunTransitionAnimation(ActivateModuleMessage obj) { var direction = Direction.Left; var oldContent = _moduleContainer.Content as UIElement; var oldModule = oldContent as IModule; if (oldModule != null) { direction = _model.ModuleDirectionRelativeTo(oldModule, obj.Module); } var gridColumn = direction == Direction.Right ? 0 : 2; if (oldContent != null) { _moduleContainer.Content = null; _animationGrid.Children.Add(oldContent); Grid.SetColumn(oldContent, gridColumn); } _animationGrid.ColumnDefinitions[gridColumn].Width = new GridLength(1, GridUnitType.Star); _animationGrid.Margin = direction == Direction.Right ? new Thickness(0, 0, -ActualWidth, 0) : new Thickness(-ActualWidth, 0, 0, 0); _animationGrid.RenderTransform = _xform; var animation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetName(animation, "_xform"); Storyboard.SetTargetProperty(animation, new PropertyPath(TranslateTransform.XProperty)); animation.Duration = TimeSpan.FromSeconds(0.16); if (direction == Direction.Right) { animation.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromPercent(0))); animation.KeyFrames.Add(new EasingDoubleKeyFrame(-ActualWidth, KeyTime.FromPercent(1.0))); } else { animation.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromPercent(0))); animation.KeyFrames.Add(new EasingDoubleKeyFrame(ActualWidth, KeyTime.FromPercent(1.0))); } var sb = new Storyboard(); sb.Children.Add(animation); animation.Completed += (sender, args) => { _animationGrid.Children.Remove(oldContent); _animationGrid.ColumnDefinitions[gridColumn].Width = new GridLength(0, GridUnitType.Star); _animationGrid.RenderTransform = null; _animationGrid.Margin = new Thickness(0, 0, 0, 0); }; _moduleContainer.Content = obj.Module.Visual; sb.Begin(_animationGrid); }