• 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);
            }




        }
    }
  • 相关阅读:
    vs2015连接oracle 11g(.net自带方式 using System.Data.OracleClient;)
    div层叠顺序额
    linux运维、架构之路-Zabbix自动化
    linux运维、架构之路-Zabbix监控
    linux运维、架构之路-keepalived高可用
    linux运维、架构之路-内网NTP时间服务器
    linux运维、架构之路-Nginx反向代理
    linux运维、架构之路-数据库迁移
    linux运维、架构之路-网络基础
    linux运维、架构之路-shell编程(一)
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434818.html
Copyright © 2020-2023  润新知