private void SyntaxViewer_Loaded(object sender, System.Windows.RoutedEventArgs e) { if (FilePath != null && File.Exists(FilePath)) { Dispatcher.BeginInvoke(DispatcherPriority.Background, new ThreadStart(() => { FileInfo fi = new FileInfo(FilePath); var reader = new StreamReader(FilePath); string text = reader.ReadToEnd(); Paragraph para = null; if (fi != null) { if (fi.Extension == ".cs") { para = new SyntaxHighlighterCSharp().FormatCode(text); } else { para = SyntaxHighlighterXAML.FormatCode(text); } } var document = new FlowDocument(); document.Blocks.Clear(); document.Blocks.Add(para); this.Document = document; })); } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { if (XamlSource != null && File.Exists(XamlSource)) { FlowDocumentScrollViewer scrollReader = new FlowDocumentScrollViewer(); Dispatcher.BeginInvoke(DispatcherPriority.Background, new ThreadStart(() => { var reader = new StreamReader(XamlSource); string text = reader.ReadToEnd(); Paragraph para = para = SyntaxHighlighterXAML.FormatCode(text); var document = new FlowDocument(); document.Blocks.Clear(); document.Blocks.Add(para); scrollReader.Document = document; })); (SourceCodeViewTabControl.Items[0] as TabItem).Content = scrollReader; } if (CSharapSource != null && File.Exists(CSharapSource)) { FlowDocumentScrollViewer scrollReader = new FlowDocumentScrollViewer(); Dispatcher.BeginInvoke(DispatcherPriority.Background, new ThreadStart(() => { var reader = new StreamReader(CSharapSource); string text = reader.ReadToEnd(); Paragraph para = para = new SyntaxHighlighterCSharp().FormatCode(text);; var document = new FlowDocument(); document.Blocks.Clear(); document.Blocks.Add(para); scrollReader.Document = document; })); (SourceCodeViewTabControl.Items[1] as TabItem).Content = scrollReader; } if (CSharapSource == null || !File.Exists(CSharapSource)) { (SourceCodeViewTabControl.Items[1] as TabItem).Visibility = Visibility.Collapsed; } if (XamlSource == null || !File.Exists(XamlSource)) { (SourceCodeViewTabControl.Items[0] as TabItem).Visibility = Visibility.Collapsed; } }