Custom Image in HtmlContentProvider

SyntaxEditor for WPF Forum

Posted 7 months ago by Josh
Version: 17.2.0
Avatar

Hello,

I can't seem to get a custom image to appear in the HtmlContentProvider.

public class CustomHtmlContentProvider : HtmlContentProvider
	{
		private readonly Model _model;

		public CustomHtmlContentProvider(Model model, string html)
			: base(html)
		{
			_model = model;
		}

		protected override Image GetImage(string source)
		{
			if (source.StartsWith("resource:"))
			{
				BitmapImage bitmapImage = new BitmapImage();
				switch (source)
				{
					case "resource:statement":
						bitmapImage = new BitmapImage(_model.GraphicStatementUri);
						break;
				}

				var image = new Image
				{
					Source = bitmapImage,
					Height = 16,
					Width = 16
				};
				//image.Stretch = Stretch.Uniform;
				//image.VerticalAlignment = VerticalAlignment.Center;
				//image.HorizontalAlignment = HorizontalAlignment.Center;

				return image;
			}

			return base.GetImage(source);
		}
	}

The GetContent will hit this code, but the image is not displayed.  Do you have an example of using a custom image in the quick info tip?

Comments (3)

Answer - Posted 7 months ago by Josh
Avatar

Well, for some odd reason, when using the uri as a relative path in the completion provider the icon works just fine, but within the quick info, I need to use a absolute path with the pack://application:,,,

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

Hi Josh,

Good, I'm glad you sorted it out.  Yes an absolute Uri would be needed for the BitmapImage.  While we don't have an example of using custom images, the code you posted should work as long as your Uri for the BitmapImage is valid. 

By the way, our internal logic first checks to see if the source string starts with a "resource:" and if it does, it sees if what follows that prefix can parse into one of our CommonImageKind values.  If so, it uses our built-in image.  Otherwise it calls the method you override and uses that Image.  I would suggest you not use the "resource:" prefix for your custom images so that your values don't have a chance to conflict with ours.  You can use any other prefix you like.


Actipro Software Support

Posted 7 months ago by Josh
Avatar

Yeah I changed it to custom:

Thank you!

The latest build of this product (v22.1.3) was released 20 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.