title: Use TextBlock to show the content and the date created (found in file properties) of a large text file and change the border color of the TextBlock
body: <p>I have the following XAML code that creates a browse file functionality of large txt files.</p>
  <p><strong>XAML code</strong></p>
  <pre class="lang-xml prettyprint-override"><code>Window x:Class=&quot;TestEnvironment.MainWindow&quot;
          xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
          xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
          xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
          xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
          xmlns:materialDesign=&quot;http://materialdesigninxaml.net/winfx/xaml/themes&quot;
          xmlns:local=&quot;clr-namespace:TestEnvironment&quot; 
          mc:Ignorable=&quot;d&quot;
          Title=&quot;MainWindow&quot; Height=&quot;600&quot; Width=&quot;1080&quot; ResizeMode=&quot;NoResize&quot; WindowStartupLocation=&quot;CenterScreen&quot; WindowStyle=&quot;None&quot;&gt;
      &lt;StackPanel Background=&quot;WhiteSmoke&quot;&gt;
          
          &lt;!--Grid 1--&gt;
          &lt;Grid Height=&quot;40&quot; ShowGridLines=&quot;True&quot;&gt;
              &lt;StackPanel HorizontalAlignment=&quot;Left&quot; Margin=&quot;20 0&quot;&gt;
                  &lt;ComboBox FontSize=&quot;15&quot; Width=&quot;50&quot; Foreground=&quot;#FFA2A2A2&quot; SelectedIndex=&quot;0&quot; VerticalAlignment=&quot;Center&quot;&gt;
                      &lt;ComboBoxItem IsSelected=&quot;False&quot;&gt;EN&lt;/ComboBoxItem&gt;
                      &lt;ComboBoxItem IsSelected=&quot;True&quot;&gt;GR&lt;/ComboBoxItem&gt;
                  &lt;/ComboBox&gt;
              &lt;/StackPanel&gt;
              &lt;StackPanel Orientation=&quot;Horizontal&quot; HorizontalAlignment=&quot;Right&quot; Margin=&quot;20 0&quot;&gt;
                  &lt;Button Content=&quot;FAQ&quot; Background=&quot;{x:Null}&quot; BorderBrush=&quot;{x:Null}&quot; Foreground=&quot;#FFA2A2A2&quot; FontSize=&quot;15&quot; FontWeight=&quot;Bold&quot; VerticalAlignment=&quot;Center&quot;/&gt;
                  &lt;Button Content=&quot;CONTACT&quot; Background=&quot;{x:Null}&quot; BorderBrush=&quot;{x:Null}&quot; Foreground=&quot;#FFA2A2A2&quot; FontSize=&quot;15&quot; FontWeight=&quot;Bold&quot; VerticalAlignment=&quot;Center&quot;/&gt;
                  &lt;Button Content=&quot;MY ACCOUNT&quot; Background=&quot;{x:Null}&quot; BorderBrush=&quot;{x:Null}&quot; Foreground=&quot;#FFA2A2A2&quot; FontSize=&quot;15&quot; FontWeight=&quot;Bold&quot; VerticalAlignment=&quot;Center&quot;/&gt;
                  &lt;Button Background=&quot;{x:Null}&quot; BorderBrush=&quot;{x:Null}&quot; VerticalAlignment=&quot;Center&quot; Style=&quot;{StaticResource MaterialDesignFloatingActionMiniAccentButton}&quot;&gt;
                      &lt;materialDesign:PackIcon Kind=&quot;Power&quot; Foreground=&quot;#FFA2A2A2&quot; Width=&quot;25&quot; Height=&quot;25&quot; /&gt;
                  &lt;/Button&gt;
              &lt;/StackPanel&gt;
          &lt;/Grid&gt;
          
          &lt;!--Grid 2--&gt;
          &lt;Grid Height=&quot;100&quot;  ShowGridLines=&quot;True&quot;&gt;
              &lt;StackPanel Orientation=&quot;Horizontal&quot; VerticalAlignment=&quot;Top&quot; Margin=&quot;10 0&quot;&gt;
                  &lt;Button Uid=&quot;0&quot; Width=&quot;150&quot; Content=&quot;LOAD FILES&quot; Height=&quot;50&quot; Background=&quot;{x:Null}&quot; BorderBrush=&quot;{x:Null}&quot; Foreground=&quot;#FF2196F3&quot; Click=&quot;Button_Click&quot;/&gt;
                  &lt;Button Uid=&quot;1&quot; Width=&quot;150&quot; Content=&quot;FILES LAYOUT&quot; Height=&quot;50&quot; Background=&quot;{x:Null}&quot; BorderBrush=&quot;{x:Null}&quot; Foreground=&quot;#FF2196F3&quot; Click=&quot;Button_Click&quot;/&gt;
                  &lt;Button Uid=&quot;2&quot; Width=&quot;150&quot; Content=&quot;BUSINESS CHECKS&quot; Height=&quot;50&quot; Background=&quot;{x:Null}&quot; BorderBrush=&quot;{x:Null}&quot; Foreground=&quot;#FF2196F3&quot; Click=&quot;Button_Click&quot;/&gt;
              &lt;/StackPanel&gt;
              &lt;Grid x:Name=&quot;GridCursor&quot; Width=&quot;150&quot; Height=&quot;5&quot; Background=&quot;#FF2196F3&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;10 0&quot;/&gt;
          &lt;/Grid&gt;
          
          &lt;!--Grid 3--&gt;
          &lt;Grid x:Name=&quot;GridMain&quot; Height=&quot;460&quot; Background=&quot;LightGray&quot; ShowGridLines=&quot;True&quot;&gt;
  
              &lt;TextBox HorizontalAlignment=&quot;Left&quot; Height=&quot;40&quot; Margin=&quot;30,13,0,0&quot; TextWrapping=&quot;Wrap&quot;   
                   Text=&quot;TextBox&quot; FontFamily=&quot;Arial&quot;  VerticalAlignment=&quot;Top&quot; Width=&quot;436&quot; Name=&quot;FileNameTextBox&quot;/&gt;
              &lt;Button x:Name=&quot;BrowseButton&quot; Content=&quot;Browse a file&quot; HorizontalAlignment=&quot;Left&quot;   
                  Margin=&quot;485,13,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;121&quot; Click=&quot;BrowseButton_Click&quot;   
                  RenderTransformOrigin=&quot;1.047,0.821&quot; Height=&quot;40&quot;/&gt;
              &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;282&quot; Margin=&quot;30,96,0,0&quot;   
                     TextWrapping=&quot;Wrap&quot; Text=&quot;TextBlock&quot; FontFamily=&quot;Arial&quot; VerticalAlignment=&quot;Top&quot;  
                     Width=&quot;703&quot; Name=&quot;TextBlock1&quot;&gt;
              &lt;/TextBlock&gt;
              &lt;Button x:Name=&quot;LoadButton&quot; Content=&quot;Load&quot; HorizontalAlignment=&quot;Left&quot;   
                  Margin=&quot;682,13,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;121&quot; Click=&quot;BrowseButton_Click&quot;   
                  RenderTransformOrigin=&quot;1.047,0.821&quot; Height=&quot;40&quot;/&gt;
          &lt;/Grid&gt;
  
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  <p>App.xaml file</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Application x:Class=&quot;TestEnvironment.App&quot;
               xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
               xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
               xmlns:local=&quot;clr-namespace:TestEnvironment&quot;
               StartupUri=&quot;MainWindow.xaml&quot;&gt;
      &lt;Application.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ResourceDictionary.MergedDictionaries&gt;
                  &lt;ResourceDictionary Source=&quot;pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml&quot; /&gt;
                  &lt;ResourceDictionary Source=&quot;pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml&quot; /&gt;
                  &lt;ResourceDictionary Source=&quot;pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml&quot; /&gt;
                  &lt;ResourceDictionary Source=&quot;pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Blue.xaml&quot; /&gt;
              &lt;/ResourceDictionary.MergedDictionaries&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>
  <p>Output of the WPF editor
  <a href="https://i.stack.imgur.com/cvhH0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cvhH0.png" alt="enter image description here" /></a></p>
  <p>What I want is to be able to browse and show the content of a large file. I don't care if the whole file is shown or just a sample of it.</p>
  <p>The execute I am executing can show only small files. Like the below:</p>
  <p>You will need to load MaterialDesignThemes from Nuget packages to replicate the issue.</p>
  <pre class="lang-cs prettyprint-override"><code>using MaterialDesignThemes.Wpf;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  using System.Data.SqlClient;
  using System.Diagnostics;
  
  namespace TestEnvironment
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
  
      public partial class MainWindow : Window
      {   
          public MainWindow()
          {
              InitializeComponent();
          }
  
          private void Button_Click(object sender, RoutedEventArgs e)
          {
              int index = int.Parse(((Button)e.Source).Uid);
  
              GridCursor.Margin = new Thickness(10 + (150 * index), 0, 0, 0);
  
              switch (index)
              {
                  case 0:
                      GridMain.Background = Brushes.LightGray;
                      break;
                  case 1:
                      GridMain.Background = Brushes.LightGray;
                      break;
                  case 2:
                      GridMain.Background = Brushes.LightGray;
                      break;
              }
          }
  
          private void BrowseButton_Click(object sender, RoutedEventArgs e)
          {
              // Create OpenFileDialog
              Microsoft.Win32.OpenFileDialog openFileDlg = new Microsoft.Win32.OpenFileDialog();
  
              // Launch OpenFileDialog by calling ShowDialog method
              Nullable&lt;bool&gt; result = openFileDlg.ShowDialog();
              // Get the selected file name and display in a TextBox.
              // Load content of file in a TextBlock
              if (result == true)
              {
                  FileNameTextBox.Text = openFileDlg.FileName;
                  TextBlock1.Text = System.IO.File.ReadAllText(openFileDlg.FileName);
                  Debug.WriteLine(&quot;Txt file contents!&quot;);
              }
  
              // Set filter for file extension and default file extension  
              openFileDlg.DefaultExt = &quot;.txt&quot;;
              openFileDlg.Filter = &quot;Text files (*.txt)|*.txt|All files (*.*)|*.*&quot;;
  
              Debug.WriteLine(&quot;Txt imported&quot;);
  
              // Set initial directory    
              openFileDlg.InitialDirectory = @&quot;C:\Documents\&quot;;
  
              // Multiple selection with all file types    
              openFileDlg.Multiselect = true;
  
              Debug.WriteLine(&quot;End!&quot;);
          }
      }
  }
  </code></pre>
  <p>The code above what currently does is to present the content of a short txt file.</p>
  <p><a href="https://i.stack.imgur.com/5oYbK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5oYbK.png" alt="enter image description here" /></a></p>
  <p>For example a large txt file that I want to present is like the following with 30K rows:</p>
  <p><a href="https://i.stack.imgur.com/RzKZo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RzKZo.png" alt="enter image description here" /></a></p>
  <p>So what I want are the followings:</p>
  <ol>
  <li><p>Load the content of a larger file and if the content cannot fit in the TextBlock window then either present a short version of it or use a scroll bar to view the rest of its content.</p>
  </li>
  <li><p>Display above the content of the txt file the Created On date which is found in Right Click-&gt; the Properties window of the txt file. (Only if this is feasible. Because I am not sure if C# can access the properties window of a file)</p>
  </li>
  <li><p>How can I change the border color of the TextBlock object and make it white.</p>
  </li>
  </ol>
  <p>Thank you in advance for any help.</p>
  <p><strong>UPDATES based on the comments</strong></p>
  <ol>
  <li>I have add the boarder around my TextBlock like below:</li>
  </ol>
  <pre class="lang-xml prettyprint-override"><code>            &lt;Border BorderThickness=&quot;3&quot; BorderBrush=&quot;LightCyan&quot;&gt;
              &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;282&quot; Margin=&quot;30,96,0,0&quot;   
                     TextWrapping=&quot;Wrap&quot; Text=&quot;TextBlock&quot; FontFamily=&quot;Arial&quot; VerticalAlignment=&quot;Top&quot;  
                     Width=&quot;703&quot; TextTrimming=&quot;CharacterEllipsis&quot; Name=&quot;TextBlock1&quot;&gt;
              &lt;/TextBlock&gt;
              &lt;/Border&gt;
  </code></pre>
  <p>But the highlighted boarder goes around my Grid instead of only the textblock</p>
  <p><a href="https://i.stack.imgur.com/DRG0E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DRG0E.png" alt="enter image description here" /></a></p>
  <ol start="2">
  <li>I used the GetCreationTime() property and indeed the creation time of the file was generated. Although, the previous text of the box was deleted and only the data value was shown. My code:</li>
  </ol>
  <pre class="lang-cs prettyprint-override"><code>            if (result == true)
              {
                  FileNameTextBox.Text = openFileDlg.FileName;
                  TextBlock1.Text = System.IO.File.ReadAllText(openFileDlg.FileName);
                  TextBlock1.Text = System.IO.File.GetCreationTime(openFileDlg.FileName).ToString();
                  Debug.WriteLine(&quot;Txt file contents!&quot;);
              }
  </code></pre>
  <ol start="3">
  <li>The property TextTrimming=&quot;CharacterEllipsis&quot; didn't seem to work. Even though it is correct, it did not solve my problem.</li>
  </ol>