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. 多XML追加操作

    假设要统计当前系统中所有的试卷进行分析,试卷是以XML格式存储的,所有这就需要将所有零散的XML文件整合起来,处理成一个完整的XML文件,进行分析, 下面是简单额处理方法: 当前XML文件格式: &l ...

  2. 实用防火墙(Iptables)脚本分析

    实用防火墙(Iptables)脚本分析 --Redhat,CentOS,Ubuntu等常见Linux发行版中都会预装Iptables防火墙,大多数初学者设置起来由于对这款软件比较陌生,设置起来比较困难 ...

  3. java根据sessionid获取session

    import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpSession; /** * * Class ...

  4. Could not resolve this reference. Could not locate the assembly

    Rebuild Project 的时候提示找不到NewtonJson 组件,重新添加了Dll(Newtonsoft.Json.dll),依然抛错. 解决办法,将Dll(Newtonsoft.Json. ...

  5. SDL2 Tutorial

    Hello World for SDL2 SDL2 setting for visual studio. http://lazyfoo.net/tutorials/SDL/01_hello_SDL/w ...

  6. 用python3统计代码行数

    今天接到一个电话面试,对方问我在一个项目中维护了多少行代码. 我懵逼了,从来没有统计过啊,怎么还会有这种需求? 当时一脸茫然的想了想,回答了一个,呃...差不多两千多行吧...感觉很心虚 挂完电话之后 ...

  7. Hbase多master

    单台master的配置 hbase.master master:60000 这是我们通常配置的,这样就定义了master是的ip和端口. 但是当我们需要配置多台master进行,我们只需要提供端口,因 ...

  8. Java 编译报错:illegal character

    1.检查编译版本:1.5还是1.6 2.重新引用一下Jar包

  9. 移植u-boot-1.1.6之mtdparts分区

    和u-boot高版本不同,mtdparts命令没有cmd_mtdparts这么一个单独的文件来实现. 不过,搜索uboot可以在cmd_jffs2.c里面看到如下代码: U_BOOT_CMD( mtd ...

  10. 深入浅出HTML与XHTML的区别

    HTML(HyperText Markup Language,超文本标记语言)最早的HTML官方正式规范,是1995年IETF(Internet Engineering Task Force,因特网工 ...