DataView usage combind with event and ViewModel From ERP-DEV
reflesh the selected item in DataView
when we use DataView to display a set of data. Generally, we binding the selected item to our object in ViewModel. Then, we can modify the selected item to reflesh ui. How we do it?
Relative Class
ObservableCollection
we usually use this type to host our data source. and binding the data source of ui element to this. So, if any add or delete operation, it will
reflect back to ui automatically.ListCollectionView
This class is used to get the view of the ui element. WPF has alreadly done some background work. it use the datasource
to generate the View object and present it into the ui. so, if we hope to operate the ui. we need the view class not the
data source.Sample Code
Xaml:
<ListView Grid.Row="1" Margin="5" Background="LightYellow" Name="lstProducts" ItemsSource="{Binding Products, Mode=TwoWay}" SelectedItem="{Binding SelectedProduct, Mode=TwoWay}" SelectionChanged="selectedItemChanged">
<ListView.View>
<GridView AllowsColumnReorder="True" >
<GridViewColumn DisplayMemberBinding="{Binding ProductName}" Header="产品名称" Width="200"/>
<GridViewColumn DisplayMemberBinding="{Binding ProductSize}" Header="产品大小" Width="200"/>
</GridView>
</ListView.View>
</ListView>
Xaml.cs event:
private void selectedItemChanged(object sender, SelectionChangedEventArgs e)
{
ListView lv = sender as ListView;
ListCollectionView lcv = (ListCollectionView)CollectionViewSource.GetDefaultView(lv.ItemsSource);
lcv.MoveCurrentTo(lv.SelectedItem);
}
ViewModel:
#region public properties
public ObservableCollection<ProductDataVM> Products
{
get
{
return _products;
}
set
{
_products = value;
RaisePropertyChanged("");
}
}
public ProductDataVM SelectedProduct
{
get
{
return _selectedProduct;
}
set
{
_selectedProduct = value;
RaisePropertyChanged("");
}
}
#endregion
DataView usage combind with event and ViewModel From ERP-DEV的更多相关文章
- Knockout.Js官网学习(event绑定、submit绑定)
event绑定 event绑定在DOM元素上添加指定的事件句柄以便元素被触发的时候执行定义的JavaScript 函数.大部分情况下是用在keypress,mouseover和mouseout上. 简 ...
- mysql binlog协议分析--具体event
这几天在修改canal, 连接mysql和maria接收到的event有所区别 拿一个简单的insert sql来举例 mysql 会有以下几个event写入到binlog里 1.ANONYMOUS_ ...
- Apache Kafka - Schema Registry
关于我们为什么需要Schema Registry? 参考, https://www.confluent.io/blog/how-i-learned-to-stop-worrying-and-love- ...
- C++模拟C#事件委托机制(二)
原文 来自于http://www.cnblogs.com/netssfy/archive/2010/02/02/1662056.html 为了解决非法地址访问的冲突,首先需要知道发生该错误的原因是什么 ...
- gcview使用
1.下载适用的版本 https://github.com/chewiebug/GCViewer Supported verbose:gc formats are: Oracle JDK 1.8 -Xl ...
- fs event_socket
mod_event_socket Skip to end of metadata Created by John Boteler, last modified by Niek Vlesse ...
- 4.Knockout.Js(事件绑定)
前言 click绑定在DOM元素上添加事件句柄以便元素被点击的时候执行定义的JavaScript 函数.大部分是用在button,input和连接a上,但是可以在任意元素上使用. 简单示例 <h ...
- Using the EventManager
Using the EventManager This tutorial explores the features of zend-eventmanager in-depth. Terminolog ...
- Knockout应用开发指南 第三章:绑定语法(2)
原文:Knockout应用开发指南 第三章:绑定语法(2) 7 click 绑定 目的 click绑定在DOM元素上添加事件句柄以便元素被点击的时候执行定义的JavaScript 函数.大部分是用 ...
随机推荐
- file not found while xcode archive
今天碰到一个问题,就是我像在我的ios app中添加支付宝功能,按照文档我添加好了测试也成功,但是在archive的时候就是出问题,很奇怪.最后网上查了文档,最后在stackoverflow上面找到了 ...
- 纯servlet返回xml数据
... void doget..... response.setContentType("application/xml");//设置格式 PrintWriter out = r ...
- JS常用的设计模式(17)—— 状态模式
状态模式主要可以用于这种场景 1 一个对象的行为取决于它的状态 2 一个操作中含有庞大的条件分支语句 回想下街头霸王的游戏. 隆有走动,攻击,防御,跌倒,跳跃等等多种状态,而这些状态之间既有联系又互相 ...
- hbase很有价值的读写性能提升
NoSQL现在风生水起,hbase的使用也越来越广,但目前几乎所有的NoSQL产品在运维上都没法和DB相提并论,在这篇blog中来总结下我们在运维hbase时的一些问题以及解决的方法,也希望得到更多h ...
- 图解Javascript上下文与作用域
原文网址:http://blog.rainy.im/2015/07/04/scope-chain-and-prototype-chain-in-js/ 本文尝试阐述Javascript中的上下文与作用 ...
- 如何解决Android的SDK与ADT不匹配问题
win7/xp 下面安装Android虚拟机,更新SDK后,在Eclipse preference里指向android-sdk-windows时.出现 :This Android SDK requir ...
- 在WP8项目中使用ARMASM
由于之前项目中某些密集运算优化的需要,涉及到ARMASM相关的内容, 所以有幸可以在此分享一下自己的经验. 先铺垫一些知识: 1. ARM处理器有两种指令ARM.THUMB, 在WP8下默认是THUM ...
- 常用的MyEclipse快捷键
在调试程序的时候,我们经常需要注释一些代码,在用Myeclipse编程时,就可以用 Ctrl+/ 为选中的一段代码加上以 // 打头的注释:当需要恢复代码功能的时候,又可以用Ctrl+/ 去掉注释.这 ...
- windows下如何修改远程登录端口
windows下如何修改远程登录端口 windows远程桌面默认端口为3389,修改 方法如下:在"开始>运行"中输入"regedit" 点击“确定”,打 ...
- iOS中UIKit——UIFont得到iOS设备上的系统字体
for (NSString *fontFamily in [UIFont familyNames]) { NSLog(@"字体家族是:%@",fontFamily); for(N ...