views:

277

answers:

1

How can I bind a WPF TextBlock to a text file? I want for the TextBlock to display the content of the file.

+1  A: 

You need to read the file into a string in memory and bind to that string instead.

View model:

class ViewModel
{
    public string FileText { get; set; }
    public void ReadFile(string path)
    {
        FileText = File.ReadAllText(path);
    }
}

XAML:

<TextBlock Text="{Binding FileText}"/>
Aviad P.