I am looking for RichTextBox and FlowDocument sources.

I have TextEditor inherited from RichTextBox

Properties overlap with this line:

DefaultStyleKeyProperty.OverrideMetadata(typeof(TextEditor), new FrameworkPropertyMetadata(typeof(TextEditor))); 

.

 public class TextEditor : RichTextBox static TextEditor() { DefaultStyleKeyProperty.OverrideMetadata(typeof(TextEditor), new FrameworkPropertyMetadata(typeof(TextEditor))); 

If you commit it, the controller works as a RichTextBox.

But the TextEditor properties do not work.

Without commenting - the controller works as TextEditor. But you can not insert pictures into it.

Partially an example of my code here: How to insert a picture into a RichTextBox?

 public class TextEditor : RichTextBox public sealed class TextDocument : FlowDocument 
  • one
  • @Grundy: Why not the answer? - VladD
  • @VladD, because these are the link answers :-) - Grundy

1 answer 1

We collect sourceof.net and look for:

Source themes with styles can be found locally in Visual Studio files. For example, at the 2015th Studio they are stored here:

% ProgramFiles (x86)% \ Microsoft Visual Studio 14.0 \ DesignTools \ SystemThemes \ Wpf

A line

 DefaultStyleKeyProperty.OverrideMetadata(typeof(TextEditor), new FrameworkPropertyMetadata(typeof(TextEditor))); 

you overlap not the properties, but the default control style: now it will be equal to the style for which TargetType set in TextEditor .

Custom control styles are usually specified in the Generic.xaml file and look like this:

 <ResourceDictionary ...> <Style TargetType="{x:Type local:TextEditor}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:TextEditor}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> 

It is important to understand that this style redefines not only the Template (in fact, the control layout), but in general all the properties of the base style, since BasedOn is null default.

If you need to inherit some existing style in your style (in your case, this is the RichTextBox style), and thus preserve the behavior and markup of the RichTextBox , then specify the BasedOn explicitly, and do not overwrite the Template property:

 ... <Style TargetType="{x:Type local:TextEditor}" BasedOn="{StaticResource {x:Type RichTextBox}}"> </Style> ... 
  • Wow, did not know about DesignTools \ SystemThemes \ Wpf, thanks! - VladD