WPF绑定到linq表达式
using ClassLibrary;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CollectionBinding
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public ObservableCollection<Product> products;
public IEnumerable<Product> matches;
private void btnGetProducts_Click_1(object sender, RoutedEventArgs e)
{
decimal min = Convert.ToDecimal(txtMinUniCost.Text);
products = StoreDB.GetProducts();
matches = from p in products where p.UnitCost > min select p;
lstProducts.ItemsSource = matches;
lstProducts.DisplayMemberPath = "ModelName";
}
private void btnDelete_Click_1(object sender, RoutedEventArgs e)
{
Product p = (Product)lstProducts.SelectedItem;
products.Remove(p);
StoreDB.DeleteProductByID(p.ProductID);
}
private void btnInsert_Click_1(object sender, RoutedEventArgs e)
{
int categoryID = Convert.ToInt32(txtCategoryID.Text);
decimal unitCost = Convert.ToDecimal(txtUnitCost.Text);
Product p = new Product() { CategoryID = categoryID, ModelNumber = txtModelNumber.Text, ModelName = txtModelName.Text, ProductImage = txtProductImage.Text, UnitCost = unitCost, Description = txtDescription.Text };
StoreDB.InsertProduct(p);
products.Add(p);
}
}
}
最新文章
- junit测试,使用classpath和file 加载文件的区别
- Java多线程系列--“JUC集合”09之 LinkedBlockingDeque
- SQLSERVER吞噬内存解决记录
- C特殊浮点值NaN
- 剑指offer系列52---约瑟夫环问题
- Unity3D 使用 Editor 脚本,自定义 脚本的属性面板
- Uber将在泰国首推";优步摩托";服务
- Maximum Product Subarray动态规划思想
- 访问taotao-portal 中controller中返回taotaoresult 测试httppost方法 出现406错误
- 【学习笔记】Hibernate 一对一关联映射 组件映射 二级缓存 集合缓存
- SQL 收缩数据库日志的几种办法 (2005与2008 略有区别)
- 托管C++线程锁实现
- Leetcode 34 Find First and Last Position of Element in Sorted Array 解题思路 (python)
- 剑指offer--3.从头打印链表
- bzoj1106 树状数组
- day9--队列queue
- 使用Sqlserver事务发布实现数据同步(sql2008)_Mssq l数据库教程
- [UE4]优先级与相关性
- 单例模式——java设计模式
- SDUT 1269-走迷宫(DFS打印路径)
热门文章
- EChats+Ajax之柱状图的数据交互
- IT增值服务-客户案例(三):合肥薪火科技,Java和P2P网络借贷系统开发指导
- [Angular] Using directive to create a simple Credit card validator
- LUOGU 1525 关押罪犯 - 并查集拆点(对立点) / 二分+二分图染色
- MySql批量drop table
- HTML5移动开发实战必备知识——本地存储(1)
- Hibernate中的配置文件
- java十五个常用类学习及方法举例
- XMPP之ios即时通讯客户端开发-创建工程添加XMPPFramework及其他框架(三)
- 学习鸟哥的Linux私房菜笔记(15)——文件系统