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?

  1. 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.

  2. 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的更多相关文章

  1. Knockout.Js官网学习(event绑定、submit绑定)

    event绑定 event绑定在DOM元素上添加指定的事件句柄以便元素被触发的时候执行定义的JavaScript 函数.大部分情况下是用在keypress,mouseover和mouseout上. 简 ...

  2. mysql binlog协议分析--具体event

    这几天在修改canal, 连接mysql和maria接收到的event有所区别 拿一个简单的insert sql来举例 mysql 会有以下几个event写入到binlog里 1.ANONYMOUS_ ...

  3. Apache Kafka - Schema Registry

    关于我们为什么需要Schema Registry? 参考, https://www.confluent.io/blog/how-i-learned-to-stop-worrying-and-love- ...

  4. C++模拟C#事件委托机制(二)

    原文 来自于http://www.cnblogs.com/netssfy/archive/2010/02/02/1662056.html 为了解决非法地址访问的冲突,首先需要知道发生该错误的原因是什么 ...

  5. gcview使用

    1.下载适用的版本 https://github.com/chewiebug/GCViewer Supported verbose:gc formats are: Oracle JDK 1.8 -Xl ...

  6. fs event_socket

    mod_event_socket     Skip to end of metadata   Created by John Boteler, last modified by Niek Vlesse ...

  7. 4.Knockout.Js(事件绑定)

    前言 click绑定在DOM元素上添加事件句柄以便元素被点击的时候执行定义的JavaScript 函数.大部分是用在button,input和连接a上,但是可以在任意元素上使用. 简单示例 <h ...

  8. Using the EventManager

    Using the EventManager This tutorial explores the features of zend-eventmanager in-depth. Terminolog ...

  9. Knockout应用开发指南 第三章:绑定语法(2)

    原文:Knockout应用开发指南 第三章:绑定语法(2) 7   click 绑定 目的 click绑定在DOM元素上添加事件句柄以便元素被点击的时候执行定义的JavaScript 函数.大部分是用 ...

随机推荐

  1. JS里的onclick事件

    可以通过以下代码了解JS里的onclick事件: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml&quo ...

  2. Android控件大全(三)——RecyclerView

    是时候用RecyclerView来替换ListView和GridView了 好处就不多说了,百度一搜一大把,来介绍下用法 先定义个适配器: public class BottomSheetAdapte ...

  3. 简化对象extend拓展

    发现对对象继承或拷贝的时候,总是要$点来点去好麻烦,我的解决办法如下: (function(){ Object.prototype.extend = function(o){ $.extend(tru ...

  4. dell N1500 安全配置

    http://www.dell.com/Support/Article/us/en/19/HOW10832 Setting a management IP address A reachable IP ...

  5. Java Base64 加密解密

    使用JDK的类 BASE64Decoder  BASE64Encoder package test; import sun.misc.BASE64Decoder; import sun.misc.BA ...

  6. sql取字段特定符号的前/后

    declare @canshu varchar(200)set @canshu='24§咨询客户'--某符号之后的字段内容select substring(@canshu,charindex('§', ...

  7. 首页banner特效

     <link href="css/swiper.min.css" rel="stylesheet" />  <script src=" ...

  8. POJ C++程序设计 编程题#1 编程作业—继承与派生

    编程题#1 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 写一个MyStr ...

  9. Linux搭建NFS提供磁盘给Windows使用

    在Windows2008系统下设置挂载Linux服务器磁盘 一.系统环境 系统平台:CentOS release 5.8 (Final) NFS Server IP:X....X...153.157 ...

  10. [leetcode]_Best Time to Buy and Sell Stock I && II

    一个系列三道题,我都不会做,google之答案.过了两道,第三道看不懂,放置,稍后继续. 一.Best Time to Buy and Sell Stock I 题目:一个数组表示一支股票的价格变换. ...