c# – 使用MVVM选择更改事件
发布时间:2020-12-15 08:40:23 所属栏目:百科 来源:网络整理
导读:我有一个包含人员列表的列表框. 当用户单击某个项时,viewModel应将currentPerson对象设置为用户单击的Object. 我必须为此使用ViewModel,因此MainWindow.xaml.xs中没有代码.任何想法如何解决这个问题? 解决方法 这很简单: 将属性CurrentPerson添加到ViewMod
我有一个包含人员列表的列表框.
当用户单击某个项时,viewModel应将currentPerson对象设置为用户单击的Object. 我必须为此使用ViewModel,因此MainWindow.xaml.xs中没有代码.任何想法如何解决这个问题? 解决方法
这很简单:
将属性CurrentPerson添加到ViewModel并将其绑定到ListBox的SelectedItem属性. 像这样的东西: 查看型号: public Person CurrentPerson { get { return _currentPerson; } set { if(value == _currentPerson) return; _currentPerson = value; NotifyOfPropertyChange("CurrentPerson"); } } 视图: <ListBox SelectedItem="{Binding CurrentPerson}" ...> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Ajax跨域请求COOKIE无法带上的解决办法
- cocos2dx3.1.1版本 向eclipse上移植Android项目
- ruby-on-rails – 对于名称与复数相同的模型,`has_many,:t
- c# – 如何在一个页面中设置cookie值并从asp.net网站的另一
- swift 点击cell没反应,点击后应该跳到指定页面
- 深入学习C语言中memset()函数的用法
- Dojo学习笔记(5. dojo.lang.array & dojo.lang.func &a
- swift 快速奔跑的兔几 本节的内容是:基于文档的应用程序
- 《Test-Driven development By Example》阅读(二)
- Fastjson介绍