示例#1
0
        static void CreateDragAdorner()
        {
            DataTemplate template = GetDragAdornerTemplate(m_DragInfo.VisualSource);
            Point        offset   = GetDragAdornerOffset(m_DragInfo.VisualSource);
            double       opacity  = GetDragAdornerOpacity(m_DragInfo.VisualSource);

            if (template != null)
            {
                // Find current active window
                UIElement rootElement = null;
                if (Application.Current.Windows.Count == 1)
                {
                    rootElement = (UIElement)Application.Current.MainWindow.Content;
                }
                else
                {
                    foreach (var w in Application.Current.Windows)
                    {
                        if ((w as Window).IsActive)
                        {
                            rootElement = (UIElement)(w as Window).Content;
                            break;
                        }
                    }
                }
                if (rootElement == null)
                {
                    throw new ApplicationException("No active window found to adorn");
                }

                UIElement adornment = null;

                if (m_DragInfo.Data is IEnumerable && !(m_DragInfo.Data is string))
                {
                    if (((IEnumerable)m_DragInfo.Data).Cast <object>().Count() <= 10)
                    {
                        ItemsControl itemsControl = new ItemsControl();
                        itemsControl.ItemsSource  = (IEnumerable)m_DragInfo.Data;
                        itemsControl.ItemTemplate = template;

                        // The ItemsControl doesn't display unless we create a border to contain it.
                        // Not quite sure why this is...
                        Border border = new Border();
                        border.Child = itemsControl;
                        adornment    = border;
                    }
                }
                else
                {
                    ContentPresenter contentPresenter = new ContentPresenter();
                    contentPresenter.Content         = m_DragInfo.Data;
                    contentPresenter.ContentTemplate = template;
                    adornment = contentPresenter;
                }

                if (adornment != null)
                {
                    adornment.Opacity = 0.5;
                    DragAdorner       = new DragAdorner(rootElement, adornment);

                    if (offset != null)
                    {
                        DragAdorner.Offset = offset;
                    }
                    if (opacity != 0)
                    {
                        DragAdorner.Opacity = opacity;
                    }
                }
            }
        }
示例#2
0
        static void CreateDragAdorner()
        {
            DataTemplate template = GetDragAdornerTemplate(m_DragInfo.VisualSource);
            Point offset = GetDragAdornerOffset(m_DragInfo.VisualSource);
            double opacity = GetDragAdornerOpacity(m_DragInfo.VisualSource);

            if (template != null)
            {
                // Find current active window
                UIElement rootElement = null;
                if (Application.Current.Windows.Count == 1)
                {
                    rootElement = (UIElement)Application.Current.MainWindow.Content;
                }
                else
                {
                    foreach (var w in Application.Current.Windows)
                        if ((w as Window).IsActive)
                        {
                            rootElement = (UIElement)(w as Window).Content;
                            break;
                        }
                }
                if (rootElement == null)
                    throw new ApplicationException("No active window found to adorn");

                UIElement adornment = null;

                if (m_DragInfo.Data is IEnumerable && !(m_DragInfo.Data is string))
                {
                    if (((IEnumerable)m_DragInfo.Data).Cast<object>().Count() <= 10)
                    {
                        ItemsControl itemsControl = new ItemsControl();
                        itemsControl.ItemsSource = (IEnumerable)m_DragInfo.Data;
                        itemsControl.ItemTemplate = template;

                        // The ItemsControl doesn't display unless we create a border to contain it.
                        // Not quite sure why this is...
                        Border border = new Border();
                        border.Child = itemsControl;
                        adornment = border;
                    }
                }
                else
                {
                    ContentPresenter contentPresenter = new ContentPresenter();
                    contentPresenter.Content = m_DragInfo.Data;
                    contentPresenter.ContentTemplate = template;
                    adornment = contentPresenter;
                }

                if (adornment != null)
                {
                    adornment.Opacity = 0.5;
                    DragAdorner = new DragAdorner(rootElement, adornment);

                    if (offset != null)
                        DragAdorner.Offset = offset;
                    if (opacity != 0)
                        DragAdorner.Opacity = opacity;
                }
            }
        }