Exemplo n.º 1
0
        private void ClosePanel(PanelName name)
        {
            //logger.LogDebug($"ClosePanel - name: {name}");
            log.Trace($"{nameof(ClosePanel)}({nameof(name)}: {name})");
            var panelInstance = panelInstances.FirstOrDefault(i => i.Descriptor.Name == name);

            if (panelInstance != null)
            {
                CloseRadPane(panelInstance.RadPane);
            }
        }
Exemplo n.º 2
0
        private PanelInstance CreatePanelInstance(PanelName name, Dictionary <string, object> args)
        {
            //logger.LogDebug($"CreatePanelInstance - name: {name}");
            log.Trace($"{nameof(CreatePanelInstance)}({nameof(name)}: {name}, {nameof(args)}: {args})");
            var descriptor = panelDescritors.Single(p => p.Name.Name == name.Name);
            var view       = serviceProvider.GetService(descriptor.ViewType);

            if (!(view is FrameworkElement))
            {
                throw new ArgumentException($"The '{nameof(descriptor.ViewType)}' must be '{nameof(FrameworkElement)}'");
            }
            var radPane = new RadPane {
                Content = view, IsPinned = descriptor.IsPinned
            };
            IPanel panel;

            if (view is IPanel pa)
            {
                panel = pa;
            }
            else if (view is IPanelView vi)
            {
                panel = vi.Panel;
            }
            else
            {
                throw new NotSupportedException($"The '{nameof(descriptor.ViewType)}' must be '{nameof(IPanel)}' or '{nameof(IPanelView)}'");
            }
            var panelInstance = new PanelInstance(string.IsNullOrWhiteSpace(descriptor.Name.Key)
                                ? new GenericPanelDescriptor(name.ToString(), descriptor.ViewType, descriptor.DefaultPosition, descriptor.RemoveOnHide, descriptor.IsPinned)
                                : descriptor, panel, (FrameworkElement)view, radPane);

            panelInstances.Add(panelInstance);
            radPane.SetBinding(RadPane.TitleProperty, new Binding(nameof(panel.Title))
            {
                Source = panel
            });
            radPane.SetBinding(RadPane.HeaderProperty, new Binding(nameof(panel.Header))
            {
                Source = panel
            });
            RadDocking.SetSerializationTag(radPane, name.ToString());
            if (panel is IInitializablePanel iniPanel)
            {
                iniPanel.Initialize(name, args);
            }
            return(panelInstance);
        }
Exemplo n.º 3
0
        private void OpenPanel(PanelName name, Dictionary <string, object> args)
        {
            //logger.LogDebug($"OpenPanel - name: {name}");
            log.Trace($"{nameof(OpenPanel)}({nameof(name)}: {name}, {nameof(args)}: {args})");
            var panelInstance = panelInstances.FirstOrDefault(i => i.Descriptor.Name == name);

            if (panelInstance != null)
            {
                panelInstance.RadPane.IsHidden = false;
            }
            else
            {
                panelInstance = CreatePanelInstance(name, args);
                PositionPanel(panelInstance.RadPane, panelInstance.Descriptor.DefaultPosition);
            }
            panelInstance.RadPane.IsActive = true;
        }
