Пример #1
0
            public ButtonWrapper(MultiButtonBarControl itemControl, BarMultiButton.ButtonInfo buttonInfo)
            {
                this.itemControl = itemControl;
                this.Button      = buttonInfo;
                this.ActiveTheme = buttonInfo.BarItem.ControlTheme;
                string          text       = itemControl.GetDisplayText(this.Button.Text);
                SolidColorBrush?imageBrush = null;

                if (text.StartsWith("icon:"))
                {
                    string icon = text.Substring(text.IndexOf(':') + 1);
                    this.ImageSource = BarImages.CreateImageSource(icon);
                    if (this.ImageSource is DrawingImage di)
                    {
                        imageBrush = BarImages.ChangeDrawingColor(di.Drawing, this.ActiveTheme.TextColor ?? Colors.White);
                    }
                }
                else
                {
                    this.Text = text;
                }

                // Update the theme when the property changes.
                this.itemControl.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName == nameof(this.itemControl.ActiveTheme))
                    {
                        this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(args.PropertyName));
                        if (imageBrush is not null && this.ActiveTheme.TextColor.HasValue)
                        {
                            imageBrush.Color = this.ActiveTheme.TextColor.Value;
                        }
                    }
                };
            }
Пример #2
0
        /// <summary>
        /// Gets the text or icon to be displayed, based on the given text. This allows symbols to be easily expressed
        /// in the json.
        /// May also return a string prefixed with "icon:", where the rest of the text is the bar icon.
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        protected string GetDisplayText(string text)
        {
            var(finalText, icon) = text switch
            {
                "+" => ("\u2795", "plus"),
                "-" => ("\u2796", "minus"),
                "||" => ("\u258e \u258e", ""),
                "|>" => ("\u25b6", ""),
                "[]" => ("\u25a0", ""),
                _ => (text, null)
            };

            string?iconPath = string.IsNullOrEmpty(icon)
                ? null
                : BarImages.GetBarIconFile(icon);

            return(iconPath is not null
                ? $"icon:{iconPath}"
                : finalText);
        }