Added Markdown renderer
This commit is contained in:
parent
7036df995a
commit
897188de47
@ -60,10 +60,7 @@
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Grid.Row="1" Margin="0,15,0,0" Header="Device Driver Compatibility Summary">
|
||||
<TextBlock Text="{Binding Path=SummaryText}"
|
||||
TextAlignment="Justify"
|
||||
TextWrapping="WrapWithOverflow"
|
||||
FontSize="14px" />
|
||||
<FlowDocumentScrollViewer Height="200" VerticalScrollBarVisibility="Auto" Document="{Binding SummaryDocument}"/>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</controls:MetroWindow>
|
@ -1,5 +1,12 @@
|
||||
using DerpingDrivers.Util;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Windows.Documents;
|
||||
using System.Xaml;
|
||||
using DerpingDrivers.Util;
|
||||
using MahApps.Metro.Controls;
|
||||
using Markdig;
|
||||
using Markdig.Wpf;
|
||||
|
||||
namespace DerpingDrivers
|
||||
{
|
||||
@ -49,5 +56,49 @@ namespace DerpingDrivers
|
||||
|
||||
public string SummaryText =>
|
||||
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
|
||||
|
||||
public FlowDocument SummaryDocument
|
||||
{
|
||||
get
|
||||
{
|
||||
var markdown = "*None available*";
|
||||
|
||||
// Convert Markdown to XAML
|
||||
var xaml = Markdig.Wpf.Markdown.ToXaml(markdown, BuildPipeline());
|
||||
|
||||
// Render XAML for FlowDocument Control
|
||||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xaml)))
|
||||
{
|
||||
var reader = new XamlXmlReader(stream, new MyXamlSchemaContext());
|
||||
|
||||
if (System.Windows.Markup.XamlReader.Load(reader) is FlowDocument document)
|
||||
{
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static MarkdownPipeline BuildPipeline()
|
||||
{
|
||||
return new MarkdownPipelineBuilder()
|
||||
.UseSupportedExtensions()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
|
||||
internal class MyXamlSchemaContext : XamlSchemaContext
|
||||
{
|
||||
public override bool TryGetCompatibleXamlNamespace(string xamlNamespace, out string compatibleNamespace)
|
||||
{
|
||||
if (xamlNamespace.Equals("clr-namespace:Markdig.Wpf"))
|
||||
{
|
||||
compatibleNamespace = $"clr-namespace:Markdig.Wpf;assembly={Assembly.GetAssembly(typeof(Markdig.Wpf.Styles)).FullName}";
|
||||
return true;
|
||||
}
|
||||
return base.TryGetCompatibleXamlNamespace(xamlNamespace, out compatibleNamespace);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user