Exemplo n.º 4
0
        public void AttachDocking(RadDocking docking)
        {
            //using var scope = logger.BeginScope(nameof(AttachDocking));
            log.Trace(nameof(AttachDocking));
            //logger.LogDebug("AttachDocking");
            //using (logger.BeginScope("OtroScope"))
            //{
            try
            {
                GenerateException();
            }
            catch (Exception ex)
            {
                //logger.LogError(new EventId(123, "Evento de prueba"), ex, "Mensaje de prueba", "Argumento de prueba", PanelName.Parse("Nombre@Key"));
                log.Error("Mensaje de prueba", ex);
            }
            //}
            if (this.docking != null)
            {
                throw new InvalidOperationException($"Only one RadDocking can be attached");
            }
            this.docking = docking;
            void AttachPane(PanelPosition state)
            {
                var split = new RadSplitContainer {
                    InitialPosition = (DockState)(int)state
                };
                //var pane = new RadPaneGroup { Tag = state, TabStripPlacement = Dock.Top };
                var pane = new RadPaneGroup {
                    Tag = state
                };

                RadDocking.SetSerializationTag(pane, state.ToString());
                split.Items.Add(pane);
                docking.Items.Add(split);
            }

            AttachPane(PanelPosition.DockedTop);
            AttachPane(PanelPosition.DockedBottom);
            AttachPane(PanelPosition.DockedLeft);
            AttachPane(PanelPosition.DockedRight);
            var sp = new RadSplitContainer();
            var gr = new RadPaneGroup
            {
                Tag = PanelPosition.Document,
                TabStripPlacement = Dock.Left
            };

            RadDocking.SetSerializationTag(gr, PanelPosition.Document.ToString());
            sp.Items.Add(gr);
            docking.DocumentHost        = sp;
            docking.DockingPanesFactory = new ShellDockingPanesFactory((dock, radPane) =>
            {
                //logger.LogDebug("AddPane");
                log.Trace($"{nameof(docking)}.{nameof(docking.DockingPanesFactory)}.AddPane");
                IPanelDescriptor descriptor;
                if (radPane.Content is IPanel panel)
                {
                    descriptor = panelInstances.Single(i => i.Panel == panel).Descriptor;
                }
                else if (radPane.Content is IPanelView view)
                {
                    descriptor = panelInstances.Single(i => i.Panel == view.Panel).Descriptor;
                }
                else
                {
                    throw new NotSupportedException($"The '{nameof(RadPane)}.{nameof(radPane.Content)}' must be '{nameof(IPanel)}' or '{nameof(IPanelView)}'");
                }
                PositionPanel(radPane, descriptor.DefaultPosition);
            }, (dock, item) => item is RadPane radPane ? radPane : null);
            docking.ElementLoading += (_, e) =>
            {
                //logger.LogDebug($"Dock_ElementLoading - AffectedElementSerializationTag: '{e.AffectedElementSerializationTag}'");
                log.Trace($"{nameof(docking)}.{nameof(docking.ElementLoading)} - {nameof(e.AffectedElementSerializationTag)}: {e.AffectedElementSerializationTag}");
                try
                {
                    var name = PanelName.Parse(e.AffectedElementSerializationTag);
                    if (panelDescritors.Any(p => p.Name.Name == name.Name))
                    {
                        // Element is a known panel
                        e.SetAffectedElement(CreatePanelInstance(name, e.ElementProperties.ToDictionary(p => p.Key, p => (object)p.Value)).RadPane);
                    }
                    else if (Enum.GetNames(typeof(PanelPosition)).Contains(e.AffectedElementSerializationTag) && e.AffectedElement is RadPaneGroup pane)
                    {
                        // Element is a main structural group panel
                        pane.Tag = Enum.Parse(typeof(PanelPosition), e.AffectedElementSerializationTag);
                    }
                    else
                    {
                        // Element is unknown
                        e.Cancel = true;
                    }
                }
                catch (Exception ex)
                {
                    //logger.LogError($"ERROR loading '{e.AffectedElementSerializationTag}'", ex);
                    log.Error($"ERROR loading '{e.AffectedElementSerializationTag}'", ex);
                }
            };
            docking.ElementLoaded += (_, e) =>
            {
                //logger.LogDebug($"Dock_ElementLoaded - AffectedElementSerializationTag: '{e.AffectedElementSerializationTag}'");
                log.Trace($"{nameof(docking)}.{nameof(docking.ElementLoaded)} - {nameof(e.AffectedElementSerializationTag)}: {e.AffectedElementSerializationTag}");
                if (e.AffectedElement is RadPane radPane)
                {
                    IPanel panel;
                    if (radPane.Content is IPanel pa)
                    {
                        panel = pa;
                    }
                    else if (radPane.Content is IPanelView vi)
                    {
                        panel = vi.Panel;
                    }
                    else
                    {
                        throw new NotSupportedException($"Must be '{nameof(IPanel)}' or '{nameof(IPanelView)}'");
                    }
                    radPane.SetBinding(RadPane.TitleProperty, new Binding(nameof(panel.Title))
                    {
                        Source = panel
                    });
                    radPane.SetBinding(RadPane.HeaderProperty, new Binding(nameof(panel.Header))
                    {
                        Source = panel
                    });
                }
            };
            docking.ElementLayoutSaving += (_, e) =>
            {
                //logger.LogDebug($"Dock_ElementLayoutSaving '{e.AffectedElementSerializationTag}'");
                log.Trace($"{nameof(docking)}.{nameof(docking.ElementLayoutSaving)} - {nameof(e.AffectedElementSerializationTag)}: {e.AffectedElementSerializationTag}");
                if (e.ElementProperties.ContainsKey("IsHidden") && e.ElementProperties["IsHidden"] == "True")
                {
                    e.Cancel = true;
                }
            };
            docking.Close += (s, e) =>
            {
                log.Trace($"{nameof(docking)}.{nameof(docking.Close)}");
                foreach (var radPane in e.Panes)
                {
                    var panelInstance = panelInstances.Single(i => i.View == radPane.Content);
                    if (panelInstance.Descriptor.RemoveOnHide)
                    {
                        panelInstance.RadPane.RemoveFromParent();
                        panelInstances.Remove(panelInstance);
                    }
                }
            };
        }
Exemplo n.º 5
0
 public static void OpenPanel(this IMessageBus me, PanelName name, params (string Key, object Value)[] args) => OpenPanel(me, name, args.Transform(list => new Dictionary <string, object>(list.Select(l => new KeyValuePair <string, object>(l.Key, l.Value)))));