Esempio n. 1
0
        internal static object CreateToolBarItemContent(Codon codon)
        {
            object result  = null;
            Image  image   = null;
            Label  label   = null;
            bool   isImage = false;
            bool   isLabel = false;

            if (codon.Properties.Contains("icon"))
            {
                image        = new Image();
                image.Source = PresentationResourceService.GetBitmapSource(StringParser.Parse(codon.Properties["icon"]));
                image.Height = 16;
                image.SetResourceReference(FrameworkElement.StyleProperty, ToolBarService.ImageStyleKey);
                isImage = true;
            }
            if (codon.Properties.Contains("label"))
            {
                label         = new Label();
                label.Content = StringParser.Parse(codon.Properties["label"]);
                label.Padding = new Thickness(0);
                label.VerticalContentAlignment = VerticalAlignment.Center;
                isLabel = true;
            }

            if (isImage && isLabel)
            {
                StackPanel panel = new StackPanel();
                panel.Orientation = Orientation.Horizontal;
                image.Margin      = new Thickness(0, 0, 5, 0);
                panel.Children.Add(image);
                panel.Children.Add(label);
                result = panel;
            }
            else
            if (isImage)
            {
                result = image;
            }
            else
            if (isLabel)
            {
                result = label;
            }
            else
            {
                result = codon.Id;
            }

            if (!(result is StackPanel) && !(result is Image))
            {
                TryApplyMaterialStyle((ContentControl)result);
            }

            return(result);
        }
Esempio n. 2
0
        public CoreMenuItem(Codon codon, object caller)
        {
            this.codon  = codon;
            this.caller = caller;

            if (codon.Properties.Contains("icon"))
            {
                try {
                    var image = PresentationResourceService.GetImage(codon.Properties["icon"]);
                    image.Height = 16;
                    this.Icon    = image;
                } catch (ResourceNotFoundException) {}
            }
            UpdateText();
        }
        public CoreMenuItem(Codon codon, object caller, IReadOnlyCollection <ICondition> conditions)
        {
            this.codon      = codon;
            this.caller     = caller;
            this.conditions = conditions;

            if (codon.Properties.Contains("icon"))
            {
                try {
                    var image = new Image();
                    image.Source = PresentationResourceService.GetBitmapSource(codon.Properties["icon"]);
                    image.Height = 16;
                    this.Icon    = image;
                } catch (ResourceNotFoundException) {}
            }
            UpdateText();
        }
Esempio n. 4
0
        public ToolBarButton(Codon codon, object caller, bool createCommand)
        {
            ToolTipService.SetShowOnDisabled(this, true);

            this.codon   = codon;
            this.caller  = caller;
            this.Command = new CommandWrapper(codon, caller, createCommand);

            if (codon.Properties.Contains("icon"))
            {
                var image = PresentationResourceService.GetImage(StringParser.Parse(codon.Properties["icon"]));
                image.Height = 16;
                image.SetResourceReference(StyleProperty, ToolBarService.ImageStyleKey);
                this.Content = new PixelSnapper(image);
            }
            UpdateText();

            SetResourceReference(FrameworkElement.StyleProperty, ToolBar.ButtonStyleKey);
        }
        public ToolBarSplitButton(Codon codon, object caller, IList submenu)
        {
            ToolTipService.SetShowOnDisabled(this, true);

            this.codon  = codon;
            this.caller = caller;

            if (codon.Properties.Contains("icon"))
            {
                var image = PresentationResourceService.GetImage(StringParser.Parse(codon.Properties["icon"]));
                image.Height = 16;
                image.SetResourceReference(StyleProperty, ToolBarService.ImageStyleKey);
                this.Content = new PixelSnapper(image);
            }

            menuCommand       = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]);
            menuCommand.Owner = this;

            this.Command      = new CommandWrapper(codon, caller, menuCommand);
            this.DropDownMenu = MenuService.CreateContextMenu(submenu);

            UpdateText();
        }
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     return(PresentationResourceService.GetBitmapSource(key));
 }
