将WPF TextBlock绑定到文本文件 [英] Bind WPF TextBlock to text file
本文介绍了将WPF TextBlock绑定到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将WPF TextBlock绑定到文本文件?我想让TextBlock显示文件的内容。
How can I bind a WPF TextBlock to a text file? I want for the TextBlock to display the content of the file.
推荐答案
您需要将文件读入内存中的字符串,绑定到该字符串。
You need to read the file into a string in memory and bind to that string instead.
查看模型:
class ViewModel
{
public string FileText { get; set; }
public void ReadFile(string path)
{
FileText = File.ReadAllText(path);
}
}
XAML:
<TextBlock Text="{Binding FileText}"/>
这篇关于将WPF TextBlock绑定到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文