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 函数.大部分是用 ...
随机推荐
- Socket连接
socket中TCP的三次握手建立连接详解 我们知道tcp建立连接要进行“三次握手”,即交换三个分组.大致流程如下: 客户端向服务器发送一个SYN J 服务器向客户端响应一个SYN K,并对SYN J ...
- oracle11g空表不能导出记录
select 'alter table '||table_name||' allocate extent(size 64k);' from tabs t where not exists (selec ...
- PHP 生成excel|好用强大的php excel类库
做Magento的订单导出Excel功能,找了这个php的excel类 :PHPExcel. PHPExcel是强大的 MS Office Excel 文档生成类库,基于Microsoft's Ope ...
- .NET 命名规范 代码示例
class Person { /// <summary> /// 公有字段.属性 首字母大写 /// </summary> public string FirstName; p ...
- JS常用的设计模式(9)——策略模式
策略模式的意义是定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换.一个小例子就能让我们一目了然. 回忆下jquery里的animate方法. $( div ).animate( {&quo ...
- How to search compound files
Last week my friend told me that she made a terrible mistake. She conducted raw serch and found no s ...
- my vimrc
runtime! debian.vim "设置编码 ,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 ,ucs-bom,chinese "语言 ...
- jquery resize事件增强版
/* * jQuery resize event - v1.1 - 3/14/2010 * http://benalman.com/projects/jquery-resize-plugin/ * * ...
- [原]NYOJ 括号匹配系列2,5
本文出自:http://blog.csdn.net/svitter 括号匹配一:http://acm.nyist.net/JudgeOnline/problem.php?pid=2 括号匹配二:htt ...
- ubuntu 12.04 64位设置兼容32位的实现
在ubuntu12.04上,要运行32的程序,需要安装32位的兼容库. 以前在10.04上成功安装过,方法是 sudo apt-get install ia32-libs 但是在12.04上遇到了困难 ...