0

In VB2010 WPF, i have a textblock which, when the window loads, i need the text inside the textblock to be the same as the text in an outside .txt file. How can i do this?

Thanks

Nick

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Nick
  • 147
  • 1
  • 5
  • 16
  • In the window load event handler, you open the text file, read the contents, and copy them into the TextBlock. At which step exactly do you need help? – Heinzi Feb 03 '11 at 20:43
  • possible duplicate of [Bind WPF TextBlock to text file](http://stackoverflow.com/questions/1995325/bind-wpf-textblock-to-text-file) – Dan J Feb 03 '11 at 21:22

1 Answers1

3
<Window 
    ...
    Loaded="Window_Loaded">
    ...
    <TextBlock Name="textBlock" .../>
    ...
</Window>

and...

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    textBlock.Text = System.IO.File.ReadAllText(path);
}
H.B.
  • 166,899
  • 29
  • 327
  • 400