Storyboard GetShrinkAnimation(AwesomMenuItem item, Point pt) { Duration duration = TimeSpan.FromSeconds(0.3); var sb = new Storyboard(); sb.Duration = duration; var keyFrams = new DoubleAnimationUsingKeyFrames(); keyFrams.Duration = duration; var keyframe = new EasingDoubleKeyFrame(); keyframe.Value = pt.X; keyframe.KeyTime = TimeSpan.FromSeconds(0.3); keyFrams.KeyFrames.Add(keyframe); Storyboard.SetTarget(keyFrams, item.ItemTransfrom); Storyboard.SetTargetProperty(keyFrams, new PropertyPath(CompositeTransform.TranslateXProperty)); sb.Children.Add(keyFrams); keyFrams = new DoubleAnimationUsingKeyFrames(); keyFrams.Duration = duration; keyframe = new EasingDoubleKeyFrame(); keyframe.Value = pt.Y; keyframe.KeyTime = TimeSpan.FromSeconds(0.3); keyFrams.KeyFrames.Add(keyframe); Storyboard.SetTarget(keyFrams, item.ItemTransfrom); Storyboard.SetTargetProperty(keyFrams, new PropertyPath(CompositeTransform.TranslateYProperty)); sb.Children.Add(keyFrams); var da = GetDoubleAnimation(duration, 0.01, 1); Storyboard.SetTarget(da, item.ItemTransfrom); Storyboard.SetTargetProperty(da, new PropertyPath(CompositeTransform.ScaleXProperty)); sb.Children.Add(da); da = GetDoubleAnimation(duration, 0.01, 1); Storyboard.SetTarget(da, item.ItemTransfrom); Storyboard.SetTargetProperty(da, new PropertyPath(CompositeTransform.ScaleYProperty)); sb.Children.Add(da); da = GetDoubleAnimation(duration, 1, 0); Storyboard.SetTarget(da, item); Storyboard.SetTargetProperty(da, new PropertyPath(UIElement.OpacityProperty)); sb.Children.Add(da); return(sb); }
private void InitAddButton(bool byPopint = false) { _addButton = new AwesomMenuItem(_addUri, _addUriHighlited); _addButton.ItemTransfrom.TranslateX = _startPoint.X; _addButton.ItemTransfrom.TranslateY = _startPoint.Y; _addButton.Tag = 999; if (byPopint) { _addButton.VerticalAlignment = VerticalAlignment.Top; _addButton.HorizontalAlignment = HorizontalAlignment.Left; } Canvas.SetZIndex(_addButton, 10); _addButton.ClickMenuItem -= Item_ClickMenuItem; _addButton.ClickMenuItem += Item_ClickMenuItem; this.Children.Add(_addButton); }
private void ProcessItem(AwesomMenuItem item) { if (item != null) { if (item != null && !item.Tag.Equals(999)) { int index = Convert.ToInt32(item.Tag); MessageBox.Show(string.Format("Item {0} Clicked!", index)); //switch (index) //{ // case 0: // MessageBox.Show(string.Format("Item {0} Clicked!", index)); // break; // case 1: // MessageBox.Show(string.Format("Item {0} Clicked!", index)); // break; // case 2: // break; //} } } }
private void Item_ClickMenuItem(AwesomMenuItem item) { if (item.Tag.Equals(_addButton.Tag)) { this.IsExpanding = !this.IsExpanding; return; } if (TapToDissmissItem) { //blowup current button Point pt = new Point(item.ItemTransfrom.TranslateX, item.ItemTransfrom.TranslateY); var blowUpStory = GetBlowUpAnimation(item, pt); blowUpStory.Begin(); blowUpStory.Completed += (o, a) => { item.ItemTransfrom.TranslateX = _startPoint.X; item.ItemTransfrom.TranslateY = _startPoint.Y; item.ItemTransfrom.ScaleX = 1; item.ItemTransfrom.ScaleY = 1; item.Opacity = 1; blowUpStory.Stop(); blowUpStory.Children.Clear(); blowUpStory = null; }; foreach (var otherItem in MenuItems) { if (item != otherItem) { Point p = new Point(otherItem.ItemTransfrom.TranslateX, otherItem.ItemTransfrom.TranslateY); var shrinkStory = GetShrinkAnimation(otherItem, p); shrinkStory.Begin(); shrinkStory.Completed += (o, a) => { otherItem.ItemTransfrom.TranslateX = _startPoint.X; otherItem.ItemTransfrom.TranslateY = _startPoint.Y; otherItem.ItemTransfrom.ScaleX = 1; otherItem.ItemTransfrom.ScaleY = 1; otherItem.Opacity = 1; shrinkStory.Stop(); shrinkStory.Children.Clear(); shrinkStory = null; }; } } _isExpanding = false; //收起做的动画 //弧度 double angle = this.IsExpanding ? -Math.PI / 4 : 0; //角度 angle = angle * 180; Duration duration = TimeSpan.FromSeconds(0.5); _addButton.RenderTransformOrigin = new Point(0.5, 0.5); var da = GetDoubleAnimation(duration, _addButton.ItemTransfrom.Rotation, angle); var sb = new Storyboard(); //sb.Duration = duration; Storyboard.SetTarget(da, _addButton.ItemTransfrom); Storyboard.SetTargetProperty(da, new PropertyPath(CompositeTransform.RotationProperty)); sb.Children.Add(da); sb.Begin(); sb.Completed += (o, a) => { sb.Stop(); _addButton.ItemTransfrom.Rotation = angle; sb.Children.Clear(); sb = null; }; } if (ActionClosed != null) { ActionClosed(item); } //if (ActionDisMiss != null) // ActionDisMiss(this, Convert.ToInt32(item.Tag)); }
private void Close() { if (_flag < 0) { _timer.Stop(); _timer = null; return; } int tag = _flag; AwesomMenuItem item = null; //if (tag >= MenuItems.Count) //{ // item = _addButton; //} //else //item = MenuItems[tag]; if (tag - 1 < 0) { return; } item = MenuItems[tag - 1]; Duration duration = TimeSpan.FromSeconds(0.5); var sb = new Storyboard(); sb.Duration = duration; var da = new DoubleAnimationUsingKeyFrames(); da.Duration = duration; var keyframe = new EasingDoubleKeyFrame(); keyframe.Value = 0; keyframe.KeyTime = TimeSpan.FromSeconds(0.0); da.KeyFrames.Add(keyframe); keyframe = new EasingDoubleKeyFrame(); keyframe.Value = 180; keyframe.KeyTime = TimeSpan.FromSeconds(0.25); da.KeyFrames.Add(keyframe); keyframe = new EasingDoubleKeyFrame(); keyframe.Value = 0; keyframe.KeyTime = TimeSpan.FromSeconds(0.5); da.KeyFrames.Add(keyframe); Storyboard.SetTarget(da, item.ItemTransfrom); Storyboard.SetTargetProperty(da, new PropertyPath(CompositeTransform.RotationProperty)); sb.Children.Add(da); da = new DoubleAnimationUsingKeyFrames(); da.Duration = duration; keyframe = new EasingDoubleKeyFrame(); keyframe.Value = item.EndPoint.X; keyframe.KeyTime = TimeSpan.FromSeconds(0); da.KeyFrames.Add(keyframe); keyframe = new EasingDoubleKeyFrame(); keyframe.Value = item.FarPoint.X; keyframe.KeyTime = TimeSpan.FromSeconds(0.25); da.KeyFrames.Add(keyframe); keyframe = new EasingDoubleKeyFrame(); keyframe.Value = item.StratPoint.X; keyframe.KeyTime = TimeSpan.FromSeconds(0.5); da.KeyFrames.Add(keyframe); Storyboard.SetTarget(da, item.ItemTransfrom); Storyboard.SetTargetProperty(da, new PropertyPath(CompositeTransform.TranslateXProperty)); sb.Children.Add(da); da = new DoubleAnimationUsingKeyFrames(); da.Duration = duration; keyframe = new EasingDoubleKeyFrame(); keyframe.Value = item.EndPoint.Y; keyframe.KeyTime = TimeSpan.FromSeconds(0); da.KeyFrames.Add(keyframe); keyframe = new EasingDoubleKeyFrame(); keyframe.Value = item.FarPoint.Y; keyframe.KeyTime = TimeSpan.FromSeconds(0.25); da.KeyFrames.Add(keyframe); keyframe = new EasingDoubleKeyFrame(); keyframe.Value = item.StratPoint.Y; keyframe.KeyTime = TimeSpan.FromSeconds(0.5); da.KeyFrames.Add(keyframe); Storyboard.SetTarget(da, item.ItemTransfrom); Storyboard.SetTargetProperty(da, new PropertyPath(CompositeTransform.TranslateYProperty)); sb.Children.Add(da); sb.Begin(); sb.Completed += (o, a) => { item.ItemTransfrom.TranslateX = item.StratPoint.X; item.ItemTransfrom.TranslateY = item.StratPoint.Y; item.ItemTransfrom.Rotation = 0; sb.Stop(); sb.Children.Clear(); da = null; sb = null; if (ActionClosed != null) { if (_closedByTapMenu == true) { _closedByTapMenu = false; ActionClosed(null); } else { ActionClosed(_addButton); } } }; _flag--; }
private void Item_ClickMenuItem(AwesomMenuItem item) { if (item.Tag.Equals(_addButton.Tag)) { this.IsExpanding = !this.IsExpanding; return; } if (TapToDissmissItem) { //blowup current button Point pt = new Point(item.ItemTransfrom.TranslateX, item.ItemTransfrom.TranslateY); var blowUpStory = GetBlowUpAnimation(item, pt); blowUpStory.Begin(); blowUpStory.Completed += (o, a) => { item.ItemTransfrom.TranslateX = _startPoint.X; item.ItemTransfrom.TranslateY = _startPoint.Y; item.ItemTransfrom.ScaleX = 1; item.ItemTransfrom.ScaleY = 1; item.Opacity = 1; blowUpStory.Stop(); blowUpStory.Children.Clear(); blowUpStory = null; }; foreach (var otherItem in MenuItems) { if (item != otherItem) { Point p = new Point(otherItem.ItemTransfrom.TranslateX, otherItem.ItemTransfrom.TranslateY); var shrinkStory = GetShrinkAnimation(otherItem, p); shrinkStory.Begin(); shrinkStory.Completed += (o, a) => { otherItem.ItemTransfrom.TranslateX = _startPoint.X; otherItem.ItemTransfrom.TranslateY = _startPoint.Y; otherItem.ItemTransfrom.ScaleX = 1; otherItem.ItemTransfrom.ScaleY = 1; otherItem.Opacity = 1; shrinkStory.Stop(); shrinkStory.Children.Clear(); shrinkStory = null; }; } } _isExpanding = false; //收起做的动画 //弧度 double angle = this.IsExpanding ? -Math.PI / 4 : 0; //角度 angle = angle * 180; Duration duration = TimeSpan.FromSeconds(0.5); _addButton.RenderTransformOrigin = new Point(0.5, 0.5); var da = GetDoubleAnimation(duration, _addButton.ItemTransfrom.Rotation, angle); var sb = new Storyboard(); //sb.Duration = duration; Storyboard.SetTarget(da, _addButton.ItemTransfrom); Storyboard.SetTargetProperty(da, new PropertyPath(CompositeTransform.RotationProperty)); sb.Children.Add(da); sb.Begin(); sb.Completed += (o, a) => { sb.Stop(); _addButton.ItemTransfrom.Rotation = angle; sb.Children.Clear(); sb = null; }; } if (ActionClosed != null) ActionClosed(item); //if (ActionDisMiss != null) // ActionDisMiss(this, Convert.ToInt32(item.Tag)); }
Storyboard GetShrinkAnimation(AwesomMenuItem item, Point pt) { Duration duration = TimeSpan.FromSeconds(0.3); var sb = new Storyboard(); sb.Duration = duration; var keyFrams = new DoubleAnimationUsingKeyFrames(); keyFrams.Duration = duration; var keyframe = new EasingDoubleKeyFrame(); keyframe.Value = pt.X; keyframe.KeyTime = TimeSpan.FromSeconds(0.3); keyFrams.KeyFrames.Add(keyframe); Storyboard.SetTarget(keyFrams, item.ItemTransfrom); Storyboard.SetTargetProperty(keyFrams, new PropertyPath(CompositeTransform.TranslateXProperty)); sb.Children.Add(keyFrams); keyFrams = new DoubleAnimationUsingKeyFrames(); keyFrams.Duration = duration; keyframe = new EasingDoubleKeyFrame(); keyframe.Value = pt.Y; keyframe.KeyTime = TimeSpan.FromSeconds(0.3); keyFrams.KeyFrames.Add(keyframe); Storyboard.SetTarget(keyFrams, item.ItemTransfrom); Storyboard.SetTargetProperty(keyFrams, new PropertyPath(CompositeTransform.TranslateYProperty)); sb.Children.Add(keyFrams); var da = GetDoubleAnimation(duration, 0.01, 1); Storyboard.SetTarget(da, item.ItemTransfrom); Storyboard.SetTargetProperty(da, new PropertyPath(CompositeTransform.ScaleXProperty)); sb.Children.Add(da); da = GetDoubleAnimation(duration, 0.01, 1); Storyboard.SetTarget(da, item.ItemTransfrom); Storyboard.SetTargetProperty(da, new PropertyPath(CompositeTransform.ScaleYProperty)); sb.Children.Add(da); da = GetDoubleAnimation(duration, 1, 0); Storyboard.SetTarget(da, item); Storyboard.SetTargetProperty(da, new PropertyPath(UIElement.OpacityProperty)); sb.Children.Add(da); return sb; }