I am trying to create a markup extension that will take an HTML string, convert it to a FlowDocument, and return a FlowDocument. I am new to creating markup extensions, and I hope this will be obvious to people with a lot of experience. Here is my code:
[MarkupExtensionReturnType(typeof(FlowDocument))] public class HtmlToXamlExtension : MarkupExtension { public HtmlToXamlExtension(String source) { this.Source = source; } [ConstructorArgument("source")] public String Source { get; set; } public Type LocalizationResourceType { get; set; } public override object ProvideValue(IServiceProvider serviceProvider) { if (this.Source == null) { throw new InvalidOperationException("Source must be set."); } FlowDocument flowDocument = new FlowDocument(); flowDocument.PagePadding = new Thickness(0, 0, 0, 0); string xaml = HtmlToXamlConverter.ConvertHtmlToXaml(Source.ToString(), false); using (MemoryStream stream = new MemoryStream((new ASCIIEncoding()).GetBytes(xaml))) { TextRange text = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd); text.Load(stream, DataFormats.Xaml); } return flowDocument; } }
Update: here is XAML.
<RadioButton.ToolTip> <FlowDocumentScrollViewer Document="{ext:HtmlToXaml Source={x:Static res:ExtrudeXaml.RadioButtonCreateBody_TooltipContent}}" ScrollViewer.VerticalScrollBarVisibility="Hidden" /> </RadioButton.ToolTip>
And my list of VS errors:
- Error 3 The unknown "Source" property for the type "MS.Internal.Markup.MarkupExtensionParser + UnknownMarkupExtension" encountered when parsing the Markup Extension. Line 89 Position 49.
- Error 1 Type "HtmlToXamlExtension" does not contain a constructor with the specified number of arguments.
- Error 2 No constructor for type 'HtmlToXamlExtension' has 0 parameters.
MCRXB source share