This is a migrated thread and some comments may be shown as answers.

Limiting table colour paletter

9 Answers 56 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 03 Dec 2013, 12:39 AM
We are limiting the colours that users can select through our ColorPicker controls so that text foreground / background colours are only in a certain pre-defined range.

I have been looking and can't figure out how to do this for tables (cell background, and cell/table border colours). Is there a way to specify the palette and data template (for custom tooltip) similar to the ColorPicker control? We do not want users to select any arbitrary colour, only from a certain list.

Thanks.

9 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 05 Dec 2013, 06:48 PM
Hello,

Thank you for contacting us!

Unfortunately, at this point there is no easy way to achieve the desired result. We will do our best to expose an extensibility point which will help you in this regard in one of our future releases.

Please excuse us for the inconvenience! Let us know if you have any other questions.

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Nick
Top achievements
Rank 1
answered on 06 Dec 2013, 12:56 AM
Thanks Petya. We will need to determine an appropriate workaround on our side for now.

0
Accepted
Petya
Telerik team
answered on 06 Dec 2013, 05:28 PM
Hello,

On a second thought, you can try finding the respective color selector controls by their name and changing the palettes like this:
TablePropertiesDialog tablePropertiesDialog = (this.radRichTextBox.TablePropertiesDialog as TablePropertiesDialog);//.FindName("tableProperties") as Telerik.Windows.Controls.RichTextBoxUI.Dialogs.TableProperties.TableProperties;
CellProperties cellProperties = (tablePropertiesDialog.FindName("cellProperties") as CellProperties);
RadColorSelector colorSelector = (cellProperties.FindName("backgroundColorPicker") as DropDownColorPicker).FindName("colorSelector") as RadColorSelector;
colorSelector.MainPalette = ColorPreset.Grayscale;
 
 
TableBordersDialog tableBordersDialog = (this.radRichTextBox.TableBordersDialog as TableBordersDialog);
 
TableBordersProperties tableBordersProperties = tableBordersDialog.FindName("tableBordersControl") as TableBordersProperties;
TableBorderSelector tableBordersSelector = tableBordersProperties.FindName("borderSelector") as TableBorderSelector;
RadColorSelector bordersColorSelector = tableBordersSelector.FindName("colorSelector") as RadColorSelector;
bordersColorSelector.MainPalette = ColorPreset.Grayscale;
 
CellBordersProperties cellBordersProperties = tableBordersDialog.FindName("cellBordersControl") as CellBordersProperties;
TableBorderSelector cellBordersSelector = cellBordersProperties.FindName("borderSelector") as TableBorderSelector;
RadColorSelector cellBordersColorSelector = cellBordersSelector.FindName("colorSelector") as RadColorSelector;
cellBordersColorSelector.MainPalette = ColorPreset.Grayscale;

I hope this helps!

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Nick
Top achievements
Rank 1
answered on 09 Dec 2013, 05:27 AM
Thanks Petya - I managed to replace all 3 with our custom colours and it works great. I even got the tooltip with the colour names working, based on the DataTemplate example in the documentation.

My only problem is that 'Automatic' is being used for the borders in a fresh table, but we have to fix this elsewhere.
0
Petya
Telerik team
answered on 11 Dec 2013, 01:13 PM
Hello,

When inserting a new table from the predefined UI of RadRichTextBox, the TableGrid style is applied to that table. With this in mind, you can modify the mentioned style in any way desired by obtaining it from the document's style repository:
StyleDefinition tableGridStyle = this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.DefaultTableGridStyleName];
tableGridStyle.TableStyle.Borders = new TableBorders(new Telerik.Windows.Documents.Model.Border(BorderStyle.Dashed, Colors.Aquamarine));
this.radRichTextBox.UpdateEditorLayout(); //update instances already added to the document

Note that as the style repository is a property of RadDocument, once the document in the editor is changed the default values for the style's properties will be used. In order to apply this to all documents shown in RadRichTextBox you can subscribe to the DocumentChanged event of RadRichTextBox.

I hope this helps!

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Nick
Top achievements
Rank 1
answered on 11 Dec 2013, 10:55 PM
Thanks Petya! That is much simpler than my other approach (making my own InsertTableCommand replacement) so I'll use it instead.

It'll take a long time to learn all of these tricks.

Since you've been so helpful can I ask one more thing? When exporting as XML we want to use user defined colour names instead of RGB values. At the moment I can do a lookup in our list but this won't work if 2 colours have the same RGB value (the user can change them over time).

The only solution I have is to apply the Color manually to the document and store the details in the Tag attribute for each item but this seems very messy. Also when I did a quick test the selection event only returned the Color struct (based on the ColorPropertyPath setting) and not the full ColorViewModel object which contains the name etc.

0
Petya
Telerik team
answered on 14 Dec 2013, 04:14 PM
Hi Nick,

I am not sure I fully understand your scenario. Would you mind sharing more details on what you are trying to achieve?

As far as I can tell you could use RadRichTextBox's styling mechanism which allows you to predefine styles for different type of content - tables, paragraphs, etc. When serializing this to XAML, it would look like this:
<t:Span StyleName="CustomStyle" Text="Insert " />
where CustomStyle is a character style I created:
<s:StyleDefinition DisplayName="Custom Style" IsCustom="True" IsDefault="False" IsPrimary="True" Name="CustomStyle" Type="Character" UIPriority="0">
  <s:StyleDefinition.SpanStyle>
    <s:SpanProperties ForeColor="#FFFFC000" />
  </s:StyleDefinition.SpanStyle>
</s:StyleDefinition>

In this case the value of the ForeColor is still represented in RGB, however if the user modifies the style definition, all content which has the style applied will be changed.

I hope this suits your needs.

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Nick
Top achievements
Rank 1
answered on 16 Dec 2013, 12:12 AM
Hi Petya, this may be better suited to the ColorPicker forum but I will attempt to explain.

We export the XAML and use it to produce PDF files for printing. Each file may have different branding so for example when the customer sets up the page he will select our named 'Overdue Amount' colour which has an RGB Value of 'ff0000'. 

However when running the file for another brand, maybe they want yellow. So we need to know not that the item is 'ff0000' but instead that it is 'Overdue Amount' and we can substitute the correct CMYK colour at run time, using the previously exported XAML.

When exporting the XAML, we can lookup the RGB value 'ff0000' and discover it is 'Overdue Amount' from our list. But if there are 2 colours with the same value this lookup cannot work.

Is there a way to apply metadata to the document objects to record which colour name was selected? I see there is a 'Tag' attribute that can contain a string, but to use this we need to a) have access to the original ColorViewModel object (not just the Color) which has the name, and b) discover and update all items under the current selection correctly.

Does this make sense? Is there a simpler way to do the last part? We are already using styles - this feature is for overriding the styles for specific words/backgrounds. Thanks.
0
Petya
Telerik team
answered on 18 Dec 2013, 05:27 PM
Hi Nick,

Thanks for sharing those details with us!

Based on your requirements using the Tag property is one of the options you can adopt. Unfortunately, there are no additional tips I can suggest in this case. 

The only other option to preserve custom data when exporting is in a custom annotation. Custom annotations are appropriate when in need to keep semantic information on an export/import roundtrip, but you should be aware that they are only persisted in XAML format. You can check this help article for further information on the topic.

I hope this is helpful!

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
RichTextBox
Asked by
Nick
Top achievements
Rank 1
Answers by
Petya
Telerik team
Nick
Top achievements
Rank 1
Share this question
or