locked
How to prevent a MarkerFormatDefinition's values being overridden. RRS feed

  • Question

  • Hi. 

    I have a MarkerFormatDefinition that highlights certain note text found in comments. The defining class looks like this:

       [Export(typeof(EditorFormatDefinition))]
        [Name("MarkerFormatDefinition/NoteFormatDefinition")]
        [Order(After = "default")]
        [UserVisible(true)]
        public class NoteFormatDefinition : MarkerFormatDefinition
        {
            #region Constructors
            /// <summary>
            /// Initializes a new instance of the <see cref="NoteFormatDefinition"/> class.
            /// </summary>
            public NoteFormatDefinition()
            {
                //Set the visual properties of text tagged with the NoteTag.
                this.BackgroundColor = Colors.Black;
                this.ForegroundColor = Colors.Blue;
                this.Border = new Pen(new SolidColorBrush(Colors.Red), 2.0);
                this.DisplayName = "Note";
                this.ZOrder = 5;
                this.ForegroundBrush = new SolidColorBrush(Colors.Red);
            }
    
            #endregion Constructors
    
    
        }
    

    Unfortunately the ForegroundColor is always ignored as it seems to be overridden by the standard Comment formatting. I've tried fiddling with the Order attribute, but I just can't work out how to fix this. Does anyone know?

     

    Steve

    Monday, October 24, 2011 8:35 AM

All replies

  • Hi Steve, 

    The string "default" value is not for setting the priority order. You can use "Default Priority" to represent default priority.

    As a recommendation, please use the constant string Priority.Default here for the order.

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, October 26, 2011 3:42 AM
  • Yi, 

     

    Thanks for that advice. Unfortunately, it still doesn't fix the foreground issue. The foreground text is still taking on the foreground from the Comment setting (defined by VS). It does pick up my Background Brush, but that's it. 

     

    Steve

    Wednesday, October 26, 2011 7:07 AM
  • Hi

    I just create a new Editor Classifier project from VS and using following code:

    namespace EditorClassifier1
    {
        #region Format definition
        /// <summary>
        /// Defines an editor format for the EditorClassifier1 type that has a purple background
        /// and is underlined.
        /// </summary>
        [Export(typeof(EditorFormatDefinition))]
        [ClassificationType(ClassificationTypeNames = "EditorClassifier1")]
        [Name("EditorClassifier1")]
        [UserVisible(true)] //this should be visible to the end user
        [Order(Before = Priority.Default)] //set the priority to be after the default classifiers
        internal sealed class EditorClassifier1Format : ClassificationFormatDefinition
        {
            /// <summary>
            /// Defines the visual format for the "EditorClassifier1" classification type
            /// </summary>
            public EditorClassifier1Format()
            {
               // this.DisplayName = "EditorClassifier1"; //human readable version of the name
              //  this.BackgroundColor = Colors.BlueViolet;
              //  this.TextDecorations = System.Windows.TextDecorations.Underline;
    
    
                this.BackgroundColor = Colors.Black;
                this.ForegroundColor = Colors.Blue;
             
                this.DisplayName = "Note";
         
                this.ForegroundBrush = new SolidColorBrush(Colors.Red);
    
    
            }
        }
        #endregion //Format definition
    }
    
    

     

    I get the following result:

     

    It seems the blue is applied to text.

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 31, 2011 1:54 PM
  • Yi,

     

    Thanks for your answer. I get the correct results using ClassificationTags. But I am trying to use TextMarkerTags to define the look of my text. It appears these all get applied before any styles associated with ClassificationTags. I'm trying to find a way around this.

    Regards, 

     

    Steve

    Monday, October 31, 2011 3:12 PM
  • Hello Steve,

    Please note that markers and classifications are separate entities.

    A marker is simply a rectangle drawn over a piece of text. It can have a background color (fill) and a foreground color (border). It does not change the classification properties of the text.

    Classification on the other hand, solely changes the properties of the text's formatting and is unable to draw a border around it, for example.

    In VS 2008, legacy markers had the ability to change the classification of the text on top of which they were, but the new editor markers don't have this capability. If you like, you can use a legacy marker and our shim implementation would essentially use a classifier to classify the text for you, and a marker to change the text background and draw a border around it if need be.

    Having the text classified though is easier than it sounds. Here is a design that you can pursue if you like:

    Have an ITagger that produces your own custom tag, let's say, you call it IClassifiedMarkerTag which implements ITag. In it, it has two fields: IClassificationType classificationType and string markerName.

    Change your current tagger that produces your marker tags to be this new ITagger. Then provide 2 new tagger providers:

    ITagger<IClassificationTag>

    ITagger<ITextMarkerTag>

    In those tagger implementations, you would simply create a TagAggregator<IClassifiedMarkerTag> and essentially forward all your queries to your real ITagger<IClassifiedMarkerTag>. You would only inspect the classification type desired, and the name of the marker to use to produce corresponding ITextMarkerTag and IClassificationTag(s).

    This way, you get full control over the appearance of the text and also the marker and you get to keep your current tagger which tags your markers.

    Please let me know if you have any questions!

    -Ameen

    Thursday, November 24, 2011 12:57 AM
  • Ameen, 

     

    Hey, great post. It is a really clear explanation of the issue.

    I'll have a go at the change this weekend and report back. 

     

    Thanks.

     

     

    Thursday, November 24, 2011 8:46 AM