Own commands for "Text Highlight Color" and "Font Color" buttons

Ribbon for WPF Forum

Posted 8 months ago by Procam
Version: 18.1.0671
Avatar

Hello,

in your samples there is for Text Highlight Color:

<ribbon:SplitButton Command="sample:ApplicationCommands.ApplyDefaultForeground" KeyTipAccessText="FC">
<StackPanel>
<ribbon:ColorPickerGallery InitialColumnCount="10" HorizontalAlignment="Center"
Command="sample:ApplicationCommands.ApplyForeground" IsPreviewEnabled="True">
<ribbon:ColorPickerGallery.CategorizedItemsSource>
<x:Array Type="{x:Type media:SolidColorBrush}">
<media:SolidColorBrush ribbon:PopupGallery.Category="Theme Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#FFFFFF" ribbon:ScreenTipService.ScreenTipHeader="White" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Theme Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#000000" ribbon:ScreenTipService.ScreenTipHeader="Black" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Theme Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#EEECE1" ribbon:ScreenTipService.ScreenTipHeader="Tan" /><media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" Color="#7030A0" ribbon:ScreenTipService.ScreenTipHeader="Purple" />
</x:Array>
</ribbon:ColorPickerGallery.CategorizedItemsSource>
</ribbon:ColorPickerGallery>
</StackPanel>
</ribbon:SplitButton>

The aplied command in the sample for this is:

		public static RibbonCommand ApplyDefaultBackground {
			get {
				if (applyDefaultBackground == null)
					applyDefaultBackground = new RibbonCommand("ApplyDefaultBackground", typeof(Ribbon), "Text Highlight Color", null, "pack://application:,,,/SampleBrowser;component/Resources/Images/TextHighlightColor16.png");				
				return applyDefaultBackground;
			}
		}

 This piece of code changes in the richtexbox the backgroud of the selected text. Also changes the fill color of litle rectangle below the icon.

My request is how can I use some own command? Because instead of richtextbox I have another control color to be changed after clicking this button. In my own command I would like to use also the TextHighlightColor16.png of the sample so the little rectangle can be updated after selecting some color from the picker color.

Thanks for your help.

[Modified 8 months ago]

Comments (3)

Posted 8 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Please see the RichTextBoxExtended file's OnApplyBackgroundCanExecute and OnApplyBackgroundExecute methods as those basically are what process that command.  The RichTextBoxExtended constructor sets them up with:

this.CommandBindings.Add(new CommandBinding(ApplicationCommands.ApplyBackground,
  OnApplyBackgroundExecute, OnApplyBackgroundCanExecute));

Then you can see how the one method calls a UpdateApplyDefaultBackgroundSmallImageSource method in that code as well.  That is what updates the image source to fill in the box in TextHighlightColor16.png.


Actipro Software Support

Posted 8 months ago by Procam
Avatar

Hello,

I have done in similar way as you adviced. The splitbutton is created dynamically in code, The command for that is set as in the sample, but in the ApplyForegroundExecute I get for e.Parameter not BrushValueCommandParameter but ICheckableCommandParameter. How can I set the BrushValueCommandParameter when creating the splitbutton dynamically? Or am I missing something else?

        public static void ApplyForegroundExecute(object target, ExecutedRoutedEventArgs e)
        {
            GcSpreadSheet spreadSheet = target as GcSpreadSheet;
            if (spreadSheet == null) return;

            BrushValueCommandParameter parameter = e.Parameter as BrushValueCommandParameter;

The splitbutton is created this way:

                                ColorPicker colorPicker = new ColorPicker();
                                SplitButton splitButton = new SplitButton
                                {
                                    Id = commandModel.Id,
                                    ImageSourceLarge = renderTargetBitmap,
                                    ImageSourceSmall = renderTargetBitmap,
                                    Command = commandModel.Command,
                                    //CommandParameter = new BrushValueCommandParameter(), // not helped
                                    Label = commandModel.Caption,
                                    PopupContent = colorPicker
                                };

[Modified 8 months ago]

Posted 8 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I would expect the uncommented line you had to work in general.  There is code in SplitButton to coerce the CommandParameter property to be a CheckbableCommandParameter if there is no CommandParameter set.  But otherwise, it should use whatever value you set.  Perhaps try setting the property after the other properties are all set, in a separate line, and see what the result of the CommandParameter property is after it's set.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.