Beispiel #1
0
 public static Image ToImage(this UIElement element)
 {
     return(new Image()
     {
         Source = UIExtensions.ToImageSource(element)
     });
 }
Beispiel #2
0
        private static void OnAllowEnhancedDropChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            UIElement uiElement1 = (UIElement)obj;

            if (uiElement1 == null)
            {
                return;
            }
            UIElement uiElement2 = (UIElement)UIExtensions.GetParent((DependencyObject)uiElement1);

            if (uiElement2 == null)
            {
                return;
            }
            if ((bool)args.OldValue)
            {
                uiElement2.RemoveHandler(UIElement.DragEnterEvent, (Delegate) new DragEventHandler(Advent.Common.UI.DragDrop.ParentDragEnter));
                uiElement1.RemoveHandler(UIElement.DragOverEvent, (Delegate) new DragEventHandler(Advent.Common.UI.DragDrop.ElementDragOver));
                uiElement1.PreviewDragLeave         -= new DragEventHandler(Advent.Common.UI.DragDrop.ElementPreviewDragLeave);
                uiElement1.PreviewDrop              -= new DragEventHandler(Advent.Common.UI.DragDrop.ElementPreviewDrop);
                uiElement1.PreviewQueryContinueDrag -= new QueryContinueDragEventHandler(Advent.Common.UI.DragDrop.ElementPreviewQueryContinueDrag);
                Advent.Common.UI.DragDrop.dragElements.Remove(uiElement1);
            }
            if (!(bool)args.NewValue)
            {
                return;
            }
            uiElement2.AddHandler(UIElement.DragEnterEvent, (Delegate) new DragEventHandler(Advent.Common.UI.DragDrop.ParentDragEnter), true);
            uiElement1.AddHandler(UIElement.DragOverEvent, (Delegate) new DragEventHandler(Advent.Common.UI.DragDrop.ElementDragOver), true);
            uiElement1.PreviewDragLeave         += new DragEventHandler(Advent.Common.UI.DragDrop.ElementPreviewDragLeave);
            uiElement1.PreviewDrop              += new DragEventHandler(Advent.Common.UI.DragDrop.ElementPreviewDrop);
            uiElement1.PreviewQueryContinueDrag += new QueryContinueDragEventHandler(Advent.Common.UI.DragDrop.ElementPreviewQueryContinueDrag);
            Advent.Common.UI.DragDrop.dragElements.Add(uiElement1);
        }
Beispiel #3
0
 public WindowPreview(FrameworkElement destination, IntPtr sourceHandle)
 {
     this.sourceHandle = sourceHandle;
     this.window       = UIExtensions.GetAncestor <Window>((DependencyObject)destination);
     Marshal.ThrowExceptionForHR(Advent.Common.Interop.NativeMethods.DwmRegisterThumbnail(new WindowInteropHelper(this.window).Handle, sourceHandle, ref this.thumbnailHandle));
     this.Destination           = destination;
     this.opacity               = 1.0;
     this.clientAreaOnly        = false;
     this.isVisible             = false;
     destination.LayoutUpdated += new EventHandler(this.Destination_LayoutUpdated);
 }
Beispiel #4
0
        public static bool IsDescendantOf(this DependencyObject child, DependencyObject ancestor)
        {
            DependencyObject parent = VisualTreeHelper.GetParent(child);

            if (parent == null)
            {
                return(false);
            }
            if (parent == ancestor)
            {
                return(true);
            }
            else
            {
                return(UIExtensions.IsDescendantOf(parent, ancestor));
            }
        }
Beispiel #5
0
        public static T GetAncestor <T>(this DependencyObject child) where T : DependencyObject
        {
            DependencyObject parent = VisualTreeHelper.GetParent(child);

            if (parent == null)
            {
                return(default(T));
            }
            T obj = parent as T;

            if ((object)obj != null)
            {
                return(obj);
            }
            else
            {
                return(UIExtensions.GetAncestor <T>(parent));
            }
        }
Beispiel #6
0
        private static void ParentDragEnter(object sender, DragEventArgs e)
        {
            if (e.OriginalSource != Advent.Common.UI.DragDrop.dragEnterOriginalSource)
            {
                Advent.Common.UI.DragDrop.dragEnterOriginalSource = e.OriginalSource;
                Advent.Common.UI.DragDrop.isDragEnterHandled      = false;
            }
            if (Advent.Common.UI.DragDrop.isDragEnterHandled)
            {
                return;
            }
            UIElement uiElement1 = (UIElement)null;

            foreach (UIElement uiElement2 in Advent.Common.UI.DragDrop.dragElements)
            {
                if (uiElement2.IsAncestorOf((DependencyObject)e.OriginalSource) && VisualTreeHelper.GetParent((DependencyObject)uiElement2) == sender)
                {
                    uiElement1 = uiElement2;
                    break;
                }
            }
            if (uiElement1 == null)
            {
                return;
            }
            Window ancestor           = UIExtensions.GetAncestor <Window>((DependencyObject)uiElement1);
            string descriptionMessage = Advent.Common.UI.DragDrop.GetDropDescription((DependencyObject)uiElement1);

            if (descriptionMessage != null)
            {
                descriptionMessage = descriptionMessage.Replace("{0}", "%1");
            }
            uiElement1.SetValue(Advent.Common.UI.DragDrop.IsDropOverPropertyKey, (object)true);
            DataObjectExtensions.DragEnter(ancestor, e.Data, Mouse.GetPosition((IInputElement)ancestor), e.Effects, descriptionMessage, Advent.Common.UI.DragDrop.GetDropDescriptionInsert((DependencyObject)uiElement1));
            Advent.Common.UI.DragDrop.isDragEnterHandled = true;
        }
Beispiel #7
0
 private static void ElementDragOver(object sender, DragEventArgs e)
 {
     DataObjectExtensions.DragOver(Mouse.GetPosition((IInputElement)UIExtensions.GetAncestor <Window>((DependencyObject)sender)), e.Effects);
 }
Beispiel #8
0
 private static void ElementPreviewDrop(object sender, DragEventArgs e)
 {
     ((DependencyObject)sender).SetValue(Advent.Common.UI.DragDrop.IsDropOverPropertyKey, (object)false);
     DataObjectExtensions.Drop(e.Data, Mouse.GetPosition((IInputElement)UIExtensions.GetAncestor <Window>((DependencyObject)sender)), e.Effects);
     Advent.Common.UI.DragDrop.dragEnterOriginalSource = (object)null;
 }