コード例 #1
0
        /// <summary>
        ///		Añade / selecciona un panel
        /// </summary>
        public void AddPane(string id, string header, UserControl control, object tag = null, DockPosition position = DockPosition.Bottom)
        {
            DockLayoutDocument previous = GetDocument(id);

            if (previous != null)
            {
                previous.LayoutContent.IsActive = true;
                ActiveDocument = previous;
            }
            else
            {
                LayoutAnchorGroup layoutGroup = GetGroupPane(Layout, position);
                LayoutAnchorable  layoutPane  = new LayoutAnchorable {
                    Title = header, ToolTip = header
                };

                // Añade el contenido
                layoutPane.Content   = control;
                layoutPane.ContentId = id;
                // Añade el contenido al grupo
                layoutGroup.Children.Add(layoutPane);
                layoutPane.IsActive  = true;
                layoutPane.IsVisible = true;
                // Asigna los parámetros del grupo
                layoutPane.FloatingHeight = 400;
                layoutPane.FloatingWidth  = 400;
                // Añade el panel a la lista de documentos del controlador
                AddDocument(id, header, DockLayoutDocument.DocumentType.Panel, layoutPane, control, tag);
            }
        }
コード例 #2
0
 /// <summary>
 ///		Lanza el evento de cambio de documento
 /// </summary>
 private void RaiseEventChangeDocument(DockLayoutDocument document)
 {
     if (document != null && (document.LayoutContent?.IsActive ?? false))
     {
         ActiveDocumentChanged?.Invoke(this, EventArgs.Empty);
     }
 }
コード例 #3
0
        /// <summary>
        ///		Añade / selecciona un documento
        /// </summary>
        public void AddDocument(string id, string header, UserControl control, object tag = null)
        {
            DockLayoutDocument previous = GetDocument(id);

            if (previous != null)
            {
                previous.LayoutContent.IsActive = true;
                ActiveDocument = previous;
            }
            else
            {
                LayoutDocumentPane documentPane   = Layout.Descendents().OfType <LayoutDocumentPane>().FirstOrDefault();
                LayoutDocument     layoutDocument = new LayoutDocument {
                    Title = header, ToolTip = header
                };

                // Crea un documento y le asigna el control de contenido
                if (documentPane != null)
                {
                    // Asigna el control
                    layoutDocument.Content   = control;
                    layoutDocument.ContentId = id;
                    // Añade el nuevo LayoutDocument al array existente
                    documentPane.Children.Add(layoutDocument);
                    // Activa el documento
                    layoutDocument.IsActive   = true;
                    layoutDocument.IsSelected = true;
                    // Cambia el foco al control
                    control.Focus();
                    // Añade el documento al controlador
                    AddDocument(id, header, DockLayoutDocument.DocumentType.Document, layoutDocument, control, tag);
                }
            }
        }
コード例 #4
0
        /// <summary>
        ///		Añade un documento al control o lo selecciona
        /// </summary>
        private void AddDocument(string id, string header, DockLayoutDocument.DocumentType type,
                                 LayoutContent layoutContent, UserControl userControl, object tag = null)
        {
            DockLayoutDocument document = new DockLayoutDocument(id, header, type, layoutContent, userControl, tag);

            // Añade el documento al diccionario
            Documents.Add(document.Id, document);
            // Asigna los manejadores de evento a la vista
            layoutContent.Closing         += (sender, args) => args.Cancel = !TreatEventCloseForm(document);
            layoutContent.IsActiveChanged += (sender, args) => RaiseEventChangeDocument(document);
            // Activa el documento
            document.LayoutContent.IsActive = true;
            ActiveDocument = document;
        }
コード例 #5
0
        /// <summary>
        ///		Trata el evento de cierre de un documento
        /// </summary>
        private bool TreatEventCloseForm(DockLayoutDocument document)
        {
            bool canClose = true;

            // Si es un documento, antes de cerrar se pregunta a la ventana principal
            if (document.Type == DockLayoutDocument.DocumentType.Document)
            {
                ClosingEventArgs args = new ClosingEventArgs(document);

                // Llama al manejador de eventos
                Closing?.Invoke(this, args);
                // Si no se ha cancelado, se puede cerrar
                canClose = !args.Cancel;
            }
            // Si se debe cerrar, se quita del diccionario
            if (canClose && Documents.ContainsKey(document.Id))
            {
                Documents.Remove(document.Id);
            }
            // Devuelve el valor que indica si se puede cerrar el documento
            return(canClose);
        }
コード例 #6
0
 public ClosingEventArgs(DockLayoutDocument document)
 {
     Document = document;
 }