/// <summary> /// Creates a highlight annotation with the specified color and author /// </summary> /// <param name="service">the AnnotationService</param> /// <param name="textRange">highlight anchor</param> /// <param name="author">highlight author</param> /// <param name="color">highlight brush</param> /// <returns>created annotation</returns> private static Annotation CreateHighlight(AnnotationService service, ITextRange textRange, string author, Nullable<Color> color) { Invariant.Assert(textRange != null, "textRange is null"); Annotation annotation = CreateAnnotationForSelection(service, textRange, HighlightComponent.TypeName, author); // Set the cargo with highlight color if (color != null) { ColorConverter converter = new ColorConverter(); XmlDocument doc = new XmlDocument(); XmlElement colorsElement = doc.CreateElement(HighlightComponent.ColorsContentName, AnnotationXmlConstants.Namespaces.BaseSchemaNamespace); colorsElement.SetAttribute(HighlightComponent.BackgroundAttributeName, converter.ConvertToInvariantString(color.Value)); AnnotationResource cargo = new AnnotationResource(HighlightComponent.HighlightResourceName); cargo.Contents.Add(colorsElement); annotation.Cargos.Add(cargo); } return annotation; }