我正在使用 MVVM 加载文本文件并显示它们的内容。
模型
MyFile.cs
有一个Name
和Text
// 实现 INotifyPropertyChanged
MyFileRepository.cs
// 我加载的文件的集合
视图模型
OpenFileCommand
加载文件并将其添加到 _filerepository 对象
FileCollection
绑定到视图
看法
Button
解雇OpenCommand
ComboBox
显示加载文件的名称
TextBox
在 combobx 中显示所选文件的内容
<Button Name="OpenFile" Command="{Binding OpenFileCommand}">
<ComboBox Name="FilesList" ItemsSource="{Binding Path=FileCollection}" DisplayMemberPath="Name" />
<TextBox Name="FileContent" Text="{Binding the Text of selected file in combobx "/>
如何将combobx中选择的MyFile的Text属性绑定到TextBox?