WPF绑定到linq表达式
2018-03-30 08:31
155 查看
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);
}
}
}
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);
}
}
}
相关文章推荐
- WPF学习之 数据绑定
- wpf 转换器(枚举类型和布尔类型绑定)
- WPF学习笔记 - 在XAML里绑定
- 模拟实现WPF的依赖属性及绑定通知机制(1)--依赖属性
- WPF技巧(1)异步绑定
- WPF 数据绑定 定制一个集合的视图 导航
- wpf Content数据绑定StringFormat起作用的原理和解决(转)
- WPF ListView 分组数据绑定 TreeView递归数据绑定
- WPF —ListView用ItemsSource绑定对象列表
- WPF中ListBoxItem绑定一个UserControl的学习
- wpf 数据绑定有关讲解
- WPF学习笔记:(一)数据绑定与DataContext
- 将命令绑定到事件中(WPF)
- WPF数据绑定Binding(二)
- WPF新手之如何将数据绑定到TreeView
- WPF学习笔记:(一)数据绑定与DataContext
- wpf 在MVVM模式下开发时,怎样让一个属性绑定到多个RadioButton上
- WPF中DataGrid控件内Button的Command和CommandParameter的绑定
- WPF 命令绑定简单应用
- WPF ListView 的三种数据绑定方式