Exemplo n.º 1
0
        private void RenderGroup()
        {
            TitleTextBlock.Text = Title;
            DescriptionTextBlock.Text = Description;

            var descriptors = new List<CommandDescriptor>();

            foreach (var command in StartPageManager.Commands)
            {
                if (command.Attribute.ParentName != ParentName)
                {
                    continue;
                }

                descriptors.Add(new CommandDescriptor(command.Command, command.Attribute));
            }

            foreach (var cmd in CommandManager.Commands)
            {
                var command = cmd as IStartPageCommand;
                if (command == null)
                {
                    continue;
                }

                var attributes = command.GetType().GetCustomAttributes(typeof(StartPageCommandAttribute), false);
                if (attributes.Length == 0)
                {
                    continue;
                }

                foreach (var attribute in attributes.OfType<StartPageCommandAttribute>())
                {
                    if (attribute.ParentName != ParentName)
                    {
                        continue;
                    }

                    descriptors.Add(new CommandDescriptor(command, attribute));
                }
            }

            if (descriptors.Count == 0)
            {
                return;
            }

            descriptors.Sort((d1, d2) => d1.Attribute.Priority == d2.Attribute.Priority ? string.Compare(d1.Attribute.Text, d2.Attribute.Text, StringComparison.InvariantCultureIgnoreCase) : d1.Attribute.Priority >= d2.Attribute.Priority ? 1 : -1);

            foreach (var descriptor in descriptors)
            {
                var textBlock = new TextBlock
                {
                    FontSize = 12,
                    Margin = new Thickness(0, 2, 0, 0)
                };

                var hyperlink = new Hyperlink();
                hyperlink.Inlines.Add(descriptor.Attribute.Text);
                textBlock.Inlines.Add(hyperlink);

                var d = descriptor;
                hyperlink.Click += (sender, args) => Execute(d);

                // hyperlink.Foreground = descriptor.Command.CanExecute(context) ? StartPageViewer.EnabledLink : StartPageViewer.DisabledLink;
                List.Children.Add(textBlock);

                StartPage.AddHyperlink(descriptor.Command, hyperlink);
            }
        }