/// <summary>
        /// Displays content in a window
        /// </summary>
        /// <param name="windowTitle">Title text shown in window</param>
        /// <param name="windowContents">Contents of the window</param>        
        /// <param name="isModal">Determines wheter the window is modal or not</param>
        /// <param name="onClosingHandler">Event handler invoked when window is closing, and can be handled to cancel window closure</param>
        /// <param name="windowType">The type of the window</param>
        /// <param name="onClosedHandler">Event handler invoked when window is closed</param>
        /// <param name="top">The distance from the top of the application at which to position the window</param>
        /// <param name="left">The distance from the left of the application at which to position the window</param>
        /// <returns>The window</returns>
        public object ShowWindow(string windowTitle, FrameworkElement windowContents, bool isModal = false, 
            EventHandler<CancelEventArgs> onClosingHandler = null, EventHandler onClosedHandler = null, 
            WindowType windowType = WindowType.Floating, double? top = null, double? left = null)            
        {                        
            if (windowContents == null)
                throw new ArgumentNullException("windowContents");

            int hashCode = windowContents.GetHashCode();
            FloatingWindow floatingWindow = null;
            if (!m_FloatingWindows.TryGetValue(hashCode, out floatingWindow))
            {
                // not existing yet
                floatingWindow = new FloatingWindow()
                {
                    Title = windowTitle ?? string.Empty,
                };

                switch (windowType)
                {
                    case WindowType.Floating:
                if (FloatingWindowStyle != null)
                    floatingWindow.Style = FloatingWindowStyle;
                        break;
                    case WindowType.DesignTimeFloating:
                        if (DesignTimeWindowStyle != null)
                            floatingWindow.Style = DesignTimeWindowStyle;
                        else if (FloatingWindowStyle != null) // fallback to FloatingWindowStyle
                            floatingWindow.Style = FloatingWindowStyle;
                        break;
                }

                floatingWindow.Closed += (o, e) =>
                {
                    if (onClosedHandler != null)
                        onClosedHandler.Invoke(o, e);

                    m_FloatingWindows.Remove(hashCode);

                    if (floatingWindow != null)
                        floatingWindow.Content = null;
                };

                if (onClosingHandler != null)
                    floatingWindow.Closing += onClosingHandler;
                floatingWindow.Content = windowContents;
                m_FloatingWindows.Add(hashCode, floatingWindow);
            }


            if (top != null)
                floatingWindow.VerticalOffset = (double)top;

            if (left != null)
                floatingWindow.HorizontalOffset = (double)left;

            floatingWindow.Show(isModal);

            return floatingWindow;
        }
Esempio n. 2
0
        /// <summary>
        /// Executed when the a key is presses when the window is open.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Key event args.</param>
        private void ChildWindow_KeyDown(object sender, KeyEventArgs e)
        {
            FloatingWindow ew = sender as FloatingWindow;

            Debug.Assert(ew != null, "FloatableWindow instance is null.");

            // Ctrl+Shift+F4 closes the FloatableWindow
            if (e != null && !e.Handled && e.Key == Key.F4 &&
                ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) &&
                ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift))
            {
                ew.Hide();
                e.Handled = true;
            }
        }
        public void Execute(object parameter)
        {
            if (!string.IsNullOrWhiteSpace(StyleName) && AttachmentEditorStyle == null)
                return;

            FeatureLayer layer = GetFeatureLayer(parameter);
            if (layer == null)
                return;

            Graphic graphic = layer.SelectedGraphics != null ? layer.SelectedGraphics.ElementAt(0) : null;
            if (graphic == null)
                return;

            if (_configuration == null)
                _configuration = new AttachmentEditorConfiguration();

            if (_attachmentEditor == null)
            {
                _attachmentEditor = new AttachmentEditor();
                _attachmentEditor.Width = _configuration.Width;
                _attachmentEditor.Height = _configuration.Height;
                _attachmentEditor.FilterIndex = _configuration.FilterIndex;
                _attachmentEditor.Filter = _configuration.Filter;
                _attachmentEditor.Multiselect = _configuration.MultiSelect;
                if(AttachmentEditorStyle != null)
                    _attachmentEditor.Style = AttachmentEditorStyle;

                _window = new FloatingWindow();
                _window.Content = _attachmentEditor;
                _window.Title = Resources.Strings.AttachmentEditorHeader;
            }

            _attachmentEditor.DataContext = _configuration;
            _attachmentEditor.GraphicSource = null;
            _attachmentEditor.FeatureLayer = null;
            if (graphic != null)
            {
                _attachmentEditor.FeatureLayer = layer;
                _attachmentEditor.GraphicSource = graphic;
                _window.Show(true);
            }
        }