zoukankan      html  css  js  c++  java
  • 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);
            }




        }
    }
  • 相关阅读:
    IDEA 中 右键新建时,没有新建class的解决方案
    Git--删除远程仓库文件但不删除本地仓库资源
    Git——跟踪或取消跟踪文件
    git命令大杂烩
    判断项目中是否有slf4j的实现类
    完美解决在Servlet中出现一个输出中文乱码的问题
    mysql常用命令和语句
    设置idea快速生成doc comment
    关于pom.xml中的dependency中的顺序
    Pyqt5_QMessageBox
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434818.html
Copyright © 2011-2022 走看看