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 函数.大部分是用 ...
随机推荐
- postgresql安装配置
一,什么是postgresql PostgreSQL是以加州大学伯克利分校计算机系开发的 POSTGRES 版本 4.2 为基础的对象关系型数据库管理系统(ORDBMS),简称pgsql,它支持大部分 ...
- WWF3状态机工作流<WWF第七篇>
状态机是另外一种常见的工作流类型.它是以状态的变迁为驱动而进行业务流转的,是一定需要人为干预的,而不像顺序类型工作流那样可以按照事先设计好的业务流程一步一步依次执行下去. 一.状态机工作流范例 Sta ...
- MSSQL Server Transaction 数据库事务回滚的用法
使用的表结构如下: Commit TransAction Else Rollback TransAction/* 自定义一个变量来判断最后是否发生过错误.*/ ...
- css中float left与float right的使用说明
转自:http://www.jb51.net/css/33740.html 脚本之家 No! 要注意以下几点: 1. 浮动元素会被自动设置成块级元素,相当于给元素设置了display:block( ...
- poj2027
#include <stdio.h> int main(){ int n; int a,b; while(~scanf("%d",&n)){ while(n-- ...
- hdu1203
#include <stdio.h> #include <math.h> #define mmin(x,y) (x)<(y)?(x):(y) int main(){ +] ...
- RegisterStartupScript和RegisterClientScriptBlock的区别
1. //注册到 <form> 尾部 ,HTML元素已加载完毕 this.Page.ClientScript.RegisterStartupScript(this.GetType( ...
- Tomcat启动过程(三):从SocketProcessor到Container
1.Http11Protocol中的内部类Http11ConnectionHandler,执行其process方法 if (processor == null) { processor = creat ...
- wpf常见枚举收集
Icons made by from www.flaticon.com
- Winform下WebBrowser 编辑模式 监听键盘按键事件
最近使用 WebBrowser 做了个富文本编辑器(其实网上有很多很多).例如下面这个玩意(不要在意界面神马的) WebBrowser在编辑模式下可以有一些HTML标签的功能,改变字体大小颜色等等等. ...