- 浏览: 195874 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (231)
- C++学习 (41)
- vc学习 (25)
- vc异常 (4)
- Flex (2)
- Ext (0)
- java学习笔记 (15)
- mysql学习笔记 (1)
- ibatis学习笔记 (7)
- struts1学习笔记 (1)
- hibernate学习笔记 (3)
- javascript学习笔记 (8)
- eclipse快捷键 (2)
- 英语学习 (1)
- cmd (1)
- eclipse 配置 (2)
- 其他 (4)
- JAVASE (34)
- firefox (1)
- linux (8)
- Apache (6)
- cms (22)
- jsuc (10)
- html (3)
- css (1)
- 作图 (2)
- vs2012 (2)
- 编码转换 (12)
- work_unicode (1)
- work_webbrowser (1)
- work_trade_quotes_login (1)
- c#学习 (38)
- wpf学习 (31)
- wpf快速学习 (1)
- VB学习 (1)
- NSIS (4)
- log4cpp (3)
- 学习web (1)
- 经验 (1)
- c_汇编 (1)
最新评论
本篇学习了ObservableCollection<T>相关知识,因为在项目开发中我碰到一些问题,后来发现时我的理解偏差!所以做下笔记!
(一)代码:
(二)实现类成员更改通知UI:
要想实现类属性值修改,我们必须修改Student类,如下:
(三)总结:
本篇学习了 ObservableCollection<T>与List<T>作为绑定数据源的不同,实例充分说明了 ObservableCollection<T>在Silverlight中作为绑定数据源的优势! 并例举了自己最初对ObservableCollection<T>的误解。并说明了怎样实现类属性成员的修改更改UI的实现方法!这里绑定可以是OneTime,OneWay,TwoWay.具体 理解可以看我的另一篇文章Silverlight中OneTime,OneWay,TwoWay及INotifyPropertyChanged 接口的理解
(四)
数据层已经变了,为何有时更新不了界面,因为取不到界面
(五)
线程内进行
for (int i = 0; i < vCancels.Count; i++)
{
Mgr.TransactionService.CancelOrder("F", vCancels[i].OrderId, vCancels[i].ContractNo, vCancels[i].OperatorNo);
}
不要涉及到任何界面的,开始用界面的iTransactionService
iTransactionService = Mgr.TransactionService;
线程中for循环还是会卡界面
(一)代码:
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; //添加命名空间 using System.Collections.ObjectModel; using System.ComponentModel; namespace CatalogTest { public partial class ObservableCollectionVSList : UserControl { ObservableCollection<Student> students = new ObservableCollection<Student>(); //List<Student> students = new List<Student>(); Student selectedStudent = null; public ObservableCollectionVSList() { InitializeComponent(); this.Loaded += new RoutedEventHandler(ObservableCollectionVSList_Loaded); } void ObservableCollectionVSList_Loaded(object sender, RoutedEventArgs e) { Student student1 = new Student() { StudentID = "001", StudentName = "张三" }; Student student2 = new Student() { StudentID = "002", StudentName = "李四" }; Student student3 = new Student() { StudentID = "003", StudentName = "王五" }; students.Add(student1); students.Add(student2); students.Add(student3); //绑定 listBox1.ItemsSource = students; listBox1.DisplayMemberPath = "StudentName"; //注册选择项事件 this.listBox1.SelectionChanged += new SelectionChangedEventHandler(listBox1_SelectionChanged); } void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { selectedStudent = this.listBox1.SelectedItem as Student; } //删除 private void btnDel_Click(object sender, RoutedEventArgs e) { if (selectedStudent != null) { students.Remove(selectedStudent); } } //修改 private void btnEdit_Click(object sender, RoutedEventArgs e) { if (selectedStudent != null) { int myIndex = students.IndexOf(selectedStudent); students[myIndex].StudentName = "我改名了!"; } } //添加 private void btnAdd_Click(object sender, RoutedEventArgs e) { Student student = new Student() { StudentID="009",StudentName="Joetao"}; students.Add(student); } } public class Student { public string StudentID { get; set; } public string StudentName { get; set; } } //分别采用 ObservableCollection<Student>与List<Student>作为绑定数据源 //当我们用List<T>作为数据源绑定UI控件时:当做增删改操作来修改students绑定数据源时,数据源都不能通知UI更新。 //当我们用ObservableCollection<T>作为数据绑定UI控件时:当做增删改操作来修改students绑定数据源时,Add()和Remove()操作修改的数据源能通知UI更新,而改操作不能更新UI. // //这一点正说明了MSDN上对ObservableCollection<T>类介绍:"表示一个动态数据集合,在添加项、移除项或刷新整个列表时,此集合将提供通知。" //我在处理这个问题理解偏差: //在一开始的时候我对这句话:“实现您自己的集合之前,应考虑使用 ObservableCollection<T> 类,该类具有 INotifyCollectionChanged 和 INotifyPropertyChanged 的内置实现。“ //被我理解为了只要用了ObservableCollection<T>,这个类集合以及类集合中的所有成员属性就具有更改通知的功能,这个理解是错误。ObservableCollection<T>只是针对T类型而言,并非给予了 //类成员属性更改通知的功能,要想类成员属性具有更改UI功能还得让类继承INotifyPropertyChanged接口,并用 (NotifyCollectionChangedEventArgs) 的事件数据报告有关集合更改的特性的信息 }
(二)实现类成员更改通知UI:
要想实现类属性值修改,我们必须修改Student类,如下:
public class Student : INotifyPropertyChanged { private string studentID; public string StudentID { get { return studentID; } set { studentID = value; NotifyPropertyChange("StudentID"); } } private string studentName; public string StudentName { get { return studentName; } set { studentName = value; NotifyPropertyChange("StudentName"); } } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChange(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }
(三)总结:
本篇学习了 ObservableCollection<T>与List<T>作为绑定数据源的不同,实例充分说明了 ObservableCollection<T>在Silverlight中作为绑定数据源的优势! 并例举了自己最初对ObservableCollection<T>的误解。并说明了怎样实现类属性成员的修改更改UI的实现方法!这里绑定可以是OneTime,OneWay,TwoWay.具体 理解可以看我的另一篇文章Silverlight中OneTime,OneWay,TwoWay及INotifyPropertyChanged 接口的理解
(四)
数据层已经变了,为何有时更新不了界面,因为取不到界面
(五)
线程内进行
for (int i = 0; i < vCancels.Count; i++)
{
Mgr.TransactionService.CancelOrder("F", vCancels[i].OrderId, vCancels[i].ContractNo, vCancels[i].OperatorNo);
}
不要涉及到任何界面的,开始用界面的iTransactionService
iTransactionService = Mgr.TransactionService;
线程中for循环还是会卡界面
发表评论
-
byte数组直接输出
2016-07-19 11:38 1205byte数组直接输出 BitConverter.ToStrin ... -
wfi:WindowsFormsHost焦点设置
2016-07-05 17:56 528<wfi:WindowsFormsHost> ... -
x:Name
2016-04-25 10:44 414由于“Dameer”是在同一程序集中实现的,您必须设置 x:N ... -
WindowsFormsHost的使用注意
2016-04-25 10:24 1284一使用 1 引用 2 xmlns:wfi ="clr ... -
TextBox滚动条
2016-04-22 16:51 616<TextBox Grid.Row="1& ... -
TextBlock滚动条
2016-04-22 16:49 406<ScrollViewer Name="s ... -
C#_WPF_WPF用户控件库
2016-04-12 11:37 758新建项目》window桌面》WPF用户控件库 -
DependencyProperty.UnsetValue_WPF涉及到资源的嵌套引用,被引用的资源要定义在引用的资源前面
2015-10-27 15:09 1921错误 1 “{DependencyProperty.Unset ... -
string格式的日期时间字符串转为DateTime类型
2015-08-05 14:22 918string格式的日期时间字符串转为DateTime类型 / ... -
checkbox
2015-07-28 17:18 503private void Chec ... -
自定义DataGrid样式
2015-06-26 22:03 706<ResourceDictionary xmlns=&q ... -
x:Name x:Key Name区别
2015-06-25 15:40 556x:Name x:Key Name区别 1、x:Key 只 ... -
work_代码添加
2015-06-23 17:15 471<UserControl x:Class=" ... -
FindName和VisualTreeHelper
2015-06-19 13:23 720int iCount = this.dataGridCan ... -
理解WPF中的视觉树和逻辑树(转载)
2015-06-19 13:00 555理解WPF中的视觉树和逻辑树 理解WPF中的 ... -
理解WPF中的视觉树和逻辑树(转载)
2015-06-19 12:58 1601理解WPF中的视觉树和逻 ... -
GetEnumerator
2015-06-19 12:39 618IEnumerator enumerator = this ... -
资源文件获取配置
2015-06-18 16:03 340object obj = Application.Curren ... -
Pack URI
2015-06-18 15:41 651主要用来定位 资源文 ... -
C#学习之DateTime
2015-04-23 10:30 413DateTime string.Format("{ ...
相关推荐
C#+List<T>+GridControl实现主从表嵌套
<br>AnimatingTilePanel<br>BlockBar<br>ColorPicker<br>DateControls<br>FlipTile3D<br>FolderPicker<br>Graph<br>Hex<br>InfoTextBox<br>...VisualTreeViewer<br>XAMLTShirt<br>Zap<br><br>下载自http://wpf.netfx3.com/<br>版权归原作者所有
WPF <ZoomableCanvas> 实现缩放移动
<br><br>Developers encountering WPF and .NET 3.5 for the first time in their professional lives.<br>About the Apress Pro Series<br><br>The Apress Pro series books are practical, professional tutorials...
2006 年12月 <br>【开 本】 16开 <br>【页 码】 656 <br>【版 次】1-1 <br>Book Description<br><br> <br><br>Printed entirely in color, with helpful figures and syntax coloring to make code samples appear ...
WCF & WPF 聊天程序源码<br>For those that have read some of my other CodeProject articles you will probably know, that I am not shy about trying out new technologies. But one good thing about that is ...
微软官网 WPF DataGrid 分组演示程序 内容包括 DataGrid,ObservableCollection<T>,ICollectionView,CollectionViewSource等模块的应用
<RadioButton>中国</RadioButton> <RadioButton>美国</RadioButton> <RadioButton>日本</RadioButton> <RadioButton>法国</RadioButton> </StackPanel> </Expander> <Expander Name="expander2" IsExpanded=...
Page1的ListView是别人的代码。... ObservableCollection<DataGridColumn> collec=new ObservableCollection<DataGridColumn> ();我们控件不是listview类型的,所以不能 public GridViewColumnCollection collec;。
/// <summary> /// 加法命令 /// </summary> public BaseCommand AddCommand { get; set; } /// <summary> /// 减法命令 /// </summary> public BaseCommand SubCommand { get; set; } /// <summary> /// ...
From creating appealing graphics and animated structures to enhancing performance and security, you'll be programming in no time.<br><br>First you'll explore the WPF framework and learn how to ...
<ListBox ItemsSource="{StaticResource Data}" > <ListBox.ItemTemplate> <DataTemplate> <ListBox ItemsSource="{Binding .}"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding .}" ...
《实用WPF图形编程》<br>英文PDF
C#WPF 右键菜单 显示 事件触发 测试通过 <TextBox Name="txtbox"> <!-- 设置右键菜单 --> <TextBox.ContextMenu> <ContextMenu> <MenuItem Header="编辑"> <!-- 调用系统命令 --> <MenuItem Command="Copy"></...
详细介绍了WPF的相关技术,是很好的入门书籍。
<StackPanel Height="Auto" Name="stackPanel1" Width="Auto" > <ListView Height="Auto" x:Name="listView1" Width="Auto" ItemsSource="{Binding}" SelectionChanged="Equipment_SelectionChanged" ...
WPF揭秘_code.rar WPF揭秘源码收录,赞!!!
<p>WPF 做的一个简易订单系统,采用了Caliburn和Telerik结合的方式,可以作为一些开发的参考.</p><p></p><p>软件架构</p><p>软件架构说明 基于Caliburn.Micro 框架 包含了NPOI + Dapper 等库</p><p>报表采用嵌入Web...
/// <param name=message>消息</param> /// <param name=owner>父级窗体</param> public static void ShowDialog(string message, Window owner) { //蒙板 Grid layer = new Grid() { Backgrou
WPF在DataGrid列中使用ComboBox绑定,改变ComboBox可回传至绑定的实体, 网上找了好久,终于搞定了,不是那个用枚举的例子!!ComboBox绑定的是一个实体列表. 程序名字叫 给唐僧选老婆!哈哈