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




        }
    }
  • 相关阅读:
    os模块
    random模块
    datetime模块
    time模块
    软甲开发目录规范
    模块与包
    函数递归
    内置函数
    【NOIP2016提高组】换教室
    【NOIP2015提高组】运输计划
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434818.html
Copyright © 2020-2023  润新知