【发布时间】:2012-09-09 05:31:40
【问题描述】:
我正在使用 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?
【问题讨论】:
标签: wpf mvvm binding combobox textbox