private void FormatAndRenderSampleFromString(String sampleString, ContentPresenter presenter, SyntaxHighlightLanguage HighlightLanguage) { var language = (HighlightLanguage == SyntaxHighlightLanguage.CSharp) ? Languages.CSharp : Languages.Xml; var sampleCodeRTB = new RichTextBlock(); sampleCodeRTB.FontFamily = new FontFamily("Consolas"); var formatter = GenerateRichTextFormatter(); formatter.FormatRichTextBlock(sampleString, language, sampleCodeRTB); presenter.Content = sampleCodeRTB; }
private async void FormatAndRenderSampleFromFile(Uri source, ContentPresenter presenter, SyntaxHighlightLanguage highlightLanguage) { if (source != null && source.AbsolutePath.EndsWith("txt")) { string sampleString = ""; Uri derivedSource = GetDerivedSource(source); var file = await StorageFile.GetFileFromApplicationUriAsync(derivedSource); sampleString = await FileIO.ReadTextAsync(file); FormatAndRenderSampleFromString(sampleString, presenter, highlightLanguage); } else { presenter.Visibility = Visibility.Collapsed; } }