Esempio n. 7
0
        public CoreMenuItem(Codon codon, object caller, IReadOnlyCollection <ICondition> conditions)
        {
            this.codon      = codon;
            this.caller     = caller;
            this.conditions = conditions;

            if (codon.Properties.Contains("template"))
            {
                this.Template = Application.Current.FindResource("MenuItemTemplateKey") as ControlTemplate;
                this.ApplyTemplate();
            }
            else
            {
                if (codon.Properties.Contains("packIconKey"))
                {
                    string[] packIconValues = codon.Properties["packIconKey"].Split(';');
                    string   packIconType   = packIconValues[0];
                    string   packIconKind   = packIconValues[1];
                    //object icon = null;

                    switch (packIconType)
                    {
                    case "PackIconMaterial":
                        var icon = new PackIconMaterial();
                        ((PackIconMaterial)icon).Kind = (PackIconMaterialKind)Enum
                                                        .Parse(typeof(PackIconMaterialKind),
                                                               packIconKind);
                        this.Icon = icon;
                        break;

                    case "PackIconMaterialLight":
                        var icon1 = new PackIconMaterialLight();
                        ((PackIconMaterialLight)icon1).Kind = (PackIconMaterialLightKind)Enum
                                                              .Parse(typeof(PackIconMaterialLightKind),
                                                                     packIconKind);
                        this.Icon = icon1;
                        break;

                    case "PackIconModern":
                        var icon2 = new PackIconModern();
                        ((PackIconModern)icon2).Kind = (PackIconModernKind)Enum
                                                       .Parse(typeof(PackIconModernKind),
                                                              packIconKind);
                        this.Icon = icon2;
                        break;

                    case "PackIconOcticons":
                        var icon3 = new PackIconOcticons();
                        ((PackIconOcticons)icon3).Kind = (PackIconOcticonsKind)Enum
                                                         .Parse(typeof(PackIconOcticonsKind),
                                                                packIconKind);
                        this.Icon = icon3;
                        break;

                    case "PackIconSimpleIcons":
                        var icon4 = new PackIconSimpleIcons();
                        ((PackIconSimpleIcons)icon4).Kind = (PackIconSimpleIconsKind)Enum
                                                            .Parse(typeof(PackIconSimpleIconsKind),
                                                                   packIconKind);
                        this.Icon = icon4;
                        break;

                    case "PackIconEntypo":
                        var icon5 = new PackIconEntypo();
                        ((PackIconEntypo)icon5).Kind = (PackIconEntypoKind)Enum
                                                       .Parse(typeof(PackIconEntypoKind),
                                                              packIconKind);
                        this.Icon = icon5;
                        break;

                    case "PackIconFontAwesome":
                        var icon6 = new PackIconFontAwesome();
                        ((PackIconFontAwesome)icon6).Kind = (PackIconFontAwesomeKind)Enum
                                                            .Parse(typeof(PackIconFontAwesomeKind),
                                                                   packIconKind);
                        this.Icon = icon6;
                        break;
                    }
                    //this.Icon = icon;
                }
                else
                {
                    if (codon.Properties.Contains("icon"))
                    {
                        try {
                            var image = new Image();
                            image.Source = PresentationResourceService.GetBitmapSource(codon.Properties["icon"]);
                            image.Height = 16;
                            this.Icon    = image;
                        } catch (ResourceNotFoundException) {}
                    }
                }
            }

            if (codon.Properties.Contains("style"))
            {
                Style customStyle = Application.Current.TryFindResource("MenuItemStyleKey") as Style;

                if (customStyle != null)
                {
                    this.Style = customStyle;
                    this.UpdateLayout();
                }
            }
            else
            {
                //if (codon.Properties.Contains("packIconKey")) { //Apply material theme if PackIcon theme is used
                Style matStyle = Application.Current.TryFindResource("MaterialDesignMenuItem") as Style;
                if (matStyle != null)
                {
                    this.Style = matStyle;
                }
                //}
            }

            UpdateText();
        }
