コード例 #1
0
        public override void OnApplyTemplate()
        {
            if (_button != null)
            {
                _button.Click -= OnClick;
            }

            base.OnApplyTemplate();

            _root = MoreVisualTreeExtensions.FindFirstChildOfType <Grid>(this);
            if (null == _root)
            {
                throw new NotSupportedException("Must include a Grid for manipulating.");
            }

            _button = GetTemplateChild("_button") as Button;
            if (_button != null)
            {
                _button.Click += OnClick;
            }

            TransformAnimator.EnsureAnimator(_root, ref _ta);
            OpacityAnimator.EnsureAnimator(_root, ref _oa);
            if (_oa != null)
            {
                _root.Opacity = 0;
                _oa.GoTo(1.0, new Duration(TimeSpan.FromSeconds(.5)));
            }
        }
コード例 #2
0
 /// <summary>
 /// Ensures and creates if needed the animator for an element. Will also
 /// verify that a translate transform is present.
 /// </summary>
 /// <param name="targetElement">The target element.</param>
 /// <param name="animator">The animator reference.</param>
 public static void EnsureAnimator(UIElement targetElement, ref OpacityAnimator animator)
 {
     if (animator == null)
     {
         animator = new OpacityAnimator(targetElement);
     }
     if (animator == null)
     {
         throw new InvalidOperationException("The animation system could not be prepared for the target element.");
     }
 }
コード例 #3
0
 public void ApplyTemplate(DataTemplate template, bool animateIn)
 {
     if (Presenter != null)
     {
         Presenter.ContentTemplate = template;
         if (animateIn)
         {
             Presenter.Opacity = 0;
             OpacityAnimator oa = null;
             OpacityAnimator.EnsureAnimator(Presenter, ref oa);
             if (oa != null)
             {
                 oa.GoTo(1.0, new Duration(TimeSpan.FromSeconds(.75)));
             }
         }
         Presenter.Content = Content;
         _shown            = true;
     }
 }
コード例 #4
0
 /// <summary>
 /// Ensures and creates if needed the animator for an element. Will also
 /// verify that a translate transform is present.
 /// </summary>
 /// <param name="targetElement">The target element.</param>
 /// <param name="animator">The animator reference.</param>
 public static void EnsureAnimator(UIElement targetElement, ref OpacityAnimator animator)
 {
     if (animator == null)
     {
         animator = new OpacityAnimator(targetElement);
     }
     if (animator == null)
     {
         throw new InvalidOperationException("The animation system could not be prepared for the target element.");
     }
 }
コード例 #5
0
        private static void HandleCompletion(PendingCompletion pendingCompletion)
        {
            // fadeClear, clearFade, clear, fadeRemoveSiblings are all specific
            // side effects that met my needs when building 4th & Mayor. At
            // this time I'm keeping these around.

            var bitmap = new BitmapImage();

            try
            {
                bitmap.SetSource(pendingCompletion.Stream);
                pendingCompletion.Image.Source = bitmap;
                var tag = pendingCompletion.Image.Tag as string;

                if (tag != null && tag == "clear")
                {
                    var img = pendingCompletion.Image;
                    ClearParentBackground(img);
                }
                else if (tag != null && (tag == "fadeClear" || tag == "clearFade"))
                {
                    var             img = pendingCompletion.Image;
                    OpacityAnimator oa  = null;
                    OpacityAnimator.EnsureAnimator(img, ref oa);
                    if (img != null)
                    {
                        img.Opacity = 0;
                        oa.GoTo(1.0, new Duration(TimeSpan.FromSeconds(1)), () =>
                        {
                            ClearParentBackground(img);
                            oa = null;
                        });
                    }
                }
                else if (tag != null && tag == "fadeRemoveSiblings")
                {
                    // Specialized for badge display.
                    var             img = pendingCompletion.Image;
                    OpacityAnimator oa  = null;
                    OpacityAnimator.EnsureAnimator(img, ref oa);
                    if (img != null)
                    {
                        img.Opacity = 0;
                        oa.GoTo(1.0, new Duration(TimeSpan.FromSeconds(1)), () =>
                        {
                            ClearNonImageSiblings(img);
                            oa = null;
                        });
                    }
                }
            }
            catch (Exception)
            {
                // Ignore image decode exceptions (ex: invalid image)
                // TODO: Consider what to do here.
                //QuietWatson.ReportException(ex);
            }
            finally
            {
                // Dispose of response stream
                if (pendingCompletion.Stream != null)
                {
                    pendingCompletion.Stream.Dispose();
                }
            }
        }