Esempio n. 8
0
        public static void CreateTemplatedToolBarItem(Control control, Codon codon)
        {
            if (codon.Properties.Contains("template"))
            {
                ControlTemplate customTemplate = (ControlTemplate)Application
                                                 .Current
                                                 .TryFindResource(codon.Properties["template"]);

                if (customTemplate != null)
                {
                    control.Template = customTemplate;
                    control.ApplyTemplate();
                }
            }
            else
            {
                if (codon.Properties.Contains("packIconKey"))
                {
                    string[] packIconValues = codon.Properties["packIconKey"].Split(';');
                    string   packIconType   = packIconValues[0];
                    string   packIconKind   = packIconValues[1];
                    //PackIconBase icon = null;
                    object Icon = null;

                    switch (packIconType)
                    {
                    case "PackIconMaterial":
                        var icon = new PackIconMaterial();
                        ((PackIconMaterial)icon).Kind = (PackIconMaterialKind)Enum
                                                        .Parse(typeof(PackIconMaterialKind),
                                                               packIconKind);
                        Icon = icon;
                        break;

                    case "PackIconMaterialLight":
                        var icon1 = new PackIconMaterialLight();
                        ((PackIconMaterialLight)icon1).Kind = (PackIconMaterialLightKind)Enum
                                                              .Parse(typeof(PackIconMaterialLightKind),
                                                                     packIconKind);
                        Icon = icon1;
                        break;

                    case "PackIconModern":
                        var icon2 = new PackIconModern();
                        ((PackIconModern)icon2).Kind = (PackIconModernKind)Enum
                                                       .Parse(typeof(PackIconModernKind),
                                                              packIconKind);
                        Icon = icon2;
                        break;

                    case "PackIconOcticons":
                        var icon3 = new PackIconOcticons();
                        ((PackIconOcticons)icon3).Kind = (PackIconOcticonsKind)Enum
                                                         .Parse(typeof(PackIconOcticonsKind),
                                                                packIconKind);
                        Icon = icon3;
                        break;

                    case "PackIconSimpleIcons":
                        var icon4 = new PackIconSimpleIcons();
                        ((PackIconSimpleIcons)icon4).Kind = (PackIconSimpleIconsKind)Enum
                                                            .Parse(typeof(PackIconSimpleIconsKind),
                                                                   packIconKind);
                        Icon = icon4;
                        break;

                    case "PackIconEntypo":
                        var icon5 = new PackIconEntypo();
                        ((PackIconEntypo)icon5).Kind = (PackIconEntypoKind)Enum
                                                       .Parse(typeof(PackIconEntypoKind),
                                                              packIconKind);
                        Icon = icon5;
                        break;

                    case "PackIconFontAwesome":
                        var icon6 = new PackIconFontAwesome();
                        ((PackIconFontAwesome)icon6).Kind = (PackIconFontAwesomeKind)Enum
                                                            .Parse(typeof(PackIconFontAwesomeKind),
                                                                   packIconKind);
                        Icon = icon6;
                        break;
                    }

                    if (control is MenuItem)
                    {
                        (control as MenuItem).Header = Icon;
                    }
                    else if (control is MahApps.Metro.Controls.DropDownButton)
                    {
                        (control as MahApps.Metro.Controls.DropDownButton).Content = Icon;
                    }
                    else if (control is MahApps.Metro.Controls.SplitButton)
                    {
                        (control as MahApps.Metro.Controls.SplitButton).Icon = Icon;
                    }
                    else
                    {
                        (control as ContentControl).Content = Icon;
                    }
                }

                if (codon.Properties.Contains("icon"))
                {
                    Image image = new Image();
                    image.Source = PresentationResourceService.GetBitmapSource(StringParser.Parse(codon.Properties["icon"]));
                    image.Height = 16;
                    image.SetResourceReference(FrameworkElement.StyleProperty, ToolBarService.ImageStyleKey);

                    if (control is MenuItem)
                    {
                        (control as MenuItem).Header = image;
                    }
                    else if (control is MahApps.Metro.Controls.DropDownButton)
                    {
                        (control as MahApps.Metro.Controls.DropDownButton).Content = image;
                    }
                    else if (control is MahApps.Metro.Controls.SplitButton)
                    {
                        (control as MahApps.Metro.Controls.SplitButton).Icon = image;
                    }
                    else
                    {
                        (control as ContentControl).Content = image;
                    }
                }

                if (codon.Properties.Contains("label"))
                {
                    Label label = new Label();
                    label.Content = StringParser.Parse(codon.Properties["label"]);
                    label.Padding = new Thickness(0);
                    label.VerticalContentAlignment = VerticalAlignment.Center;

                    if (control is MenuItem)
                    {
                        (control as MenuItem).Header = label;
                    }
                    else if (control is MahApps.Metro.Controls.DropDownButton)
                    {
                        (control as MahApps.Metro.Controls.DropDownButton).Content = label;
                    }
                    else if (control is MahApps.Metro.Controls.SplitButton)
                    {
                        (control as MahApps.Metro.Controls.SplitButton).Icon = label;
                    }
                    else
                    {
                        (control as ContentControl).Content = label;
                    }
                }
            }

            if (codon.Properties.Contains("style"))
            {
                Style customStyle = Application.Current.TryFindResource(codon.Properties["style"]) as Style;

                if (customStyle != null)
                {
                    control.Style = customStyle;
                }
            }
            else
            {
                if (control is MenuItem)
                {
                    Style menuStyle = Application.Current.TryFindResource("MaterialDesignMenuItem") as Style;
                    if (menuStyle != null)
                    {
                        control.Style = menuStyle;
                    }
                }
                else if (control is MahApps.Metro.Controls.DropDownButton)
                {
                    Style  btnStyle = new Style();
                    Setter fg       = new Setter();
                    Setter bg       = new Setter();

//					Style btnStyle = Application.Current.TryFindResource("MaterialDesignToolForegroundButton") as Style;
                    bg.Property = MahApps.Metro.Controls.DropDownButton.BackgroundProperty;
                    bg.Value    = (Brush)Application.Current.TryFindResource("MaterialDesignPaper");
                    fg.Property = MahApps.Metro.Controls.DropDownButton.ForegroundProperty;
                    fg.Value    = (Brush)Application.Current.TryFindResource("MaterialDesignBody");

                    btnStyle.Setters.Add(bg);
                    btnStyle.Setters.Add(fg);

                    if (btnStyle != null)
                    {
                        (control as MahApps.Metro.Controls.DropDownButton).ButtonStyle = btnStyle;
                    }

                    Style menuStyle = Application.Current.TryFindResource("MaterialDesignContextMenu") as Style;
                    if (menuStyle != null)
                    {
                        (control as MahApps.Metro.Controls.DropDownButton).MenuStyle = menuStyle;
                    }
                }
                else if (control is MahApps.Metro.Controls.SplitButton)
                {
                    Style lbStyle = Application.Current.TryFindResource("MaterialDesignListBox") as Style;
                    if (lbStyle != null)
                    {
                        (control as MahApps.Metro.Controls.SplitButton).ListBoxStyle = lbStyle;
                    }
                }
                else
                {
                    TryApplyMaterialStyle((control as ContentControl));
                }
            }

            control.ApplyTemplate();
        }